Class StringHelper


  • @Immutable
    public final class StringHelper
    extends Object
    Generic string transformation and helper methods. If you need to modify a string, start looking in this class.
    Author:
    Philip Helger
    • Field Detail

      • STRING_NOT_FOUND

        public static final int STRING_NOT_FOUND
        The constant to be returned if an String.indexOf call did not find a match!
        See Also:
        Constant Field Values
    • Method Detail

      • isEmpty

        public static boolean isEmpty​(@Nullable
                                      CharSequence aCS)
        Check if the string is null or empty.
        Parameters:
        aCS - The character sequence to check. May be null.
        Returns:
        true if the string is null or empty, false otherwise
        Since:
        10.1.8
      • isEmpty

        public static boolean isEmpty​(@Nullable
                                      String sStr)
        Check if the string is null or empty.
        Parameters:
        sStr - The string to check. May be null.
        Returns:
        true if the string is null or empty, false otherwise
        Since:
        10.1.8
      • isEmptyAfterTrim

        public static boolean isEmptyAfterTrim​(@Nullable
                                               String s)
        Check if the string is null or empty after trimming.
        Parameters:
        s - The string to check. May be null.
        Returns:
        true if the string is null or empty or consists only of whitespaces, false otherwise
        Since:
        10.1.8
      • isNotEmpty

        public static boolean isNotEmpty​(@Nullable
                                         CharSequence aCS)
        Check if the string contains any char.
        Parameters:
        aCS - The character sequence to check. May be null.
        Returns:
        true if the string contains at least one, false otherwise
        Since:
        10.1.8
      • isNotEmpty

        public static boolean isNotEmpty​(@Nullable
                                         String sStr)
        Check if the string contains any char.
        Parameters:
        sStr - The string to check. May be null.
        Returns:
        true if the string contains at least one char, false otherwise
        Since:
        10.1.8
      • isNotEmptyAfterTrim

        public static boolean isNotEmptyAfterTrim​(@Nullable
                                                  String s)
        Check if the string neither null nor empty after trimming.
        Parameters:
        s - The string to check. May be null.
        Returns:
        true if the string is neither null nor empty nor consists only of whitespaces, false otherwise
        Since:
        10.1.8
      • hasNoText

        public static boolean hasNoText​(@Nullable
                                        CharSequence aCS)
        Check if the string is null or empty.
        Parameters:
        aCS - The character sequence to check. May be null.
        Returns:
        true if the string is null or empty, false otherwise
      • hasNoText

        public static boolean hasNoText​(@Nullable
                                        String sStr)
        Check if the string is null or empty.
        Parameters:
        sStr - The string to check. May be null.
        Returns:
        true if the string is null or empty, false otherwise
      • hasNoTextAfterTrim

        public static boolean hasNoTextAfterTrim​(@Nullable
                                                 String s)
        Check if the string is null or empty after trimming.
        Parameters:
        s - The string to check. May be null.
        Returns:
        true if the string is null or empty or consists only of whitespaces, false otherwise
      • hasText

        public static boolean hasText​(@Nullable
                                      CharSequence aCS)
        Check if the string contains any char.
        Parameters:
        aCS - The character sequence to check. May be null.
        Returns:
        true if the string contains at least one, false otherwise
      • hasText

        public static boolean hasText​(@Nullable
                                      String sStr)
        Check if the string contains any char.
        Parameters:
        sStr - The string to check. May be null.
        Returns:
        true if the string contains at least one char, false otherwise
      • hasTextAfterTrim

        public static boolean hasTextAfterTrim​(@Nullable
                                               String s)
        Check if the string neither null nor empty after trimming.
        Parameters:
        s - The string to check. May be null.
        Returns:
        true if the string is neither null nor empty nor consists only of whitespaces, false otherwise
      • containsAny

        public static boolean containsAny​(@Nullable
                                          CharSequence aCS,
                                          @Nullable
                                          ICharPredicate aFilter)
        Check if the passed CharSequence contains any character matching the provided filter.
        Parameters:
        aCS - String to check. May be null.
        aFilter - The filter to use. May be null.
        Returns:
        true if the filter is null and the string is not empty. true if the filter is not null and at least one character of the string matches the filter. false otherwise.
        Since:
        9.1.7
      • containsAny

        public static boolean containsAny​(@Nullable
                                          String sStr,
                                          @Nullable
                                          ICharPredicate aFilter)
        Check if the passed String contains any character matching the provided filter.
        Parameters:
        sStr - String to check. May be null.
        aFilter - The filter to use. May be null.
        Returns:
        true if the filter is null and the string is not empty. true if the filter is not null and at least one character of the string matches the filter. false otherwise.
        Since:
        9.1.7
      • containsNone

        public static boolean containsNone​(@Nullable
                                           CharSequence aCS,
                                           @Nullable
                                           ICharPredicate aFilter)
        Check if the passed CharSequence contains no character matching the provided filter.
        Parameters:
        aCS - String to check. May be null.
        aFilter - The filter to use. May be null.
        Returns:
        true if the filter is null and the string is empty. true if the filter is not null and no character of the string matches the filter. false otherwise.
        Since:
        9.1.7
      • containsNone

        public static boolean containsNone​(@Nullable
                                           String sStr,
                                           @Nullable
                                           ICharPredicate aFilter)
        Check if the passed String contains no character matching the provided filter.
        Parameters:
        sStr - String to check. May be null.
        aFilter - The filter to use. May be null.
        Returns:
        true if the filter is null and the string is empty. true if the filter is not null and no character of the string matches the filter. false otherwise.
        Since:
        9.1.7
      • containsOnly

        public static boolean containsOnly​(@Nullable
                                           CharSequence aCS,
                                           @Nullable
                                           ICharPredicate aFilter)
        Check if the passed CharSequence contains only characters matching the provided filter.
        Parameters:
        aCS - String to check. May be null.
        aFilter - The filter to use. May be null.
        Returns:
        true if the filter is null and the string is not empty. true if the filter is not null and the string has at least one character and all characters of the string match the filter. false otherwise.
        Since:
        9.1.7
      • containsOnly

        public static boolean containsOnly​(@Nullable
                                           String sStr,
                                           @Nullable
                                           ICharPredicate aFilter)
        Check if the passed String contains only characters matching the provided filter.
        Parameters:
        sStr - String to check. May be null.
        aFilter - The filter to use. May be null.
        Returns:
        true if the filter is null and the string is not empty. true if the filter is not null and the string has at least one character and all characters of the string match the filter. false otherwise.
        Since:
        9.1.7
      • isAllWhitespace

        public static boolean isAllWhitespace​(@Nullable
                                              CharSequence s)
        Check if the passed character sequence is only whitespace or not.
        Parameters:
        s - The character sequence to be checked. May be null.
        Returns:
        true if the passed sequence is empty or if only whitespace characters are contained.
        See Also:
        Character.isWhitespace(char)
      • getLeadingZero

        @Nonnull
        public static String getLeadingZero​(int nValue,
                                            int nChars)
      • getLeadingZero

        @Nonnull
        public static String getLeadingZero​(long nValue,
                                            int nChars)
      • getWithLeading

        @Nonnull
        public static String getWithLeading​(@Nullable
                                            String sSrc,
                                            @Nonnegative
                                            int nMinLen,
                                            char cFront)
        Get a string that is filled at the beginning with the passed character until the minimum length is reached. If the input string is empty, the result is a string with the provided len only consisting of the passed characters. If the input String is longer than the provided length, it is returned unchanged.
        Parameters:
        sSrc - Source string. May be null.
        nMinLen - Minimum length. Should be > 0.
        cFront - The character to be used at the beginning
        Returns:
        A non-null string that has at least nLen chars
      • getWithLeading

        @Nonnull
        public static String getWithLeading​(int nValue,
                                            @Nonnegative
                                            int nMinLen,
                                            char cFront)
        Get a string that is filled at the beginning with the passed character until the minimum length is reached. If the input String is longer than the provided length, it is returned unchanged.
        Parameters:
        nValue - Source string. May be null.
        nMinLen - Minimum length. Should be > 0.
        cFront - The character to be used at the beginning
        Returns:
        A non-null string that has at least nLen chars
        See Also:
        getWithLeading(String, int, char)
      • getWithLeading

        @Nonnull
        public static String getWithLeading​(long nValue,
                                            @Nonnegative
                                            int nMinLen,
                                            char cFront)
        Get a string that is filled at the beginning with the passed character until the minimum length is reached. If the input String is longer than the provided length, it is returned unchanged.
        Parameters:
        nValue - Source string. May be null.
        nMinLen - Minimum length. Should be > 0.
        cFront - The character to be used at the beginning
        Returns:
        A non-null string that has at least nLen chars
        See Also:
        getWithLeading(String, int, char)
      • getWithTrailing

        @Nonnull
        public static String getWithTrailing​(@Nullable
                                             String sSrc,
                                             @Nonnegative
                                             int nMinLen,
                                             char cEnd)
        Get a string that is filled at the end with the passed character until the minimum length is reached. If the input string is empty, the result is a string with the provided len only consisting of the passed characters. If the input String is longer than the provided length, it is returned unchanged.
        Parameters:
        sSrc - Source string. May be null.
        nMinLen - Minimum length. Should be > 0.
        cEnd - The character to be used at the end
        Returns:
        A non-null string that has at least nLen chars
      • getHexChar

        public static char getHexChar​(int n)
        Get the matching hex digit as a lower case character.
        Parameters:
        n - The value to get the hex digit from. Must be between 0 and 15.
        Returns:
        The hex character (one of 0-9 or a-f), or '\0' if the value could not be converted
      • getHexCharUpperCase

        public static char getHexCharUpperCase​(int n)
        Get the matching hex digit as an upper case character.
        Parameters:
        n - The value to get the hex digit from. Must be between 0 and 15.
        Returns:
        The hex character (one of 0-9 or A-F), or '\0' if the value could not be converted
      • getHexEncoded

        @Nonnull
        public static String getHexEncoded​(@Nonnull
                                           String sInput,
                                           @Nonnull
                                           Charset aCharset)
        Convert a string to a byte array and than to a hexadecimal encoded string.
        Parameters:
        sInput - The source string. May not be null.
        aCharset - The charset to use. May not be null.
        Returns:
        The String representation of the byte array of the string.
      • getHexEncoded

        @Nonnull
        public static String getHexEncoded​(@Nonnull
                                           byte[] aInput)
        Convert a byte array to a hexadecimal encoded string.
        Parameters:
        aInput - The byte array to be converted to a String. May not be null.
        Returns:
        The String representation of the byte array.
      • getHexEncoded

        @Nonnull
        public static String getHexEncoded​(@Nonnull
                                           byte[] aInput,
                                           int nOfs,
                                           int nLen)
        Convert a byte array to a hexadecimal encoded string.
        Parameters:
        aInput - The byte array to be converted to a String. May not be null.
        nOfs - Byte array offset
        nLen - Number of bytes to encode
        Returns:
        The String representation of the byte array.
      • getHexValue

        @CheckForSigned
        public static int getHexValue​(@Nonnegative
                                      char c)
        Get the decimal value of the passed hex character
        Parameters:
        c - The hex char to convert
        Returns:
        A value between 0 and 15, or -1 if the input character is not a hex char!
      • getHexByte

        public static int getHexByte​(@Nonnegative
                                     char cHigh,
                                     @Nonnegative
                                     char cLow)
        Parameters:
        cHigh - High hex part
        cLow - Low hex part
        Returns:
        A value between 0 and 255, or -1 if any input character is not a hex char!
      • getHexString

        @Nonnull
        public static String getHexString​(byte nValue)
      • getHexStringLeadingZero

        @Nonnull
        public static String getHexStringLeadingZero​(byte nValue,
                                                     int nDigits)
      • getHexStringLeadingZero2

        @Nonnull
        public static String getHexStringLeadingZero2​(byte nValue)
      • getHexString

        @Nonnull
        public static String getHexString​(int nValue)
      • getHexStringLeadingZero

        @Nonnull
        public static String getHexStringLeadingZero​(int nValue,
                                                     int nDigits)
      • getHexString

        @Nonnull
        public static String getHexString​(long nValue)
      • getHexStringLeadingZero

        @Nonnull
        public static String getHexStringLeadingZero​(long nValue,
                                                     int nDigits)
      • getHexString

        @Nonnull
        public static String getHexString​(short nValue)
      • getHexStringLeadingZero

        @Nonnull
        public static String getHexStringLeadingZero​(short nValue,
                                                     int nDigits)
      • getLeadingCharCount

        @Nonnegative
        public static int getLeadingCharCount​(@Nullable
                                              String s,
                                              char c)
        Get the number of specified chars, the passed string starts with.
        Parameters:
        s - The string to be parsed. May be null.
        c - The char to be searched.
        Returns:
        Always ≥ 0.
      • getTrailingCharCount

        @Nonnegative
        public static int getTrailingCharCount​(@Nullable
                                               String s,
                                               char c)
        Get the number of specified chars, the passed string ends with.
        Parameters:
        s - The string to be parsed. May be null.
        c - The char to be searched.
        Returns:
        Always ≥ 0.
      • getImploded

        @Nonnull
        public static String getImploded​(@Nullable
                                         Iterable<?> aElements)
        Get a concatenated String from all elements of the passed container, without a separator. Even null elements are added.
        Parameters:
        aElements - The container to convert. May be null or empty.
        Returns:
        The concatenated string.
      • getImplodedMapped

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMapped​(@Nullable
                                                             Iterable<? extends ELEMENTTYPE> aElements,
                                                             @Nonnull
                                                             Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all elements of the passed container, without a separator. Even null elements are added.
        Type Parameters:
        ELEMENTTYPE - Iterable element type
        Parameters:
        aElements - The container to convert. May be null or empty.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImploded

        @Nonnull
        public static String getImploded​(@Nonnull
                                         String sSep,
                                         @Nullable
                                         Iterable<?> aElements)
        Get a concatenated String from all elements of the passed container, separated by the specified separator string. Even null elements are added.
        Parameters:
        sSep - The separator to use. May not be null.
        aElements - The container to convert. May be null or empty.
        Returns:
        The concatenated string.
      • getImploded

        @Nonnull
        public static String getImploded​(char cSep,
                                         @Nullable
                                         Iterable<?> aElements)
        Get a concatenated String from all elements of the passed container, separated by the specified separator char. Even null elements are added.
        Parameters:
        cSep - The separator to use.
        aElements - The container to convert. May be null or empty.
        Returns:
        The concatenated string.
      • getImplodedMapped

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMapped​(@Nonnull
                                                             String sSep,
                                                             @Nullable
                                                             Iterable<? extends ELEMENTTYPE> aElements,
                                                             @Nonnull
                                                             Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all elements of the passed container, separated by the specified separator string. Even null elements are added.
        Type Parameters:
        ELEMENTTYPE - The element type of the collection to be imploded
        Parameters:
        sSep - The separator to use. May not be null.
        aElements - The container to convert. May be null or empty.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImplodedMapped

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMapped​(char cSep,
                                                             @Nullable
                                                             Iterable<? extends ELEMENTTYPE> aElements,
                                                             @Nonnull
                                                             Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all elements of the passed container, separated by the specified separator char. Even null elements are added.
        Type Parameters:
        ELEMENTTYPE - The element type of the collection to be imploded
        Parameters:
        cSep - The separator to use.
        aElements - The container to convert. May be null or empty.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImploded

        @Nonnull
        @SafeVarargs
        public static <ELEMENTTYPE> String getImploded​(@Nullable
                                                       ELEMENTTYPE... aElements)
        Get a concatenated String from all elements of the passed array, without a separator.
        Type Parameters:
        ELEMENTTYPE - The type of elements to be imploded.
        Parameters:
        aElements - The container to convert. May be null or empty.
        Returns:
        The concatenated string.
      • getImploded

        @Nonnull
        public static <ELEMENTTYPE> String getImploded​(@Nullable
                                                       ELEMENTTYPE[] aElements,
                                                       @Nonnegative
                                                       int nOfs,
                                                       @Nonnegative
                                                       int nLen)
        Get a concatenated String from all elements of the passed array, without a separator.
        Type Parameters:
        ELEMENTTYPE - The type of elements to be imploded.
        Parameters:
        aElements - The container to convert. May be null or empty.
        nOfs - The offset to start from.
        nLen - The number of elements to implode.
        Returns:
        The concatenated string.
      • getImplodedMapped

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMapped​(@Nullable
                                                             ELEMENTTYPE[] aElements,
                                                             @Nonnull
                                                             Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all elements of the passed array, without a separator.
        Type Parameters:
        ELEMENTTYPE - The type of elements to be imploded.
        Parameters:
        aElements - The container to convert. May be null or empty.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImplodedMapped

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMapped​(@Nullable
                                                             ELEMENTTYPE[] aElements,
                                                             @Nonnegative
                                                             int nOfs,
                                                             @Nonnegative
                                                             int nLen,
                                                             @Nonnull
                                                             Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all elements of the passed array, without a separator.
        Type Parameters:
        ELEMENTTYPE - The type of elements to be imploded.
        Parameters:
        aElements - The container to convert. May be null or empty.
        nOfs - The offset to start from.
        nLen - The number of elements to implode.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImploded

        @Nonnull
        @SafeVarargs
        public static <ELEMENTTYPE> String getImploded​(@Nonnull
                                                       String sSep,
                                                       @Nullable
                                                       ELEMENTTYPE... aElements)
        Get a concatenated String from all elements of the passed array, separated by the specified separator string.
        Type Parameters:
        ELEMENTTYPE - The type of elements to be imploded.
        Parameters:
        sSep - The separator to use. May not be null.
        aElements - The container to convert. May be null or empty.
        Returns:
        The concatenated string.
      • getImploded

        @Nonnull
        @SafeVarargs
        public static <ELEMENTTYPE> String getImploded​(char cSep,
                                                       @Nullable
                                                       ELEMENTTYPE... aElements)
        Get a concatenated String from all elements of the passed array, separated by the specified separator char.
        Type Parameters:
        ELEMENTTYPE - The type of elements to be imploded.
        Parameters:
        cSep - The separator to use.
        aElements - The container to convert. May be null or empty.
        Returns:
        The concatenated string.
      • getImploded

        @Nonnull
        public static <ELEMENTTYPE> String getImploded​(@Nonnull
                                                       String sSep,
                                                       @Nullable
                                                       ELEMENTTYPE[] aElements,
                                                       @Nonnegative
                                                       int nOfs,
                                                       @Nonnegative
                                                       int nLen)
        Get a concatenated String from all elements of the passed array, separated by the specified separator string.
        Type Parameters:
        ELEMENTTYPE - The type of elements to be imploded.
        Parameters:
        sSep - The separator to use. May not be null.
        aElements - The container to convert. May be null or empty.
        nOfs - The offset to start from.
        nLen - The number of elements to implode.
        Returns:
        The concatenated string.
      • getImplodedMapped

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMapped​(@Nonnull
                                                             String sSep,
                                                             @Nullable
                                                             ELEMENTTYPE[] aElements,
                                                             @Nonnull
                                                             Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all elements of the passed array, separated by the specified separator string.
        Type Parameters:
        ELEMENTTYPE - The type of elements to be imploded.
        Parameters:
        sSep - The separator to use. May not be null.
        aElements - The container to convert. May be null or empty.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImplodedMapped

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMapped​(char cSep,
                                                             @Nullable
                                                             ELEMENTTYPE[] aElements,
                                                             @Nonnull
                                                             Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all elements of the passed array, separated by the specified separator char.
        Type Parameters:
        ELEMENTTYPE - The type of elements to be imploded.
        Parameters:
        cSep - The separator to use.
        aElements - The container to convert. May be null or empty.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImplodedMapped

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMapped​(char cSep,
                                                             @Nullable
                                                             ELEMENTTYPE[] aElements,
                                                             @Nonnegative
                                                             int nOfs,
                                                             @Nonnegative
                                                             int nLen,
                                                             @Nonnull
                                                             Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all elements of the passed array, separated by the specified separator char.
        Type Parameters:
        ELEMENTTYPE - The type of elements to be imploded.
        Parameters:
        cSep - The separator to use.
        aElements - The container to convert. May be null or empty.
        nOfs - The offset to start from.
        nLen - The number of elements to implode.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImplodedMapped

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMapped​(@Nonnull
                                                             String sSep,
                                                             @Nullable
                                                             ELEMENTTYPE[] aElements,
                                                             @Nonnegative
                                                             int nOfs,
                                                             @Nonnegative
                                                             int nLen,
                                                             @Nonnull
                                                             Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all elements of the passed array, separated by the specified separator string.
        Type Parameters:
        ELEMENTTYPE - The type of elements to be imploded.
        Parameters:
        sSep - The separator to use. May not be null.
        aElements - The container to convert. May be null or empty.
        nOfs - The offset to start from.
        nLen - The number of elements to implode.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImploded

        @Nonnull
        public static <ELEMENTTYPE> String getImploded​(char cSep,
                                                       @Nullable
                                                       ELEMENTTYPE[] aElements,
                                                       @Nonnegative
                                                       int nOfs,
                                                       @Nonnegative
                                                       int nLen)
        Get a concatenated String from all elements of the passed array, separated by the specified separator char.
        Type Parameters:
        ELEMENTTYPE - The type of elements to be imploded.
        Parameters:
        cSep - The separator to use.
        aElements - The container to convert. May be null or empty.
        nOfs - The offset to start from.
        nLen - The number of elements to implode.
        Returns:
        The concatenated string.
      • getImplodedNonEmpty

        @Nonnull
        public static String getImplodedNonEmpty​(@Nullable
                                                 Iterable<String> aElements)
        Get a concatenated String from all non-null and non empty elements of the passed container without a separator string. This the very generic version of getConcatenatedOnDemand(String, String) for an arbitrary number of elements.
        Parameters:
        aElements - The container to convert. May be null or empty.
        Returns:
        The concatenated string.
      • getImplodedMappedNonEmpty

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMappedNonEmpty​(@Nullable
                                                                     Iterable<? extends ELEMENTTYPE> aElements,
                                                                     @Nonnull
                                                                     Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all non-null and non empty elements of the passed container without a separator string. This the very generic version of getConcatenatedOnDemand(String, String) for an arbitrary number of elements.
        Type Parameters:
        ELEMENTTYPE - Iterable element type
        Parameters:
        aElements - The container to convert. May be null or empty.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImplodedMappedNonEmpty

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMappedNonEmpty​(@Nullable
                                                                     ELEMENTTYPE[] aElements,
                                                                     @Nonnull
                                                                     Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all non-null and non empty elements of the passed container without a separator string. This the very generic version of getConcatenatedOnDemand(String, String) for an arbitrary number of elements.
        Type Parameters:
        ELEMENTTYPE - Array component type
        Parameters:
        aElements - The array to convert. May be null or empty.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImplodedNonEmpty

        @Nonnull
        public static String getImplodedNonEmpty​(@Nonnull
                                                 String sSep,
                                                 @Nullable
                                                 Iterable<String> aElements)
        Get a concatenated String from all non-null and non empty elements of the passed container, separated by the specified separator string. This the very generic version of getConcatenatedOnDemand(String, String, String) for an arbitrary number of elements.
        Parameters:
        sSep - The separator to use. May not be null.
        aElements - The container to convert. May be null or empty.
        Returns:
        The concatenated string.
      • getImplodedNonEmpty

        @Nonnull
        public static String getImplodedNonEmpty​(char cSep,
                                                 @Nullable
                                                 Iterable<String> aElements)
        Get a concatenated String from all non-null and non empty elements of the passed container, separated by the specified separator char. This the very generic version of getConcatenatedOnDemand(String, String, String) for an arbitrary number of elements.
        Parameters:
        cSep - The separator to use.
        aElements - The container to convert. May be null or empty.
        Returns:
        The concatenated string.
      • getImplodedMappedNonEmpty

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMappedNonEmpty​(@Nonnull
                                                                     String sSep,
                                                                     @Nullable
                                                                     Iterable<? extends ELEMENTTYPE> aElements,
                                                                     @Nonnull
                                                                     Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all non-null and non empty elements of the passed container, separated by the specified separator string. This the very generic version of getConcatenatedOnDemand(String, String, String) for an arbitrary number of elements.
        Type Parameters:
        ELEMENTTYPE - The element type of the collection to be imploded
        Parameters:
        sSep - The separator to use. May not be null.
        aElements - The container to convert. May be null or empty.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImplodedMappedNonEmpty

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMappedNonEmpty​(char cSep,
                                                                     @Nullable
                                                                     Iterable<? extends ELEMENTTYPE> aElements,
                                                                     @Nonnull
                                                                     Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all non-null and non empty elements of the passed container, separated by the specified separator char. This the very generic version of getConcatenatedOnDemand(String, String, String) for an arbitrary number of elements.
        Type Parameters:
        ELEMENTTYPE - The element type of the collection to be imploded
        Parameters:
        cSep - The separator to use.
        aElements - The container to convert. May be null or empty.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImplodedNonEmpty

        @Nonnull
        public static String getImplodedNonEmpty​(@Nonnull
                                                 String sSep,
                                                 @Nullable
                                                 String... aElements)
        Get a concatenated String from all elements of the passed array, separated by the specified separator string. This the very generic version of getConcatenatedOnDemand(String, String, String) for an arbitrary number of elements.
        Parameters:
        sSep - The separator to use. May not be null.
        aElements - The container to convert. May be null or empty.
        Returns:
        The concatenated string.
      • getImplodedNonEmpty

        @Nonnull
        public static String getImplodedNonEmpty​(char cSep,
                                                 @Nullable
                                                 String... aElements)
        Get a concatenated String from all elements of the passed array, separated by the specified separator char. This the very generic version of getConcatenatedOnDemand(String, String, String) for an arbitrary number of elements.
        Parameters:
        cSep - The separator to use.
        aElements - The container to convert. May be null or empty.
        Returns:
        The concatenated string.
      • getImplodedMappedNonEmpty

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMappedNonEmpty​(@Nonnull
                                                                     String sSep,
                                                                     @Nullable
                                                                     ELEMENTTYPE[] aElements,
                                                                     @Nonnull
                                                                     Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all elements of the passed array, separated by the specified separator string. This the very generic version of getConcatenatedOnDemand(String, String, String) for an arbitrary number of elements.
        Type Parameters:
        ELEMENTTYPE - Array component type
        Parameters:
        sSep - The separator to use. May not be null.
        aElements - The container to convert. May be null or empty.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImplodedMappedNonEmpty

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMappedNonEmpty​(char cSep,
                                                                     @Nullable
                                                                     ELEMENTTYPE[] aElements,
                                                                     @Nonnull
                                                                     Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all elements of the passed array, separated by the specified separator char. This the very generic version of getConcatenatedOnDemand(String, String, String) for an arbitrary number of elements.
        Type Parameters:
        ELEMENTTYPE - Array component type
        Parameters:
        cSep - The separator to use.
        aElements - The container to convert. May be null or empty.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImplodedNonEmpty

        @Nonnull
        public static String getImplodedNonEmpty​(@Nonnull
                                                 String sSep,
                                                 @Nullable
                                                 String[] aElements,
                                                 @Nonnegative
                                                 int nOfs,
                                                 @Nonnegative
                                                 int nLen)
        Get a concatenated String from all elements of the passed array, separated by the specified separator string. This the very generic version of getConcatenatedOnDemand(String, String, String) for an arbitrary number of elements.
        Parameters:
        sSep - The separator to use. May not be null.
        aElements - The container to convert. May be null or empty.
        nOfs - The offset to start from.
        nLen - The number of elements to implode.
        Returns:
        The concatenated string.
      • getImplodedNonEmpty

        @Nonnull
        public static String getImplodedNonEmpty​(char cSep,
                                                 @Nullable
                                                 String[] aElements,
                                                 @Nonnegative
                                                 int nOfs,
                                                 @Nonnegative
                                                 int nLen)
        Get a concatenated String from all elements of the passed array, separated by the specified separator char. This the very generic version of getConcatenatedOnDemand(String, String, String) for an arbitrary number of elements.
        Parameters:
        cSep - The separator to use.
        aElements - The container to convert. May be null or empty.
        nOfs - The offset to start from.
        nLen - The number of elements to implode.
        Returns:
        The concatenated string.
      • getImplodedMappedNonEmpty

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMappedNonEmpty​(@Nonnull
                                                                     String sSep,
                                                                     @Nullable
                                                                     ELEMENTTYPE[] aElements,
                                                                     @Nonnegative
                                                                     int nOfs,
                                                                     @Nonnegative
                                                                     int nLen,
                                                                     @Nonnull
                                                                     Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all elements of the passed array, separated by the specified separator string. This the very generic version of getConcatenatedOnDemand(String, String, String) for an arbitrary number of elements.
        Type Parameters:
        ELEMENTTYPE - Array component type
        Parameters:
        sSep - The separator to use. May not be null.
        aElements - The container to convert. May be null or empty.
        nOfs - The offset to start from.
        nLen - The number of elements to implode.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImplodedMappedNonEmpty

        @Nonnull
        public static <ELEMENTTYPE> String getImplodedMappedNonEmpty​(char cSep,
                                                                     @Nullable
                                                                     ELEMENTTYPE[] aElements,
                                                                     @Nonnegative
                                                                     int nOfs,
                                                                     @Nonnegative
                                                                     int nLen,
                                                                     @Nonnull
                                                                     Function<? super ELEMENTTYPE,​String> aMapper)
        Get a concatenated String from all elements of the passed array, separated by the specified separator char. This the very generic version of getConcatenatedOnDemand(String, String, String) for an arbitrary number of elements.
        Type Parameters:
        ELEMENTTYPE - Array component type
        Parameters:
        cSep - The separator to use.
        aElements - The container to convert. May be null or empty.
        nOfs - The offset to start from.
        nLen - The number of elements to implode.
        aMapper - The mapping function to convert from ELEMENTTYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImploded

        @Nonnull
        public static <KEYTYPE,​VALUETYPE> String getImploded​(@Nonnull
                                                                   String sSepOuter,
                                                                   @Nonnull
                                                                   String sSepInner,
                                                                   @Nullable
                                                                   Map<KEYTYPE,​VALUETYPE> aElements)
        Get a concatenated String from all elements of the passed map, separated by the specified separator strings.
        Type Parameters:
        KEYTYPE - Map key type
        VALUETYPE - Map value type
        Parameters:
        sSepOuter - The separator to use for separating the map entries. May not be null.
        sSepInner - The separator to use for separating the key from the value. May not be null.
        aElements - The map to convert. May be null or empty.
        Returns:
        The concatenated string.
      • getImploded

        @Nonnull
        public static <KEYTYPE,​VALUETYPE> String getImploded​(char cSepOuter,
                                                                   char cSepInner,
                                                                   @Nullable
                                                                   Map<KEYTYPE,​VALUETYPE> aElements)
        Get a concatenated String from all elements of the passed map, separated by the specified separator chars.
        Type Parameters:
        KEYTYPE - Map key type
        VALUETYPE - Map value type
        Parameters:
        cSepOuter - The separator to use for separating the map entries.
        cSepInner - The separator to use for separating the key from the value.
        aElements - The map to convert. May be null or empty.
        Returns:
        The concatenated string.
      • getImplodedMapped

        @Nonnull
        public static <KEYTYPE,​VALUETYPE> String getImplodedMapped​(@Nonnull
                                                                         String sSepOuter,
                                                                         @Nonnull
                                                                         String sSepInner,
                                                                         @Nullable
                                                                         Map<? extends KEYTYPE,​? extends VALUETYPE> aElements,
                                                                         @Nonnull
                                                                         Function<? super KEYTYPE,​String> aKeyMapper,
                                                                         @Nonnull
                                                                         Function<? super VALUETYPE,​String> aValueMapper)
        Get a concatenated String from all elements of the passed map, separated by the specified separator strings.
        Type Parameters:
        KEYTYPE - Map key type
        VALUETYPE - Map value type
        Parameters:
        sSepOuter - The separator to use for separating the map entries. May not be null.
        sSepInner - The separator to use for separating the key from the value. May not be null.
        aElements - The map to convert. May be null or empty.
        aKeyMapper - The mapping function to convert from KEYTYPE to String. May not be null.
        aValueMapper - The mapping function to convert from VALUETYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getImplodedMapped

        @Nonnull
        public static <KEYTYPE,​VALUETYPE> String getImplodedMapped​(char cSepOuter,
                                                                         char cSepInner,
                                                                         @Nullable
                                                                         Map<? extends KEYTYPE,​? extends VALUETYPE> aElements,
                                                                         @Nonnull
                                                                         Function<? super KEYTYPE,​String> aKeyMapper,
                                                                         @Nonnull
                                                                         Function<? super VALUETYPE,​String> aValueMapper)
        Get a concatenated String from all elements of the passed map, separated by the specified separator chars.
        Type Parameters:
        KEYTYPE - Map key type
        VALUETYPE - Map value type
        Parameters:
        cSepOuter - The separator to use for separating the map entries.
        cSepInner - The separator to use for separating the key from the value.
        aElements - The map to convert. May be null or empty.
        aKeyMapper - The mapping function to convert from KEYTYPE to String. May not be null.
        aValueMapper - The mapping function to convert from VALUETYPE to String. May not be null.
        Returns:
        The concatenated string.
        Since:
        8.5.6
      • getExplodedArray

        @Nonnull
        public static String[] getExplodedArray​(char cSep,
                                                @Nullable
                                                String sElements,
                                                @CheckForSigned
                                                int nMaxItems)
        Take a concatenated String and return the passed String array of all elements in the passed string, using specified separator char.
        Parameters:
        cSep - The separator to use.
        sElements - The concatenated String to convert. May be null or empty.
        nMaxItems - The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.
        Returns:
        The passed collection and never null.
      • getExplodedArray

        @Nonnull
        public static String[] getExplodedArray​(char cSep,
                                                @Nullable
                                                String sElements)
        Take a concatenated String and return the passed String array of all elements in the passed string, using specified separator char.
        Parameters:
        cSep - The separator to use.
        sElements - The concatenated String to convert. May be null or empty.
        Returns:
        The passed collection and never null.
      • getExploded

        @Nonnull
        @ReturnsMutableObject("The passed parameter")
        @CodingStyleguideUnaware
        public static <COLLTYPE extends Collection<String>> COLLTYPE getExploded​(char cSep,
                                                                                 @Nullable
                                                                                 String sElements,
                                                                                 int nMaxItems,
                                                                                 @Nonnull
                                                                                 COLLTYPE aCollection)
        Take a concatenated String and return the passed Collection of all elements in the passed string, using specified separator string.
        Type Parameters:
        COLLTYPE - The collection type to be passed and returned
        Parameters:
        cSep - The separator to use.
        sElements - The concatenated String to convert. May be null or empty.
        nMaxItems - The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.
        aCollection - The non-null target collection that should be filled with the exploded elements
        Returns:
        The passed collection and never null.
      • explode

        public static void explode​(char cSep,
                                   @Nullable
                                   String sElements,
                                   @Nonnull
                                   Consumer<? super String> aConsumer)
        Split the provided string by the provided separator and invoke the consumer for each matched element. The number of returned items is unlimited.
        Parameters:
        cSep - The separator to use.
        sElements - The concatenated String to convert. May be null or empty.
        aConsumer - The non-null consumer that is invoked for each exploded element
      • explode

        public static void explode​(char cSep,
                                   @Nullable
                                   String sElements,
                                   int nMaxItems,
                                   @Nonnull
                                   Consumer<? super String> aConsumer)
        Split the provided string by the provided separator and invoke the consumer for each matched element. The maximum number of elements can be specified.
        Parameters:
        cSep - The separator to use.
        sElements - The concatenated String to convert. May be null or empty.
        nMaxItems - The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.
        aConsumer - The non-null consumer that is invoked for each exploded element
      • getExploded

        @Nonnull
        @ReturnsMutableCopy
        public static ICommonsList<String> getExploded​(char cSep,
                                                       @Nullable
                                                       String sElements)
        Take a concatenated String and return a ICommonsList of all elements in the passed string, using specified separator string.
        Parameters:
        cSep - The separator character to use.
        sElements - The concatenated String to convert. May be null or empty.
        Returns:
        The ICommonsList represented by the passed string. Never null. If the passed input string is null or "" an empty list is returned.
      • getExploded

        @Nonnull
        @ReturnsMutableCopy
        public static ICommonsList<String> getExploded​(char cSep,
                                                       @Nullable
                                                       String sElements,
                                                       int nMaxItems)
        Take a concatenated String and return a ICommonsList of all elements in the passed string, using specified separator string.
        Parameters:
        cSep - The separator character to use.
        sElements - The concatenated String to convert. May be null or empty.
        nMaxItems - The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.
        Returns:
        The ICommonsList represented by the passed string. Never null. If the passed input string is null or "" an empty list is returned.
      • getExploded

        @Nonnull
        @CodingStyleguideUnaware
        public static <COLLTYPE extends Collection<String>> COLLTYPE getExploded​(@Nonnull
                                                                                 String sSep,
                                                                                 @Nullable
                                                                                 String sElements,
                                                                                 int nMaxItems,
                                                                                 @Nonnull
                                                                                 COLLTYPE aCollection)
        Take a concatenated String and return the passed Collection of all elements in the passed string, using specified separator string.
        Type Parameters:
        COLLTYPE - The collection type to be used and returned
        Parameters:
        sSep - The separator to use. May not be null.
        sElements - The concatenated String to convert. May be null or empty.
        nMaxItems - The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.
        aCollection - The non-null target collection that should be filled with the exploded elements
        Returns:
        The passed collection and never null.
      • explode

        public static void explode​(@Nonnull
                                   String sSep,
                                   @Nullable
                                   String sElements,
                                   @Nonnull
                                   Consumer<? super String> aConsumer)
        Split the provided string by the provided separator and invoke the consumer for each matched element.
        Parameters:
        sSep - The separator to use. May not be null.
        sElements - The concatenated String to convert. May be null or empty.
        aConsumer - The non-null consumer that is invoked for each exploded element
      • explode

        public static void explode​(@Nonnull
                                   String sSep,
                                   @Nullable
                                   String sElements,
                                   int nMaxItems,
                                   @Nonnull
                                   Consumer<? super String> aConsumer)
        Split the provided string by the provided separator and invoke the consumer for each matched element. The maximum number of elements can be specified.
        Parameters:
        sSep - The separator to use. May not be null.
        sElements - The concatenated String to convert. May be null or empty.
        nMaxItems - The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.
        aConsumer - The non-null consumer that is invoked for each exploded element
      • getExploded

        @Nonnull
        @ReturnsMutableCopy
        public static ICommonsList<String> getExploded​(@Nonnull
                                                       String sSep,
                                                       @Nullable
                                                       String sElements)
        Take a concatenated String and return a ICommonsList of all elements in the passed string, using specified separator string.
        Parameters:
        sSep - The separator to use. May not be null.
        sElements - The concatenated String to convert. May be null or empty.
        Returns:
        The ICommonsList represented by the passed string. Never null. If the passed input string is null or "" an empty list is returned.
      • getExploded

        @Nonnull
        @ReturnsMutableCopy
        public static ICommonsList<String> getExploded​(@Nonnull
                                                       String sSep,
                                                       @Nullable
                                                       String sElements,
                                                       int nMaxItems)
        Take a concatenated String and return a ICommonsList of all elements in the passed string, using specified separator string.
        Parameters:
        sSep - The separator to use. May not be null.
        sElements - The concatenated String to convert. May be null or empty.
        nMaxItems - The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.
        Returns:
        The ICommonsList represented by the passed string. Never null. If the passed input string is null or "" an empty list is returned.
      • getExplodedToSet

        @Nonnull
        @ReturnsMutableCopy
        public static CommonsHashSet<String> getExplodedToSet​(@Nonnull
                                                              String sSep,
                                                              @Nullable
                                                              String sElements)
        Take a concatenated String and return a Set of all elements in the passed string, using specified separator string.
        Parameters:
        sSep - The separator to use. May not be null.
        sElements - The concatenated String to convert. May be null or empty.
        Returns:
        The Set represented by the passed string. Never null. If the passed input string is null or "" an empty list is returned.
      • getExplodedToOrderedSet

        @Nonnull
        @ReturnsMutableCopy
        public static CommonsLinkedHashSet<String> getExplodedToOrderedSet​(@Nonnull
                                                                           String sSep,
                                                                           @Nullable
                                                                           String sElements)
        Take a concatenated String and return an ordered CommonsLinkedHashSet of all elements in the passed string, using specified separator string.
        Parameters:
        sSep - The separator to use. May not be null.
        sElements - The concatenated String to convert. May be null or empty.
        Returns:
        The ordered Set represented by the passed string. Never null. If the passed input string is null or "" an empty list is returned.
      • getExplodedToSortedSet

        @Nonnull
        @ReturnsMutableCopy
        public static CommonsTreeSet<String> getExplodedToSortedSet​(@Nonnull
                                                                    String sSep,
                                                                    @Nullable
                                                                    String sElements)
        Take a concatenated String and return a sorted CommonsTreeSet of all elements in the passed string, using specified separator string.
        Parameters:
        sSep - The separator to use. May not be null.
        sElements - The concatenated String to convert. May be null or empty.
        Returns:
        The sorted Set represented by the passed string. Never null. If the passed input string is null or "" an empty list is returned.
      • getRepeated

        @Nonnull
        public static String getRepeated​(char cElement,
                                         @Nonnegative
                                         int nRepeats)
        Get the passed string element repeated for a certain number of times. Each string element is simply appended at the end of the string.
        Parameters:
        cElement - The character to get repeated.
        nRepeats - The number of repetitions to retrieve. May not be < 0.
        Returns:
        A non-null string containing the string element for the given number of times.
      • getRepeated

        @Nonnull
        public static String getRepeated​(@Nonnull
                                         String sElement,
                                         @Nonnegative
                                         int nRepeats)
        Get the passed string element repeated for a certain number of times. Each string element is simply appended at the end of the string.
        Parameters:
        sElement - The string to get repeated. May not be null.
        nRepeats - The number of repetitions to retrieve. May not be < 0.
        Returns:
        A non-null string containing the string element for the given number of times.
      • getConcatenatedOnDemand

        @Nonnull
        public static String getConcatenatedOnDemand​(@Nullable
                                                     String sFront,
                                                     @Nullable
                                                     String sEnd)
        Concatenate the strings sFront and sEnd. If either front or back is null or empty only the other element is returned. If both strings are null or empty and empty String is returned.
        Parameters:
        sFront - Front string. May be null.
        sEnd - May be null.
        Returns:
        The concatenated string. Never null.
      • getConcatenatedOnDemand

        @Nonnull
        public static String getConcatenatedOnDemand​(@Nullable
                                                     String sFront,
                                                     @Nullable
                                                     String sSep,
                                                     @Nullable
                                                     String sEnd)
        Concatenate the strings sFront and sEnd by the "sSep" string. If either front or back is null or empty, the separator is not applied.
        Parameters:
        sFront - Front string. May be null.
        sSep - Separator string. May be null.
        sEnd - May be null.
        Returns:
        The concatenated string.
      • getConcatenatedOnDemand

        @Nonnull
        public static String getConcatenatedOnDemand​(@Nullable
                                                     String sFront,
                                                     char cSep,
                                                     @Nullable
                                                     String sEnd)
        Concatenate the strings sFront and sEnd by the "cSep" separator. If either front or back is null or empty, the separator is not applied.
        Parameters:
        sFront - Front string. May be null.
        cSep - Separator character.
        sEnd - May be null.
        Returns:
        The concatenated string.
      • getQuoted

        @Nonnull
        public static String getQuoted​(@Nullable
                                       String sSource)
        Get the provided string quoted or unquoted if it is null.
        Parameters:
        sSource - Source string. May be null.
        Returns:
        The String "null" if the source is null, "'" + sSource + "'" otherwise.
        Since:
        9.2.0
      • appendQuoted

        public static void appendQuoted​(@Nonnull
                                        StringBuilder aTarget,
                                        @Nullable
                                        String sSource)
        Append the provided string quoted or unquoted if it is null.
        Parameters:
        aTarget - The target to write to. May not be null.
        sSource - Source string. May be null.
        Since:
        9.2.0
        See Also:
        getQuoted(String)
      • appendQuoted

        public static void appendQuoted​(@Nonnull
                                        Appendable aTarget,
                                        @Nullable
                                        String sSource)
                                 throws IOException
        Append the provided string quoted or unquoted if it is null.
        Parameters:
        aTarget - The target to write to. May not be null.
        sSource - Source string. May be null.
        Throws:
        IOException - in case of IO error
        Since:
        9.2.0
        See Also:
        getQuoted(String)
      • startsWithIgnoreCase

        public static boolean startsWithIgnoreCase​(@Nullable
                                                   CharSequence aCS,
                                                   char c)
      • getIndexOf

        public static int getIndexOf​(@Nullable
                                     String sText,
                                     @Nullable
                                     String sSearch)
        Get the first index of sSearch within sText.
        Parameters:
        sText - The text to search in. May be null.
        sSearch - The text to search for. May be null.
        Returns:
        The first index of sSearch within sText or -1 if sSearch was not found or if any parameter was null.
        See Also:
        String.indexOf(String)
      • getIndexOf

        public static int getIndexOf​(@Nullable
                                     String sText,
                                     @Nonnegative
                                     int nFromIndex,
                                     @Nullable
                                     String sSearch)
        Get the first index of sSearch within sText starting at index nFromIndex.
        Parameters:
        sText - The text to search in. May be null.
        nFromIndex - The index to start searching in the source string
        sSearch - The text to search for. May be null.
        Returns:
        The first index of sSearch within sText or -1 if sSearch was not found or if any parameter was null.
        See Also:
        String.indexOf(String,int)
      • getLastIndexOf

        public static int getLastIndexOf​(@Nullable
                                         String sText,
                                         @Nullable
                                         String sSearch)
        Get the last index of sSearch within sText.
        Parameters:
        sText - The text to search in. May be null.
        sSearch - The text to search for. May be null.
        Returns:
        The last index of sSearch within sText or -1 if sSearch was not found or if any parameter was null.
        See Also:
        String.lastIndexOf(String)
      • getLastIndexOf

        public static int getLastIndexOf​(@Nullable
                                         String sText,
                                         @Nonnegative
                                         int nFromIndex,
                                         @Nullable
                                         String sSearch)
        Get the last index of sSearch within sText starting at index nFromIndex.
        Parameters:
        sText - The text to search in. May be null.
        nFromIndex - The index to start searching in the source string
        sSearch - The text to search for. May be null.
        Returns:
        The last index of sSearch within sText or -1 if sSearch was not found or if any parameter was null.
        See Also:
        String.lastIndexOf(String,int)
      • getIndexOf

        public static int getIndexOf​(@Nullable
                                     String sText,
                                     char cSearch)
        Get the first index of cSearch within sText.
        Parameters:
        sText - The text to search in. May be null.
        cSearch - The character to search for. May be null.
        Returns:
        The first index of sSearch within sText or -1 if cSearch was not found or if any parameter was null.
        See Also:
        String.indexOf(int)
      • getIndexOf

        public static int getIndexOf​(@Nullable
                                     String sText,
                                     @Nonnegative
                                     int nFromIndex,
                                     char cSearch)
        Get the first index of cSearch within sText starting at index nFromIndex.
        Parameters:
        sText - The text to search in. May be null.
        nFromIndex - The index to start searching in the source string
        cSearch - The character to search for. May be null.
        Returns:
        The first index of sSearch within sText or -1 if cSearch was not found or if any parameter was null.
        See Also:
        String.indexOf(int,int)
      • getLastIndexOf

        public static int getLastIndexOf​(@Nullable
                                         String sText,
                                         char cSearch)
        Get the last index of cSearch within sText.
        Parameters:
        sText - The text to search in. May be null.
        cSearch - The character to search for. May be null.
        Returns:
        The last index of sSearch within sText or -1 if cSearch was not found or if any parameter was null.
        See Also:
        String.lastIndexOf(int)
      • getLastIndexOf

        public static int getLastIndexOf​(@Nullable
                                         String sText,
                                         @Nonnegative
                                         int nFromIndex,
                                         char cSearch)
        Get the last index of cSearch within sText starting at index nFromIndex.
        Parameters:
        sText - The text to search in. May be null.
        nFromIndex - The index to start searching in the source string
        cSearch - The character to search for. May be null.
        Returns:
        The last index of sSearch within sText or -1 if cSearch was not found or if any parameter was null.
        See Also:
        String.lastIndexOf(int,int)
      • getIndexOfIgnoreCase

        public static int getIndexOfIgnoreCase​(@Nullable
                                               String sText,
                                               @Nullable
                                               String sSearch,
                                               @Nonnull
                                               Locale aSortLocale)
        Get the first index of sSearch within sText ignoring case.
        Parameters:
        sText - The text to search in. May be null.
        sSearch - The text to search for. May be null.
        aSortLocale - The locale to be used for case unifying.
        Returns:
        The first index of sSearch within sText or -1 if sSearch was not found or if any parameter was null.
        See Also:
        String.indexOf(String)
      • getIndexOfIgnoreCase

        public static int getIndexOfIgnoreCase​(@Nullable
                                               String sText,
                                               @Nonnegative
                                               int nFromIndex,
                                               @Nullable
                                               String sSearch,
                                               @Nonnull
                                               Locale aSortLocale)
        Get the first index of sSearch within sText ignoring case starting at index nFromIndex.
        Parameters:
        sText - The text to search in. May be null.
        nFromIndex - The index to start searching in the source string
        sSearch - The text to search for. May be null.
        aSortLocale - The locale to be used for case unifying.
        Returns:
        The first index of sSearch within sText or -1 if sSearch was not found or if any parameter was null.
        See Also:
        String.indexOf(String)
      • getLastIndexOfIgnoreCase

        public static int getLastIndexOfIgnoreCase​(@Nullable
                                                   String sText,
                                                   @Nullable
                                                   String sSearch,
                                                   @Nonnull
                                                   Locale aSortLocale)
        Get the last index of sSearch within sText ignoring case.
        Parameters:
        sText - The text to search in. May be null.
        sSearch - The text to search for. May be null.
        aSortLocale - The locale to be used for case unifying.
        Returns:
        The last index of sSearch within sText or -1 if sSearch was not found or if any parameter was null.
        See Also:
        String.lastIndexOf(String)
      • getLastIndexOfIgnoreCase

        public static int getLastIndexOfIgnoreCase​(@Nullable
                                                   String sText,
                                                   @Nonnegative
                                                   int nFromIndex,
                                                   @Nullable
                                                   String sSearch,
                                                   @Nonnull
                                                   Locale aSortLocale)
        Get the last index of sSearch within sText ignoring case starting at index nFromIndex.
        Parameters:
        sText - The text to search in. May be null.
        nFromIndex - The index to start searching in the source string
        sSearch - The text to search for. May be null.
        aSortLocale - The locale to be used for case unifying.
        Returns:
        The last index of sSearch within sText or -1 if sSearch was not found or if any parameter was null.
        See Also:
        String.lastIndexOf(String)
      • getIndexOfIgnoreCase

        public static int getIndexOfIgnoreCase​(@Nullable
                                               String sText,
                                               char cSearch,
                                               @Nonnull
                                               Locale aSortLocale)
        Get the first index of cSearch within sText ignoring case.
        Parameters:
        sText - The text to search in. May be null.
        cSearch - The char to search for. May be null.
        aSortLocale - The locale to be used for case unifying.
        Returns:
        The first index of sSearch within sText or -1 if sSearch was not found or if any parameter was null.
        See Also:
        String.indexOf(int)
      • getIndexOfIgnoreCase

        public static int getIndexOfIgnoreCase​(@Nullable
                                               String sText,
                                               @Nonnegative
                                               int nFromIndex,
                                               char cSearch,
                                               @Nonnull
                                               Locale aSortLocale)
        Get the first index of cSearch within sText ignoring case starting at index nFromIndex.
        Parameters:
        sText - The text to search in. May be null.
        nFromIndex - The index to start searching in the source string
        cSearch - The char to search for. May be null.
        aSortLocale - The locale to be used for case unifying.
        Returns:
        The first index of sSearch within sText or -1 if sSearch was not found or if any parameter was null.
        See Also:
        String.indexOf(int)
      • getLastIndexOfIgnoreCase

        public static int getLastIndexOfIgnoreCase​(@Nullable
                                                   String sText,
                                                   char cSearch,
                                                   @Nonnull
                                                   Locale aSortLocale)
        Get the last index of cSearch within sText ignoring case.
        Parameters:
        sText - The text to search in. May be null.
        cSearch - The char to search for. May be null.
        aSortLocale - The locale to be used for case unifying.
        Returns:
        The last index of sSearch within sText or -1 if sSearch was not found or if any parameter was null.
        See Also:
        String.lastIndexOf(int)
      • getLastIndexOfIgnoreCase

        public static int getLastIndexOfIgnoreCase​(@Nullable
                                                   String sText,
                                                   @Nonnegative
                                                   int nFromIndex,
                                                   char cSearch,
                                                   @Nonnull
                                                   Locale aSortLocale)
        Get the last index of cSearch within sText ignoring case starting at index nFromIndex.
        Parameters:
        sText - The text to search in. May be null.
        nFromIndex - The index to start searching in the source string
        cSearch - The char to search for. May be null.
        aSortLocale - The locale to be used for case unifying.
        Returns:
        The last index of sSearch within sText or -1 if sSearch was not found or if any parameter was null.
        See Also:
        String.lastIndexOf(int)
      • contains

        public static boolean contains​(@Nullable
                                       String sText,
                                       @Nullable
                                       String sSearch)
        Check if sSearch is contained within sText.
        Parameters:
        sText - The text to search in. May be null.
        sSearch - The text to search for. May be null.
        Returns:
        true if sSearch is contained in sText, false otherwise.
        See Also:
        String.contains(CharSequence)
      • contains

        public static boolean contains​(@Nullable
                                       String sText,
                                       char cSearch)
        Check if cSearch is contained within sText.
        Parameters:
        sText - The text to search in. May be null.
        cSearch - The character to search for. May be null.
        Returns:
        true if cSearch is contained in sText, false otherwise.
        See Also:
        String.contains(CharSequence)
      • containsIgnoreCase

        public static boolean containsIgnoreCase​(@Nullable
                                                 String sText,
                                                 @Nullable
                                                 String sSearch,
                                                 @Nonnull
                                                 Locale aSortLocale)
        Check if sSearch is contained within sText ignoring case.
        Parameters:
        sText - The text to search in. May be null.
        sSearch - The text to search for. May be null.
        aSortLocale - The locale to be used for case unifying.
        Returns:
        true if sSearch is contained in sText, false otherwise.
        See Also:
        String.contains(CharSequence)
      • containsIgnoreCase

        public static boolean containsIgnoreCase​(@Nullable
                                                 String sText,
                                                 char cSearch,
                                                 @Nonnull
                                                 Locale aSortLocale)
        Check if cSearch is contained within sText ignoring case.
        Parameters:
        sText - The text to search in. May be null.
        cSearch - The char to search for. May be null.
        aSortLocale - The locale to be used for case unifying.
        Returns:
        true if sSearch is contained in sText, false otherwise.
        See Also:
        String.indexOf(int)
      • containsAny

        public static boolean containsAny​(@Nullable
                                          char[] aInput,
                                          @Nonnull
                                          char[] aSearchChars)
        Check if any of the passed searched characters is contained in the input char array.
        Parameters:
        aInput - The input char array. May be null.
        aSearchChars - The char array to search. May not be null.
        Returns:
        true if at least any of the search char is contained in the input char array, false otherwise.
      • containsAny

        public static boolean containsAny​(@Nullable
                                          String sInput,
                                          @Nonnull
                                          char[] aSearchChars)
        Check if any of the passed searched characters in contained in the input string.
        Parameters:
        sInput - The input string. May be null.
        aSearchChars - The char array to search. May not be null.
        Returns:
        true if at least any of the search char is contained in the input char array, false otherwise.
      • getOccurrenceCount

        @Nonnegative
        public static int getOccurrenceCount​(@Nullable
                                             String sText,
                                             @Nullable
                                             String sSearch)
        Count the number of occurrences of sSearch within sText.
        Parameters:
        sText - The text to search in. May be null.
        sSearch - The text to search for. May be null.
        Returns:
        A non-negative number of occurrences.
      • getOccurrenceCountIgnoreCase

        @Nonnegative
        public static int getOccurrenceCountIgnoreCase​(@Nullable
                                                       String sText,
                                                       @Nullable
                                                       String sSearch,
                                                       @Nonnull
                                                       Locale aSortLocale)
        Count the number of occurrences of sSearch within sText ignoring case.
        Parameters:
        sText - The text to search in. May be null.
        sSearch - The text to search for. May be null.
        aSortLocale - The locale to be used for case unifying.
        Returns:
        A non-negative number of occurrences.
      • getOccurrenceCount

        @Nonnegative
        public static int getOccurrenceCount​(@Nullable
                                             String sText,
                                             char cSearch)
        Count the number of occurrences of cSearch within sText.
        Parameters:
        sText - The text to search in. May be null.
        cSearch - The character to search for.
        Returns:
        A non-negative number of occurrences.
      • getOccurrenceCountIgnoreCase

        @Nonnegative
        public static int getOccurrenceCountIgnoreCase​(@Nullable
                                                       String sText,
                                                       char cSearch,
                                                       @Nonnull
                                                       Locale aSortLocale)
        Count the number of occurrences of cSearch within sText ignoring case.
        Parameters:
        sText - The text to search in. May be null.
        cSearch - The character to search for.
        aSortLocale - The locale to be used for case unifying.
        Returns:
        A non-negative number of occurrences.
      • trimLeadingWhitespaces

        @Nullable
        @CheckReturnValue
        public static String trimLeadingWhitespaces​(@Nullable
                                                    String s)
        Remove any leading whitespaces from the passed string.
        Parameters:
        s - the String to be trimmed
        Returns:
        the original String with all leading whitespaces removed
      • trimTrailingWhitespaces

        @Nullable
        @CheckReturnValue
        public static String trimTrailingWhitespaces​(@Nullable
                                                     String s)
        Remove any trailing whitespaces from the passed string.
        Parameters:
        s - the String to be cut
        Returns:
        the original String with all trailing whitespaces removed
      • trimStart

        @Nullable
        @CheckReturnValue
        public static String trimStart​(@Nullable
                                       String sSrc,
                                       @Nonnegative
                                       int nCount)
        Trim the passed lead from the source value. If the source value does not start with the passed lead, nothing happens.
        Parameters:
        sSrc - The input source string
        nCount - The number of characters to trim at the end.
        Returns:
        The trimmed string, or an empty string if nCount is ≥ the length of the source string
      • trimEnd

        @Nullable
        @CheckReturnValue
        public static String trimEnd​(@Nullable
                                     String sSrc,
                                     @Nonnegative
                                     int nCount)
        Trim the passed tail from the source value. If the source value does not end with the passed tail, nothing happens.
        Parameters:
        sSrc - The input source string
        nCount - The number of characters to trim at the end.
        Returns:
        The trimmed string, or an empty string if nCount is ≥ the length of the source string
      • trimStartAndEnd

        @Nullable
        @CheckReturnValue
        public static String trimStartAndEnd​(@Nullable
                                             String sSrc,
                                             char cLead,
                                             char cTail)
        Trim the passed lead and tail from the source value. If the source value does not start with the passed lead and does not end with the passed tail, nothing happens.
        Parameters:
        sSrc - The input source string
        cLead - The char to be trimmed of the beginning
        cTail - The char to be trimmed of the end
        Returns:
        The trimmed string, or the original input string, if the lead and the tail were not found
        See Also:
        trimStart(String, char), trimEnd(String, char), trimStartAndEnd(String, char)
      • getFirstChar

        public static char getFirstChar​(@Nullable
                                        CharSequence aCS)
        Get the first character of the passed character sequence
        Parameters:
        aCS - The source character sequence
        Returns:
        CGlobal.ILLEGAL_CHAR if the passed sequence was empty
      • getFirstChar

        public static char getFirstChar​(@Nullable
                                        char[] aChars)
        Get the first character of the passed array
        Parameters:
        aChars - The character array
        Returns:
        CGlobal.ILLEGAL_CHAR if the passed array was empty
      • getLastChar

        public static char getLastChar​(@Nullable
                                       CharSequence aCS)
        Get the last character of the passed character sequence
        Parameters:
        aCS - The source character sequence
        Returns:
        CGlobal.ILLEGAL_CHAR if the passed sequence was empty
      • getLastChar

        public static char getLastChar​(@Nullable
                                       char[] aChars)
        Get the last character of the passed array
        Parameters:
        aChars - The character array
        Returns:
        CGlobal.ILLEGAL_CHAR if the passed array was empty
      • getCharacterCount

        @Nonnegative
        public static int getCharacterCount​(int nValue)
        Get the number of characters the passed value would occupy in a string representation.
        Copied from java.lang.Integer#StringSize
        Parameters:
        nValue - The integer value to check. May be be positive or negative.
        Returns:
        Number of characters required. Alyways > 0.
      • getCharacterCount

        @Nonnegative
        public static int getCharacterCount​(long nValue)
        Get the number of characters the passed value would occupy in a string representation.
        Parameters:
        nValue - The long value to check. May be be positive or negative.
        Returns:
        Number of characters required. Always > 0.
      • replaceAllSafe

        public static String replaceAllSafe​(@Nullable
                                            String sInputString,
                                            @Nonnull
                                            String sSearchText,
                                            @Nullable
                                            CharSequence aReplacementText)
        Same as replaceAll(String, String, CharSequence) but allowing for a null new-value, which is than interpreted as an empty string instead.
        Parameters:
        sInputString - The input string where the text should be replace. If this parameter is null or empty, no replacement is done.
        sSearchText - The string to be replaced. May neither be null nor empty.
        aReplacementText - The string with the replacement. May be null or empty.
        Returns:
        The input string as is, if the input string is empty or if the string to be replaced is not contained.
      • replaceAll

        @Nullable
        public static String replaceAll​(@Nullable
                                        String sInputString,
                                        @Nonnull
                                        String sSearchText,
                                        @Nonnull
                                        CharSequence aReplacementText)
        This is a fast replacement for String.replace(CharSequence, CharSequence). The problem with the mentioned String method is, that is uses internally regular expressions which use a synchronized block to compile the patterns. This method is inherently thread safe since String is immutable and we're operating on different temporary StringBuilder objects.
        Parameters:
        sInputString - The input string where the text should be replace. If this parameter is null or empty, no replacement is done.
        sSearchText - The string to be replaced. May neither be null nor empty.
        aReplacementText - The string with the replacement. May not be null but may be empty.
        Returns:
        The input string as is, if the input string is empty or if the search pattern and the replacement are equal or if the string to be replaced is not contained.
      • replaceAll

        @Nullable
        public static String replaceAll​(@Nullable
                                        String sInputString,
                                        char cSearchChar,
                                        char cReplacementChar)
        This is a fast replacement for String.replace(char, char) for characters. The problem with the mentioned String method is, that is uses internally regular expressions which use a synchronized block to compile the patterns. This method is inherently thread safe since String is immutable and we're operating on different temporary StringBuilder objects.
        Parameters:
        sInputString - The input string where the text should be replace. If this parameter is null or empty, no replacement is done.
        cSearchChar - The character to be replaced.
        cReplacementChar - The character with the replacement.
        Returns:
        The input string as is, if the input string is empty or if the search pattern and the replacement are equal or if the string to be replaced is not contained.
      • replaceAllRepeatedly

        @Nullable
        public static String replaceAllRepeatedly​(@Nullable
                                                  String sInputString,
                                                  @Nonnull
                                                  String sSearchText,
                                                  @Nonnull
                                                  String sReplacementText)
        Just calls replaceAll as long as there are still replacements found
        Parameters:
        sInputString - The input string where the text should be replace. If this parameter is null or empty, no replacement is done.
        sSearchText - The string to be replaced. May neither be null nor empty.
        sReplacementText - The string with the replacement. May not be null but may be empty.
        Returns:
        The input string as is, if the input string is empty or if the string to be replaced is not contained.
      • getReplaceMultipleResultLength

        public static int getReplaceMultipleResultLength​(@Nonnull
                                                         char[] aInputString,
                                                         @Nonnull @Nonempty
                                                         char[] aSearchChars,
                                                         @Nonnull @Nonempty
                                                         char[][] aReplacementStrings)
        Get the result length (in characters) when replacing all patterns with the replacements on the passed input array.
        Parameters:
        aInputString - Input char array. May not be null.
        aSearchChars - The one-character search patterns. May not be null.
        aReplacementStrings - The replacements to be performed. May not be null. The first dimension of this array must have exactly the same amount of elements as the patterns parameter array.
        Returns:
        CGlobal.ILLEGAL_UINT if no replacement was needed, and therefore the length of the input array could be used.
      • replaceMultiple

        @Nonnull
        public static char[] replaceMultiple​(@Nullable
                                             String sInputString,
                                             @Nonnull
                                             char[] aSearchChars,
                                             @Nonnull
                                             char[][] aReplacementStrings)
        Optimized replace method that replaces a set of characters with a set of strings. This method was created for efficient XML special character replacements!
        Parameters:
        sInputString - The input string.
        aSearchChars - The characters to replace.
        aReplacementStrings - The new strings to be inserted instead. Must have the same array length as aPatterns.
        Returns:
        The replaced version of the string or an empty char array if the input string was null.
      • replaceMultiple

        @Nonnull
        public static char[] replaceMultiple​(@Nullable
                                             char[] aInput,
                                             @Nonnull
                                             char[] aSearchChars,
                                             @Nonnull
                                             char[][] aReplacementStrings)
        Optimized replace method that replaces a set of characters with a set of strings. This method was created for efficient XML special character replacements!
        Parameters:
        aInput - The input string.
        aSearchChars - The characters to replace.
        aReplacementStrings - The new strings to be inserted instead. Must have the same array length as aPatterns.
        Returns:
        The replaced version of the string or an empty char array if the input string was null.
      • replaceMultipleTo

        @Nonnegative
        public static int replaceMultipleTo​(@Nullable
                                            String sInputString,
                                            @Nonnull
                                            char[] aSearchChars,
                                            @Nonnull
                                            char[][] aReplacementStrings,
                                            @Nonnull
                                            Writer aTarget)
                                     throws IOException
        Specialized version of replaceMultiple(String, char[], char[][]) where the object where the output should be appended is passed in as a parameter. This has the advantage, that not length calculation needs to take place!
        Parameters:
        sInputString - The input string.
        aSearchChars - The characters to replace.
        aReplacementStrings - The new strings to be inserted instead. Must have the same array length as aPatterns.
        aTarget - Where the replaced objects should be written to. May not be null.
        Returns:
        The number of replacements performed. Always ≥ 0.
        Throws:
        IOException - In case writing to the Writer fails
      • replaceMultipleTo

        @Nonnegative
        public static int replaceMultipleTo​(@Nullable
                                            char[] aInput,
                                            @Nonnull
                                            char[] aSearchChars,
                                            @Nonnull
                                            char[][] aReplacementStrings,
                                            @Nonnull
                                            Writer aTarget)
                                     throws IOException
        Specialized version of replaceMultiple(String, char[], char[][]) where the object where the output should be appended is passed in as a parameter. This has the advantage, that not length calculation needs to take place!
        Parameters:
        aInput - The input char array. May not be null.
        aSearchChars - The characters to replace.
        aReplacementStrings - The new strings to be inserted instead. Must have the same array length as aPatterns.
        aTarget - Where the replaced objects should be written to. May not be null.
        Returns:
        The number of replacements performed. Always ≥ 0.
        Throws:
        IOException - In case writing to the Writer fails
      • replaceMultipleTo

        @Nonnegative
        public static int replaceMultipleTo​(@Nullable
                                            char[] aInput,
                                            @Nonnegative
                                            int nOfs,
                                            @Nonnegative
                                            int nLen,
                                            @Nonnull
                                            char[] aSearchChars,
                                            @Nonnull
                                            char[][] aReplacementStrings,
                                            @Nonnull
                                            Writer aTarget)
                                     throws IOException
        Specialized version of replaceMultiple(String, char[], char[][]) where the object where the output should be appended is passed in as a parameter. This has the advantage, that not length calculation needs to take place!
        Parameters:
        aInput - The input char array. May be null.
        nOfs - Offset into input array. Must be ≥ 0.
        nLen - Number of characters from input array. Must be ≥ 0.
        aSearchChars - The characters to replace.
        aReplacementStrings - The new strings to be inserted instead. Must have the same array length as aPatterns.
        aTarget - Where the replaced objects should be written to. May not be null.
        Returns:
        The number of replacements performed. Always ≥ 0.
        Throws:
        IOException - In case writing to the Writer fails
      • replaceMultiple

        @Nonnull
        public static char[] replaceMultiple​(@Nullable
                                             String sInputString,
                                             @Nonnull
                                             char[] aSearchChars,
                                             char cReplacementChar)
        Optimized replace method that replaces a set of characters with another character. This method was created for efficient unsafe character replacements!
        Parameters:
        sInputString - The input string.
        aSearchChars - The characters to replace.
        cReplacementChar - The new char to be used instead of the search chars.
        Returns:
        The replaced version of the string or an empty char array if the input string was null.
      • replaceMultipleTo

        public static void replaceMultipleTo​(@Nullable
                                             String sInputString,
                                             @Nonnull
                                             char[] aSearchChars,
                                             char cReplacementChar,
                                             @Nonnull
                                             StringBuilder aTarget)
        Optimized replace method that replaces a set of characters with another character. This method was created for efficient unsafe character replacements!
        Parameters:
        sInputString - The input string.
        aSearchChars - The characters to replace.
        cReplacementChar - The new char to be used instead of the search chars.
        aTarget - The target StringBuilder to write the result to. May not be null.
      • replaceMultipleTo

        public static void replaceMultipleTo​(@Nullable
                                             String sInputString,
                                             @Nonnull
                                             char[] aSearchChars,
                                             char cReplacementChar,
                                             @Nonnull
                                             Writer aTarget)
                                      throws IOException
        Optimized replace method that replaces a set of characters with another character. This method was created for efficient unsafe character replacements!
        Parameters:
        sInputString - The input string.
        aSearchChars - The characters to replace.
        cReplacementChar - The new char to be used instead of the search chars.
        aTarget - The target writer to write the result to. May not be null.
        Throws:
        IOException - in case writing to the Writer fails
        Since:
        8.6.3
      • replaceMultipleAsString

        @Nonnull
        public static String replaceMultipleAsString​(@Nullable
                                                     String sInputString,
                                                     @Nonnull
                                                     char[] aSearchChars,
                                                     char cReplacementChar)
        Optimized replace method that replaces a set of characters with another character. This method was created for efficient unsafe character replacements!
        Parameters:
        sInputString - The input string.
        aSearchChars - The characters to replace.
        cReplacementChar - The new char to be used instead of the search chars.
        Returns:
        The replaced version of the string or an empty char array if the input string was null.
        Since:
        8.6.3
      • replaceMultiple

        @Nullable
        public static String replaceMultiple​(@Nullable
                                             String sInputString,
                                             @Nullable
                                             Map<String,​String> aTransTable)
        Perform all string replacements on the input string as defined by the passed map. All replacements are done using replaceAll(String,String,CharSequence) which is ok.
        Parameters:
        sInputString - The input string where the text should be replaced. May be null.
        aTransTable - The map with the replacements to execute. If null is passed, the input string is not altered.
        Returns:
        null if the input string was null.
      • replaceMultiple

        @Nullable
        public static String replaceMultiple​(@Nullable
                                             String sInputString,
                                             @Nullable
                                             String[] aSearchTexts,
                                             @Nullable
                                             String[] aReplacementTexts)
        Perform all string replacements on the input string as defined by the passed map. All replacements are done using replaceAll(String,String,CharSequence) which is ok.
        Parameters:
        sInputString - The input string where the text should be replaced. May be null.
        aSearchTexts - The texts to be searched. If null is passed, the input string is not altered.
        aReplacementTexts - The texts to be used as the replacements. This array must have exactly the same number of elements than the searched texts! If null is passed, the input string is not altered.
        Returns:
        null if the input string was null. The unmodified input string if no search/replace patterns where provided.
      • removeAll

        @Nullable
        public static String removeAll​(@Nullable
                                       String sInputString,
                                       char cRemoveChar)
        Remove all occurrences of the passed character from the specified input string
        Parameters:
        sInputString - The input string where the character should be removed. If this parameter is null or empty, no removing is done.
        cRemoveChar - The character to be removed.
        Returns:
        The input string as is, if the input string is empty or if the remove char is not contained.
      • removeAll

        @Nullable
        public static String removeAll​(@Nullable
                                       String sInputString,
                                       @Nullable
                                       String sRemoveString)
        Remove all occurrences of the passed character from the specified input string
        Parameters:
        sInputString - The input string where the character should be removed. If this parameter is null or empty, no removing is done.
        sRemoveString - The String to be removed. May be null or empty in which case nothing happens.
        Returns:
        The input string as is, if the input string is empty or if the remove string is empty or not contained.
      • getLength

        @Nonnegative
        public static int getLength​(@Nullable
                                    CharSequence aCS)
        Get the length of the passed character sequence.
        Parameters:
        aCS - The character sequence who's length is to be determined. May be null.
        Returns:
        0 if the parameter is null, its length otherwise.
        See Also:
        CharSequence.length()
      • getNotNull

        @Nonnull
        public static String getNotNull​(@Nullable
                                        String s)
        Get the passed string but never return null. If the passed parameter is null an empty string is returned.
        Parameters:
        s - The parameter to be not null.
        Returns:
        An empty string if the passed parameter is null, the passed string otherwise.
      • getNotNull

        @Nullable
        public static String getNotNull​(@Nullable
                                        String s,
                                        @Nullable
                                        String sDefaultIfNull)
        Get the passed string but never return null. If the passed parameter is null the second parameter is returned.
        Parameters:
        s - The parameter to be not null.
        sDefaultIfNull - The value to be used if the first parameter is null. May be null but in this case the call to this method is obsolete.
        Returns:
        The passed default value if the string is null, otherwise the input string.
      • getNotNull

        @Nullable
        public static String getNotNull​(@Nullable
                                        String s,
                                        @Nonnull
                                        Supplier<String> aDefaultIfNull)
        Get the passed string but never return null. If the passed parameter is null the second parameter is returned.
        Parameters:
        s - The parameter to be not null.
        aDefaultIfNull - The value supplier to be used if the first parameter is null. May not be null.
        Returns:
        The passed default value if the string is null, otherwise the input string.
        Since:
        10.2.0
      • getNotNull

        @Nonnull
        public static CharSequence getNotNull​(@Nullable
                                              CharSequence s)
        Get the passed CharSequence but never return null. If the passed parameter is null an empty string is returned.
        Parameters:
        s - The parameter to be not null.
        Returns:
        An empty string if the passed parameter is null, the passed CharSequence otherwise.
      • getNotNull

        @Nullable
        public static CharSequence getNotNull​(@Nullable
                                              CharSequence s,
                                              @Nullable
                                              CharSequence sDefaultIfNull)
        Get the passed CharSequence but never return null. If the passed parameter is null the second parameter is returned.
        Parameters:
        s - The parameter to be not null.
        sDefaultIfNull - The value to be used if the first parameter is null. May be null but in this case the call to this method is obsolete.
        Returns:
        The passed default value if the string is null, otherwise the input CharSequence.
      • getNotNull

        @Nullable
        public static CharSequence getNotNull​(@Nullable
                                              CharSequence s,
                                              @Nonnull
                                              Supplier<? extends CharSequence> aDefaultIfNull)
        Get the passed CharSequence but never return null. If the passed parameter is null the second parameter is returned.
        Parameters:
        s - The parameter to be not null.
        aDefaultIfNull - The value supplier to be used if the first parameter is null. May not be null.
        Returns:
        The passed default value if the string is null, otherwise the input CharSequence.
        Since:
        10.2.0
      • getNotEmpty

        @Nullable
        public static String getNotEmpty​(@Nullable
                                         String s,
                                         @Nullable
                                         String sDefaultIfEmpty)
        Get the passed string but never return an empty string. If the passed parameter is null or empty the second parameter is returned.
        Parameters:
        s - The parameter to be not null nor empty.
        sDefaultIfEmpty - The value to be used if the first parameter is null or empty. May be null but in this case the call to this method is obsolete.
        Returns:
        The passed default value if the string is null or empty, otherwise the input string.
      • getNotEmpty

        @Nullable
        public static String getNotEmpty​(@Nullable
                                         String s,
                                         @Nonnull
                                         Supplier<String> aDefaultIfEmpty)
        Get the passed string but never return an empty string. If the passed parameter is null or empty the second parameter is returned.
        Parameters:
        s - The parameter to be not null nor empty.
        aDefaultIfEmpty - The value supplier to be used if the first parameter is null or empty. May not be null.
        Returns:
        The passed default value if the string is null or empty, otherwise the input string.
        Since:
        10.2.0
      • getNotEmpty

        @Nullable
        public static CharSequence getNotEmpty​(@Nullable
                                               CharSequence s,
                                               @Nullable
                                               CharSequence sDefaultIfEmpty)
        Get the passed char sequence but never return an empty char sequence. If the passed parameter is null or empty the second parameter is returned.
        Parameters:
        s - The parameter to be not null nor empty.
        sDefaultIfEmpty - The value to be used if the first parameter is null or empty. May be null but in this case the call to this method is obsolete.
        Returns:
        The passed default value if the char sequence is null or empty, otherwise the input char sequence.
      • getNotEmpty

        @Nullable
        public static CharSequence getNotEmpty​(@Nullable
                                               CharSequence s,
                                               @Nullable
                                               Supplier<? extends CharSequence> aDefaultIfEmpty)
        Get the passed char sequence but never return an empty char sequence. If the passed parameter is null or empty the second parameter is returned.
        Parameters:
        s - The parameter to be not null nor empty.
        aDefaultIfEmpty - The value supplier to be used if the first parameter is null or empty. May not be null.
        Returns:
        The passed default value if the char sequence is null or empty, otherwise the input char sequence.
        Since:
        10.2.0
      • getToString

        @Nonnull
        public static String getToString​(@Nullable
                                         Object aObject)
        Convert the passed object to a string using the Object.toString() method.
        Parameters:
        aObject - The value to be converted. May be null.
        Returns:
        An empty string in case the passed object was null. Never null.
        See Also:
        Object.toString()
      • getToString

        @Nullable
        public static String getToString​(@Nullable
                                         Object aObject,
                                         @Nullable
                                         String sNullValue)
        Convert the passed object to a string using the Object.toString() method or otherwise return the passed default value.
        Parameters:
        aObject - The value to be converted. May be null.
        sNullValue - The value to be returned in case the passed object is null. May be null itself.
        Returns:
        The passed default value in case the passed object was null or the result of Object.toString() on the passed object.
        See Also:
        Object.toString()
      • getWithoutLeadingChar

        @Nonnull
        public static String getWithoutLeadingChar​(@Nullable
                                                   String sStr)
        Get the passed string without the first char.
        Parameters:
        sStr - The source string. May be null.
        Returns:
        An empty, non-null string if the passed string has a length ≤ 1.
      • getWithoutLeadingChars

        @Nonnull
        public static String getWithoutLeadingChars​(@Nullable
                                                    String sStr,
                                                    @Nonnegative
                                                    int nCount)
        Get the passed string without the specified number of leading chars.
        Parameters:
        sStr - The source string. May be null.
        nCount - The number of chars to remove.
        Returns:
        An empty, non-null string if the passed string has a length ≤ nCount.
      • getWithoutTrailingChar

        @Nonnull
        public static String getWithoutTrailingChar​(@Nullable
                                                    String sStr)
        Get the passed string without the last char.
        Parameters:
        sStr - The source string. May be null.
        Returns:
        An empty, non-null string if the passed string has a length ≤ 1.
      • getWithoutTrailingChars

        @Nonnull
        public static String getWithoutTrailingChars​(@Nullable
                                                     String sStr,
                                                     @Nonnegative
                                                     int nCount)
        Get the passed string without the specified number of trailing chars.
        Parameters:
        sStr - The source string. May be null.
        nCount - The number of chars to remove.
        Returns:
        An empty, non-null string if the passed string has a length ≤ nCount.
      • getWithoutAnySpaces

        @Nonnull
        public static String getWithoutAnySpaces​(@Nullable
                                                 String sStr)
        Get the passed string where all spaces (white spaces or unicode spaces) have been removed.
        Parameters:
        sStr - The source string. May be null
        Returns:
        A non-null string representing the passed string without any spaces
      • getUntilFirstIncl

        @Nullable
        public static String getUntilFirstIncl​(@Nullable
                                               String sStr,
                                               char cSearch)
        Get everything from the string up to and including the first passed char.
        Parameters:
        sStr - The source string. May be null.
        cSearch - The character to search.
        Returns:
        null if the passed string does not contain the search character.
      • getUntilFirstExcl

        @Nullable
        public static String getUntilFirstExcl​(@Nullable
                                               String sStr,
                                               char cSearch)
        Get everything from the string up to and excluding first the passed char.
        Parameters:
        sStr - The source string. May be null.
        cSearch - The character to search.
        Returns:
        null if the passed string does not contain the search character.
      • getUntilFirstIncl

        @Nullable
        public static String getUntilFirstIncl​(@Nullable
                                               String sStr,
                                               @Nullable
                                               String sSearch)
        Get everything from the string up to and including the first passed string.
        Parameters:
        sStr - The source string. May be null.
        sSearch - The string to search. May be null.
        Returns:
        null if the passed string does not contain the search string. If the search string is empty, the empty string is returned.
      • getUntilFirstExcl

        @Nullable
        public static String getUntilFirstExcl​(@Nullable
                                               String sStr,
                                               @Nullable
                                               String sSearch)
        Get everything from the string up to and excluding the first passed string.
        Parameters:
        sStr - The source string. May be null.
        sSearch - The string to search. May be null.
        Returns:
        null if the passed string does not contain the search string. If the search string is empty, the empty string is returned.
      • getUntilLastIncl

        @Nullable
        public static String getUntilLastIncl​(@Nullable
                                              String sStr,
                                              char cSearch)
        Get everything from the string up to and including the first passed char.
        Parameters:
        sStr - The source string. May be null.
        cSearch - The character to search.
        Returns:
        null if the passed string does not contain the search character.
      • getUntilLastExcl

        @Nullable
        public static String getUntilLastExcl​(@Nullable
                                              String sStr,
                                              char cSearch)
        Get everything from the string up to and excluding first the passed char.
        Parameters:
        sStr - The source string. May be null.
        cSearch - The character to search.
        Returns:
        null if the passed string does not contain the search character.
      • getUntilLastIncl

        @Nullable
        public static String getUntilLastIncl​(@Nullable
                                              String sStr,
                                              @Nullable
                                              String sSearch)
        Get everything from the string up to and including the first passed string.
        Parameters:
        sStr - The source string. May be null.
        sSearch - The string to search. May be null.
        Returns:
        null if the passed string does not contain the search string. If the search string is empty, the empty string is returned.
      • getUntilLastExcl

        @Nullable
        public static String getUntilLastExcl​(@Nullable
                                              String sStr,
                                              @Nullable
                                              String sSearch)
        Get everything from the string up to and excluding the first passed string.
        Parameters:
        sStr - The source string. May be null.
        sSearch - The string to search. May be null.
        Returns:
        null if the passed string does not contain the search string. If the search string is empty, the empty string is returned.
      • getFromFirstIncl

        @Nullable
        public static String getFromFirstIncl​(@Nullable
                                              String sStr,
                                              char cSearch)
        Get everything from the string from and including the first passed char.
        Parameters:
        sStr - The source string. May be null.
        cSearch - The character to search.
        Returns:
        null if the passed string does not contain the search character.
      • getFromFirstExcl

        @Nullable
        public static String getFromFirstExcl​(@Nullable
                                              String sStr,
                                              char cSearch)
        Get everything from the string from and excluding the first passed char.
        Parameters:
        sStr - The source string. May be null.
        cSearch - The character to search.
        Returns:
        null if the passed string does not contain the search character.
      • getFromFirstIncl

        @Nullable
        public static String getFromFirstIncl​(@Nullable
                                              String sStr,
                                              @Nullable
                                              String sSearch)
        Get everything from the string from and including the passed string.
        Parameters:
        sStr - The source string. May be null.
        sSearch - The string to search. May be null.
        Returns:
        null if the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
      • getFromFirstExcl

        @Nullable
        public static String getFromFirstExcl​(@Nullable
                                              String sStr,
                                              @Nullable
                                              String sSearch)
        Get everything from the string from and excluding the passed string.
        Parameters:
        sStr - The source string. May be null.
        sSearch - The string to search. May be null.
        Returns:
        null if the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
      • getFromLastIncl

        @Nullable
        public static String getFromLastIncl​(@Nullable
                                             String sStr,
                                             char cSearch)
        Get everything from the string from and including the first passed char.
        Parameters:
        sStr - The source string. May be null.
        cSearch - The character to search.
        Returns:
        null if the passed string does not contain the search character.
      • getFromLastExcl

        @Nullable
        public static String getFromLastExcl​(@Nullable
                                             String sStr,
                                             char cSearch)
        Get everything from the string from and excluding the first passed char.
        Parameters:
        sStr - The source string. May be null.
        cSearch - The character to search.
        Returns:
        null if the passed string does not contain the search character.
      • getFromLastIncl

        @Nullable
        public static String getFromLastIncl​(@Nullable
                                             String sStr,
                                             @Nullable
                                             String sSearch)
        Get everything from the string from and including the passed string.
        Parameters:
        sStr - The source string. May be null.
        sSearch - The string to search. May be null.
        Returns:
        null if the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
      • getFromLastExcl

        @Nullable
        public static String getFromLastExcl​(@Nullable
                                             String sStr,
                                             @Nullable
                                             String sSearch)
        Get everything from the string from and excluding the passed string.
        Parameters:
        sStr - The source string. May be null.
        sSearch - The string to search. May be null.
        Returns:
        null if the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
      • getFirstToken

        @Nullable
        public static String getFirstToken​(@Nullable
                                           String sStr,
                                           char cSearch)
        Get the first token up to (and excluding) the separating character.
        Parameters:
        sStr - The string to search. May be null.
        cSearch - The search character.
        Returns:
        The passed string if no such separator token was found.
      • getFirstToken

        @Nullable
        public static String getFirstToken​(@Nullable
                                           String sStr,
                                           @Nullable
                                           String sSearch)
        Get the first token up to (and excluding) the separating string.
        Parameters:
        sStr - The string to search. May be null.
        sSearch - The search string. May be null.
        Returns:
        The passed string if no such separator token was found.
      • getLastToken

        @Nullable
        public static String getLastToken​(@Nullable
                                          String sStr,
                                          char cSearch)
        Get the last token from (and excluding) the separating character.
        Parameters:
        sStr - The string to search. May be null.
        cSearch - The search character.
        Returns:
        The passed string if no such separator token was found.
      • getLastToken

        @Nullable
        public static String getLastToken​(@Nullable
                                          String sStr,
                                          @Nullable
                                          String sSearch)
        Get the last token from (and excluding) the separating string.
        Parameters:
        sStr - The string to search. May be null.
        sSearch - The search string. May be null.
        Returns:
        The passed string if no such separator token was found.
      • removeMultiple

        @Nonnull
        public static String removeMultiple​(@Nullable
                                            String sInputString,
                                            @Nonnull
                                            char[] aRemoveChars)
        Optimized remove method that removes a set of characters from an input string!
        Parameters:
        sInputString - The input string.
        aRemoveChars - The characters to remove. May not be null.
        Returns:
        The version of the string without the passed characters or an empty String if the input string was null.
      • iterateChars

        public static void iterateChars​(@Nullable
                                        String sInputString,
                                        @Nonnull
                                        ICharConsumer aConsumer)
        Iterate all characters and pass them to the provided consumer.
        Parameters:
        sInputString - Input String to use. May be null or empty.
        aConsumer - The consumer to be used. May not be null.
      • iterateCodePoints

        public static void iterateCodePoints​(@Nullable
                                             String sInputString,
                                             @Nonnull
                                             IntConsumer aConsumer)
        Iterate all code points and pass them to the provided consumer. This implementation is approximately 20% quicker than CharSequence.codePoints().forEachOrdered(c)
        Parameters:
        sInputString - Input String to use. May be null or empty.
        aConsumer - The consumer to be used. May not be null.
      • encodeCharToBytes

        @Nonnull
        @ReturnsMutableCopy
        public static byte[] encodeCharToBytes​(@Nonnull
                                               char[] aCharArray,
                                               @Nonnull
                                               Charset aCharset)
        Encode a char array to a byte array using the provided charset. This does the same as new String (aCharArray).getBytes (aCharset) just without the intermediate objects.
        Parameters:
        aCharset - Charset to be used. May not be null.
        aCharArray - The char array to be encoded. May not be null.
        Returns:
        The created byte array. Never null.
        Since:
        8.6.4
      • encodeCharToBytes

        @Nonnull
        @ReturnsMutableCopy
        public static byte[] encodeCharToBytes​(@Nonnull
                                               char[] aCharArray,
                                               @Nonnegative
                                               int nOfs,
                                               @Nonnegative
                                               int nLen,
                                               @Nonnull
                                               Charset aCharset)
        Encode a char array to a byte array using the provided charset. This does the same as new String (aCharArray).getBytes (aCharset) just without the intermediate objects.
        Parameters:
        aCharset - Charset to be used. May not be null.
        aCharArray - The char array to be encoded. May not be null.
        nOfs - Offset into char array. Must be ≥ 0.
        nLen - Chars to encode. Must be ≥ 0.
        Returns:
        The created byte array. Never null.
        Since:
        8.6.4
      • decodeBytesToChars

        @Nonnull
        public static char[] decodeBytesToChars​(@Nonnull
                                                byte[] aByteArray,
                                                @Nonnull
                                                Charset aCharset)
        Decode a byte array to a char array using the provided charset. This does the same as new String (aByteArray, aCharset) just without the intermediate objects.
        Parameters:
        aByteArray - The byte array to be decoded. May not be null.
        aCharset - Charset to be used. May not be null.
        Returns:
        The created char array. Never null.
        Since:
        8.6.4
      • decodeBytesToChars

        @Nonnull
        public static char[] decodeBytesToChars​(@Nonnull
                                                byte[] aByteArray,
                                                @Nonnegative
                                                int nOfs,
                                                @Nonnegative
                                                int nLen,
                                                @Nonnull
                                                Charset aCharset)
        Decode a byte array to a char array using the provided charset. This does the same as new String (aByteArray, aCharset) just without the intermediate objects.
        Parameters:
        aByteArray - The byte array to be decoded. May not be null.
        nOfs - Offset into byte array. Must be ≥ 0.
        nLen - Bytes to encode. Must be ≥ 0.
        aCharset - Charset to be used. May not be null.
        Returns:
        The created char array. Never null.
        Since:
        8.6.4