Java Code Examples for com.helger.commons.collection.ArrayHelper#contains()
The following examples show how to use
com.helger.commons.collection.ArrayHelper#contains() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonEscapeHelper.java From ph-commons with Apache License 2.0 | 6 votes |
@Nonnull public static String jsonUnescape (@Nonnull final char [] aInput) { ValueEnforcer.notNull (aInput, "Input"); if (!ArrayHelper.contains (aInput, MASK_CHAR)) { // Nothing to unescape return new String (aInput); } // Perform unescape final StringBuilder aSB = new StringBuilder (aInput.length); jsonUnescapeToStringBuilder (aInput, aSB); return aSB.toString (); }
Example 2
Source File: StringHelper.java From ph-commons with Apache License 2.0 | 5 votes |
public static boolean startsWithAny (@Nullable final CharSequence aCS, @Nullable final char [] aChars) { if (hasText (aCS) && aChars != null) if (ArrayHelper.contains (aChars, aCS.charAt (0))) return true; return false; }
Example 3
Source File: StringHelper.java From ph-commons with Apache License 2.0 | 5 votes |
public static boolean endsWithAny (@Nullable final CharSequence aCS, @Nullable final char [] aChars) { if (hasText (aCS) && aChars != null) if (ArrayHelper.contains (aChars, getLastChar (aCS))) return true; return false; }
Example 4
Source File: StringHelper.java From ph-commons with Apache License 2.0 | 5 votes |
/** * Optimized replace method that replaces a set of characters with another * character. This method was created for efficient unsafe character * replacements! * * @param sInputString * The input string. * @param aSearchChars * The characters to replace. * @param cReplacementChar * The new char to be used instead of the search chars. * @return The replaced version of the string or an empty char array if the * input string was <code>null</code>. */ @Nonnull public static char [] replaceMultiple (@Nullable final String sInputString, @Nonnull final char [] aSearchChars, final char cReplacementChar) { ValueEnforcer.notNull (aSearchChars, "SearchChars"); // Any input text? if (hasNoText (sInputString)) return ArrayHelper.EMPTY_CHAR_ARRAY; // Get char array final char [] aInput = sInputString.toCharArray (); // Any replacement patterns? if (aSearchChars.length == 0) return aInput; // build result final char [] aOutput = new char [aInput.length]; int nOutputIndex = 0; for (final char c : aInput) { if (ArrayHelper.contains (aSearchChars, c)) aOutput[nOutputIndex] = cReplacementChar; else aOutput[nOutputIndex] = c; nOutputIndex++; } return aOutput; }
Example 5
Source File: StringHelper.java From ph-commons with Apache License 2.0 | 5 votes |
/** * Optimized replace method that replaces a set of characters with another * character. This method was created for efficient unsafe character * replacements! * * @param sInputString * The input string. * @param aSearchChars * The characters to replace. * @param cReplacementChar * The new char to be used instead of the search chars. * @param aTarget * The target StringBuilder to write the result to. May not be * <code>null</code>. */ public static void replaceMultipleTo (@Nullable final String sInputString, @Nonnull final char [] aSearchChars, final char cReplacementChar, @Nonnull final StringBuilder aTarget) { ValueEnforcer.notNull (aSearchChars, "SearchChars"); ValueEnforcer.notNull (aTarget, "Target"); // Any input text? if (hasText (sInputString)) { // Any search chars? if (aSearchChars.length == 0) { aTarget.append (sInputString); } else { // Perform the replacement for (final char c : sInputString.toCharArray ()) { if (ArrayHelper.contains (aSearchChars, c)) aTarget.append (cReplacementChar); else aTarget.append (c); } } } }
Example 6
Source File: StringHelper.java From ph-commons with Apache License 2.0 | 5 votes |
/** * Optimized replace method that replaces a set of characters with another * character. This method was created for efficient unsafe character * replacements! * * @param sInputString * The input string. * @param aSearchChars * The characters to replace. * @param cReplacementChar * The new char to be used instead of the search chars. * @param aTarget * The target writer to write the result to. May not be * <code>null</code>. * @throws IOException * in case writing to the Writer fails * @since 8.6.3 */ public static void replaceMultipleTo (@Nullable final String sInputString, @Nonnull final char [] aSearchChars, final char cReplacementChar, @Nonnull final Writer aTarget) throws IOException { ValueEnforcer.notNull (aSearchChars, "SearchChars"); ValueEnforcer.notNull (aTarget, "Target"); // Any input text? if (hasText (sInputString)) { // Any search chars? if (aSearchChars.length == 0) { aTarget.write (sInputString); } else { // Perform the replacement for (final char c : sInputString.toCharArray ()) { if (ArrayHelper.contains (aSearchChars, c)) aTarget.write (cReplacementChar); else aTarget.write (c); } } } }
Example 7
Source File: StringHelper.java From ph-commons with Apache License 2.0 | 3 votes |
/** * Check if any of the passed searched characters is contained in the input * char array. * * @param aInput * The input char array. May be <code>null</code>. * @param aSearchChars * The char array to search. May not be <code>null</code>. * @return <code>true</code> if at least any of the search char is contained * in the input char array, <code>false</code> otherwise. */ public static boolean containsAny (@Nullable final char [] aInput, @Nonnull final char [] aSearchChars) { ValueEnforcer.notNull (aSearchChars, "SearchChars"); if (aInput != null) for (final char cIn : aInput) if (ArrayHelper.contains (aSearchChars, cIn)) return true; return false; }
Example 8
Source File: MimeTypeParser.java From ph-commons with Apache License 2.0 | 2 votes |
/** * Check if the passed character is a special character according to RFC 2045 * chapter 5.1 * * @param c * The character to check * @return <code>true</code> if the character is a special character, * <code>false</code> otherwise. */ public static boolean isTSpecialChar (final char c) { return ArrayHelper.contains (TSPECIAL, c); }