Package com.helger.commons.string
Class StringHelper
- java.lang.Object
-
- com.helger.commons.string.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStringHelper.ImploderBuilderA simple builder that allows to implode collections of arguments with a lot of customization.static classStringHelper.ImploderBuilderMapA simple builder that allows to implode maps of arguments with a lot of customization.
-
Field Summary
Fields Modifier and Type Field Description static intSTRING_NOT_FOUNDThe constant to be returned if an String.indexOf call did not find a match!
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidappendQuoted(Appendable aTarget, String sSource)Append the provided string quoted or unquoted if it isnull.static voidappendQuoted(StringBuilder aTarget, String sSource)Append the provided string quoted or unquoted if it isnull.static booleancontains(String sText, char cSearch)Check if cSearch is contained within sText.static booleancontains(String sText, String sSearch)Check if sSearch is contained within sText.static booleancontainsAny(char[] aInput, char[] aSearchChars)Check if any of the passed searched characters is contained in the input char array.static booleancontainsAny(CharSequence aCS, ICharPredicate aFilter)Check if the passedCharSequencecontains any character matching the provided filter.static booleancontainsAny(String sInput, char[] aSearchChars)Check if any of the passed searched characters in contained in the input string.static booleancontainsAny(String sStr, ICharPredicate aFilter)Check if the passedStringcontains any character matching the provided filter.static booleancontainsIgnoreCase(String sText, char cSearch, Locale aSortLocale)Check if cSearch is contained within sText ignoring case.static booleancontainsIgnoreCase(String sText, String sSearch, Locale aSortLocale)Check if sSearch is contained within sText ignoring case.static booleancontainsNone(CharSequence aCS, ICharPredicate aFilter)Check if the passedCharSequencecontains no character matching the provided filter.static booleancontainsNone(String sStr, ICharPredicate aFilter)Check if the passedStringcontains no character matching the provided filter.static booleancontainsOnly(CharSequence aCS, ICharPredicate aFilter)Check if the passedCharSequencecontains only characters matching the provided filter.static booleancontainsOnly(String sStr, ICharPredicate aFilter)Check if the passedStringcontains only characters matching the provided filter.static char[]decodeBytesToChars(byte[] aByteArray, int nOfs, int nLen, Charset aCharset)Decode a byte array to a char array using the provided charset.static char[]decodeBytesToChars(byte[] aByteArray, Charset aCharset)Decode a byte array to a char array using the provided charset.static byte[]encodeCharToBytes(char[] aCharArray, int nOfs, int nLen, Charset aCharset)Encode a char array to a byte array using the provided charset.static byte[]encodeCharToBytes(char[] aCharArray, Charset aCharset)Encode a char array to a byte array using the provided charset.static booleanendsWith(CharSequence aCS, char c)static booleanendsWith(CharSequence aCS, CharSequence aSearch)static booleanendsWith(String sStr, String sSearch)static booleanendsWithAny(CharSequence aCS, char[] aChars)static booleanendsWithIgnoreCase(CharSequence aCS, char c)static booleanendsWithIgnoreCase(String sStr, String sSearch)static voidexplode(char cSep, String sElements, int nMaxItems, Consumer<? super String> aConsumer)Split the provided string by the provided separator and invoke the consumer for each matched element.static voidexplode(char cSep, String sElements, Consumer<? super String> aConsumer)Split the provided string by the provided separator and invoke the consumer for each matched element.static voidexplode(String sSep, String sElements, int nMaxItems, Consumer<? super String> aConsumer)Split the provided string by the provided separator and invoke the consumer for each matched element.static voidexplode(String sSep, String sElements, Consumer<? super String> aConsumer)Split the provided string by the provided separator and invoke the consumer for each matched element.static intgetCharacterCount(int nValue)Get the number of characters the passed value would occupy in a string representation.
Copied from java.lang.Integer#StringSizestatic intgetCharacterCount(long nValue)Get the number of characters the passed value would occupy in a string representation.static intgetCharCount(char[] aChars, char cSearch)static intgetCharCount(String s, char cSearch)static StringgetConcatenatedOnDemand(String sFront, char cSep, String sEnd)Concatenate the strings sFront and sEnd by the "cSep" separator.static StringgetConcatenatedOnDemand(String sFront, String sEnd)Concatenate the strings sFront and sEnd.static StringgetConcatenatedOnDemand(String sFront, String sSep, String sEnd)Concatenate the strings sFront and sEnd by the "sSep" string.static StringgetCutAfterLength(String sValue, int nMaxLength)static StringgetCutAfterLength(String sValue, int nMaxLength, String sNewSuffix)static ICommonsList<String>getExploded(char cSep, String sElements)Take a concatenated String and return aICommonsListof all elements in the passed string, using specified separator string.static ICommonsList<String>getExploded(char cSep, String sElements, int nMaxItems)Take a concatenated String and return aICommonsListof all elements in the passed string, using specified separator string.static <COLLTYPE extends Collection<String>>
COLLTYPEgetExploded(char cSep, String sElements, int nMaxItems, COLLTYPE aCollection)Take a concatenated String and return the passed Collection of all elements in the passed string, using specified separator string.static ICommonsList<String>getExploded(String sSep, String sElements)Take a concatenated String and return aICommonsListof all elements in the passed string, using specified separator string.static ICommonsList<String>getExploded(String sSep, String sElements, int nMaxItems)Take a concatenated String and return aICommonsListof all elements in the passed string, using specified separator string.static <COLLTYPE extends Collection<String>>
COLLTYPEgetExploded(String sSep, String sElements, int nMaxItems, COLLTYPE aCollection)Take a concatenated String and return the passed Collection of all elements in the passed string, using specified separator string.static String[]getExplodedArray(char cSep, String sElements)Take a concatenated String and return the passed String array of all elements in the passed string, using specified separator char.static String[]getExplodedArray(char cSep, String sElements, int nMaxItems)Take a concatenated String and return the passed String array of all elements in the passed string, using specified separator char.static CommonsLinkedHashSet<String>getExplodedToOrderedSet(String sSep, String sElements)Take a concatenated String and return an orderedCommonsLinkedHashSetof all elements in the passed string, using specified separator string.static CommonsHashSet<String>getExplodedToSet(String sSep, String sElements)Take a concatenated String and return aSetof all elements in the passed string, using specified separator string.static CommonsTreeSet<String>getExplodedToSortedSet(String sSep, String sElements)Take a concatenated String and return a sortedCommonsTreeSetof all elements in the passed string, using specified separator string.static chargetFirstChar(char[] aChars)Get the first character of the passed arraystatic chargetFirstChar(CharSequence aCS)Get the first character of the passed character sequencestatic StringgetFirstToken(String sStr, char cSearch)Get the first token up to (and excluding) the separating character.static StringgetFirstToken(String sStr, String sSearch)Get the first token up to (and excluding) the separating string.static StringgetFromFirstExcl(String sStr, char cSearch)Get everything from the string from and excluding the first passed char.static StringgetFromFirstExcl(String sStr, String sSearch)Get everything from the string from and excluding the passed string.static StringgetFromFirstIncl(String sStr, char cSearch)Get everything from the string from and including the first passed char.static StringgetFromFirstIncl(String sStr, String sSearch)Get everything from the string from and including the passed string.static StringgetFromLastExcl(String sStr, char cSearch)Get everything from the string from and excluding the first passed char.static StringgetFromLastExcl(String sStr, String sSearch)Get everything from the string from and excluding the passed string.static StringgetFromLastIncl(String sStr, char cSearch)Get everything from the string from and including the first passed char.static StringgetFromLastIncl(String sStr, String sSearch)Get everything from the string from and including the passed string.static intgetHexByte(char cHigh, char cLow)static chargetHexChar(int n)Get the matching hex digit as a lower case character.static chargetHexCharUpperCase(int n)Get the matching hex digit as an upper case character.static byte[]getHexDecoded(char[] aInput)static byte[]getHexDecoded(char[] aInput, int nOfs, int nLen)static byte[]getHexDecoded(String sInput)static StringgetHexEncoded(byte[] aInput)Convert a byte array to a hexadecimal encoded string.static StringgetHexEncoded(byte[] aInput, int nOfs, int nLen)Convert a byte array to a hexadecimal encoded string.static StringgetHexEncoded(String sInput, Charset aCharset)Convert a string to a byte array and than to a hexadecimal encoded string.static StringgetHexString(byte nValue)static StringgetHexString(int nValue)static StringgetHexString(long nValue)static StringgetHexString(short nValue)static StringgetHexStringLeadingZero(byte nValue, int nDigits)static StringgetHexStringLeadingZero(int nValue, int nDigits)static StringgetHexStringLeadingZero(long nValue, int nDigits)static StringgetHexStringLeadingZero(short nValue, int nDigits)static StringgetHexStringLeadingZero2(byte nValue)static intgetHexValue(char c)Get the decimal value of the passed hex characterstatic <KEYTYPE,VALUETYPE>
StringgetImploded(char cSepOuter, char cSepInner, Map<KEYTYPE,VALUETYPE> aElements)Get a concatenated String from all elements of the passed map, separated by the specified separator chars.static <ELEMENTTYPE>
StringgetImploded(char cSep, ELEMENTTYPE... aElements)Get a concatenated String from all elements of the passed array, separated by the specified separator char.static <ELEMENTTYPE>
StringgetImploded(char cSep, ELEMENTTYPE[] aElements, int nOfs, int nLen)Get a concatenated String from all elements of the passed array, separated by the specified separator char.static StringgetImploded(char cSep, Iterable<?> aElements)Get a concatenated String from all elements of the passed container, separated by the specified separator char.static <ELEMENTTYPE>
StringgetImploded(ELEMENTTYPE... aElements)Get a concatenated String from all elements of the passed array, without a separator.static <ELEMENTTYPE>
StringgetImploded(ELEMENTTYPE[] aElements, int nOfs, int nLen)Get a concatenated String from all elements of the passed array, without a separator.static StringgetImploded(Iterable<?> aElements)Get a concatenated String from all elements of the passed container, without a separator.static <ELEMENTTYPE>
StringgetImploded(String sSep, ELEMENTTYPE... aElements)Get a concatenated String from all elements of the passed array, separated by the specified separator string.static <ELEMENTTYPE>
StringgetImploded(String sSep, ELEMENTTYPE[] aElements, int nOfs, int nLen)Get a concatenated String from all elements of the passed array, separated by the specified separator string.static StringgetImploded(String sSep, Iterable<?> aElements)Get a concatenated String from all elements of the passed container, separated by the specified separator string.static <KEYTYPE,VALUETYPE>
StringgetImploded(String sSepOuter, String sSepInner, Map<KEYTYPE,VALUETYPE> aElements)Get a concatenated String from all elements of the passed map, separated by the specified separator strings.static <KEYTYPE,VALUETYPE>
StringgetImplodedMapped(char cSepOuter, char cSepInner, Map<? extends KEYTYPE,? extends VALUETYPE> aElements, Function<? super KEYTYPE,String> aKeyMapper, Function<? super VALUETYPE,String> aValueMapper)Get a concatenated String from all elements of the passed map, separated by the specified separator chars.static <ELEMENTTYPE>
StringgetImplodedMapped(char cSep, ELEMENTTYPE[] aElements, int nOfs, int nLen, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all elements of the passed array, separated by the specified separator char.static <ELEMENTTYPE>
StringgetImplodedMapped(char cSep, ELEMENTTYPE[] aElements, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all elements of the passed array, separated by the specified separator char.static <ELEMENTTYPE>
StringgetImplodedMapped(char cSep, Iterable<? extends ELEMENTTYPE> aElements, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all elements of the passed container, separated by the specified separator char.static <ELEMENTTYPE>
StringgetImplodedMapped(ELEMENTTYPE[] aElements, int nOfs, int nLen, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all elements of the passed array, without a separator.static <ELEMENTTYPE>
StringgetImplodedMapped(ELEMENTTYPE[] aElements, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all elements of the passed array, without a separator.static <ELEMENTTYPE>
StringgetImplodedMapped(Iterable<? extends ELEMENTTYPE> aElements, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all elements of the passed container, without a separator.static <ELEMENTTYPE>
StringgetImplodedMapped(String sSep, ELEMENTTYPE[] aElements, int nOfs, int nLen, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all elements of the passed array, separated by the specified separator string.static <ELEMENTTYPE>
StringgetImplodedMapped(String sSep, ELEMENTTYPE[] aElements, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all elements of the passed array, separated by the specified separator string.static <ELEMENTTYPE>
StringgetImplodedMapped(String sSep, Iterable<? extends ELEMENTTYPE> aElements, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all elements of the passed container, separated by the specified separator string.static <KEYTYPE,VALUETYPE>
StringgetImplodedMapped(String sSepOuter, String sSepInner, Map<? extends KEYTYPE,? extends VALUETYPE> aElements, Function<? super KEYTYPE,String> aKeyMapper, Function<? super VALUETYPE,String> aValueMapper)Get a concatenated String from all elements of the passed map, separated by the specified separator strings.static <ELEMENTTYPE>
StringgetImplodedMappedNonEmpty(char cSep, ELEMENTTYPE[] aElements, int nOfs, int nLen, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all elements of the passed array, separated by the specified separator char.static <ELEMENTTYPE>
StringgetImplodedMappedNonEmpty(char cSep, ELEMENTTYPE[] aElements, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all elements of the passed array, separated by the specified separator char.static <ELEMENTTYPE>
StringgetImplodedMappedNonEmpty(char cSep, Iterable<? extends ELEMENTTYPE> aElements, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all non-nulland non empty elements of the passed container, separated by the specified separator char.static <ELEMENTTYPE>
StringgetImplodedMappedNonEmpty(ELEMENTTYPE[] aElements, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all non-nulland non empty elements of the passed container without a separator string.static <ELEMENTTYPE>
StringgetImplodedMappedNonEmpty(Iterable<? extends ELEMENTTYPE> aElements, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all non-nulland non empty elements of the passed container without a separator string.static <ELEMENTTYPE>
StringgetImplodedMappedNonEmpty(String sSep, ELEMENTTYPE[] aElements, int nOfs, int nLen, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all elements of the passed array, separated by the specified separator string.static <ELEMENTTYPE>
StringgetImplodedMappedNonEmpty(String sSep, ELEMENTTYPE[] aElements, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all elements of the passed array, separated by the specified separator string.static <ELEMENTTYPE>
StringgetImplodedMappedNonEmpty(String sSep, Iterable<? extends ELEMENTTYPE> aElements, Function<? super ELEMENTTYPE,String> aMapper)Get a concatenated String from all non-nulland non empty elements of the passed container, separated by the specified separator string.static StringgetImplodedNonEmpty(char cSep, Iterable<String> aElements)Get a concatenated String from all non-nulland non empty elements of the passed container, separated by the specified separator char.static StringgetImplodedNonEmpty(char cSep, String... aElements)Get a concatenated String from all elements of the passed array, separated by the specified separator char.static StringgetImplodedNonEmpty(char cSep, String[] aElements, int nOfs, int nLen)Get a concatenated String from all elements of the passed array, separated by the specified separator char.static StringgetImplodedNonEmpty(Iterable<String> aElements)Get a concatenated String from all non-nulland non empty elements of the passed container without a separator string.static StringgetImplodedNonEmpty(String sSep, Iterable<String> aElements)Get a concatenated String from all non-nulland non empty elements of the passed container, separated by the specified separator string.static StringgetImplodedNonEmpty(String sSep, String... aElements)Get a concatenated String from all elements of the passed array, separated by the specified separator string.static StringgetImplodedNonEmpty(String sSep, String[] aElements, int nOfs, int nLen)Get a concatenated String from all elements of the passed array, separated by the specified separator string.static intgetIndexOf(String sText, char cSearch)Get the first index of cSearch within sText.static intgetIndexOf(String sText, int nFromIndex, char cSearch)Get the first index of cSearch within sText starting at index nFromIndex.static intgetIndexOf(String sText, int nFromIndex, String sSearch)Get the first index of sSearch within sText starting at index nFromIndex.static intgetIndexOf(String sText, String sSearch)Get the first index of sSearch within sText.static intgetIndexOfIgnoreCase(String sText, char cSearch, Locale aSortLocale)Get the first index of cSearch within sText ignoring case.static intgetIndexOfIgnoreCase(String sText, int nFromIndex, char cSearch, Locale aSortLocale)Get the first index of cSearch within sText ignoring case starting at index nFromIndex.static intgetIndexOfIgnoreCase(String sText, int nFromIndex, String sSearch, Locale aSortLocale)Get the first index of sSearch within sText ignoring case starting at index nFromIndex.static intgetIndexOfIgnoreCase(String sText, String sSearch, Locale aSortLocale)Get the first index of sSearch within sText ignoring case.static chargetLastChar(char[] aChars)Get the last character of the passed arraystatic chargetLastChar(CharSequence aCS)Get the last character of the passed character sequencestatic intgetLastIndexOf(String sText, char cSearch)Get the last index of cSearch within sText.static intgetLastIndexOf(String sText, int nFromIndex, char cSearch)Get the last index of cSearch within sText starting at index nFromIndex.static intgetLastIndexOf(String sText, int nFromIndex, String sSearch)Get the last index of sSearch within sText starting at index nFromIndex.static intgetLastIndexOf(String sText, String sSearch)Get the last index of sSearch within sText.static intgetLastIndexOfIgnoreCase(String sText, char cSearch, Locale aSortLocale)Get the last index of cSearch within sText ignoring case.static intgetLastIndexOfIgnoreCase(String sText, int nFromIndex, char cSearch, Locale aSortLocale)Get the last index of cSearch within sText ignoring case starting at index nFromIndex.static intgetLastIndexOfIgnoreCase(String sText, int nFromIndex, String sSearch, Locale aSortLocale)Get the last index of sSearch within sText ignoring case starting at index nFromIndex.static intgetLastIndexOfIgnoreCase(String sText, String sSearch, Locale aSortLocale)Get the last index of sSearch within sText ignoring case.static StringgetLastToken(String sStr, char cSearch)Get the last token from (and excluding) the separating character.static StringgetLastToken(String sStr, String sSearch)Get the last token from (and excluding) the separating string.static intgetLeadingCharCount(String s, char c)Get the number of specified chars, the passed string starts with.static intgetLeadingWhitespaceCount(String s)Get the number of leading white spaces according toCharacter.isWhitespace(char)static StringgetLeadingZero(int nValue, int nChars)static StringgetLeadingZero(long nValue, int nChars)static StringgetLeadingZero(Byte aValue, int nChars)static StringgetLeadingZero(Integer aValue, int nChars)static StringgetLeadingZero(Long aValue, int nChars)static StringgetLeadingZero(Short aValue, int nChars)static StringgetLeadingZero(String sValue, int nChars)static intgetLength(CharSequence aCS)Get the length of the passed character sequence.static intgetLineCount(String s)static intgetLineCount(String s, char cLineSep)static CharSequencegetNotEmpty(CharSequence s, CharSequence sDefaultIfEmpty)Get the passed char sequence but never return an empty char sequence.static CharSequencegetNotEmpty(CharSequence s, Supplier<? extends CharSequence> aDefaultIfEmpty)Get the passed char sequence but never return an empty char sequence.static StringgetNotEmpty(String s, String sDefaultIfEmpty)Get the passed string but never return an empty string.static StringgetNotEmpty(String s, Supplier<String> aDefaultIfEmpty)Get the passed string but never return an empty string.static CharSequencegetNotNull(CharSequence s)Get the passedCharSequencebut never returnnull.static CharSequencegetNotNull(CharSequence s, CharSequence sDefaultIfNull)Get the passedCharSequencebut never returnnull.static CharSequencegetNotNull(CharSequence s, Supplier<? extends CharSequence> aDefaultIfNull)Get the passedCharSequencebut never returnnull.static StringgetNotNull(String s)Get the passed string but never returnnull.static StringgetNotNull(String s, String sDefaultIfNull)Get the passed string but never returnnull.static StringgetNotNull(String s, Supplier<String> aDefaultIfNull)Get the passed string but never returnnull.static intgetOccurrenceCount(String sText, char cSearch)Count the number of occurrences of cSearch within sText.static intgetOccurrenceCount(String sText, String sSearch)Count the number of occurrences of sSearch within sText.static intgetOccurrenceCountIgnoreCase(String sText, char cSearch, Locale aSortLocale)Count the number of occurrences of cSearch within sText ignoring case.static intgetOccurrenceCountIgnoreCase(String sText, String sSearch, Locale aSortLocale)Count the number of occurrences of sSearch within sText ignoring case.static StringgetQuoted(String sSource)Get the provided string quoted or unquoted if it isnull.static StringgetRepeated(char cElement, int nRepeats)Get the passed string element repeated for a certain number of times.static StringgetRepeated(String sElement, int nRepeats)Get the passed string element repeated for a certain number of times.static intgetReplaceMultipleResultLength(char[] aInputString, char[] aSearchChars, char[][] aReplacementStrings)Get the result length (in characters) when replacing all patterns with the replacements on the passed input array.static StringgetReverse(String sStr)static StringgetToString(Object aObject)Convert the passed object to a string using theObject.toString()method.static StringgetToString(Object aObject, String sNullValue)Convert the passed object to a string using theObject.toString()method or otherwise return the passed default value.static intgetTrailingCharCount(String s, char c)Get the number of specified chars, the passed string ends with.static intgetTrailingWhitespaceCount(String s)Get the number of trailing white spaces according toCharacter.isWhitespace(char)static StringgetUntilFirstExcl(String sStr, char cSearch)Get everything from the string up to and excluding first the passed char.static StringgetUntilFirstExcl(String sStr, String sSearch)Get everything from the string up to and excluding the first passed string.static StringgetUntilFirstIncl(String sStr, char cSearch)Get everything from the string up to and including the first passed char.static StringgetUntilFirstIncl(String sStr, String sSearch)Get everything from the string up to and including the first passed string.static StringgetUntilLastExcl(String sStr, char cSearch)Get everything from the string up to and excluding first the passed char.static StringgetUntilLastExcl(String sStr, String sSearch)Get everything from the string up to and excluding the first passed string.static StringgetUntilLastIncl(String sStr, char cSearch)Get everything from the string up to and including the first passed char.static StringgetUntilLastIncl(String sStr, String sSearch)Get everything from the string up to and including the first passed string.static StringgetWithLeading(int nValue, int nMinLen, char cFront)Get a string that is filled at the beginning with the passed character until the minimum length is reached.static StringgetWithLeading(long nValue, int nMinLen, char cFront)Get a string that is filled at the beginning with the passed character until the minimum length is reached.static StringgetWithLeading(String sSrc, int nMinLen, char cFront)Get a string that is filled at the beginning with the passed character until the minimum length is reached.static StringgetWithoutAnySpaces(String sStr)Get the passed string where all spaces (white spaces or unicode spaces) have been removed.static StringgetWithoutLeadingChar(String sStr)Get the passed string without the first char.static StringgetWithoutLeadingChars(String sStr, int nCount)Get the passed string without the specified number of leading chars.static StringgetWithoutTrailingChar(String sStr)Get the passed string without the last char.static StringgetWithoutTrailingChars(String sStr, int nCount)Get the passed string without the specified number of trailing chars.static StringgetWithTrailing(String sSrc, int nMinLen, char cEnd)Get a string that is filled at the end with the passed character until the minimum length is reached.static booleanhasNoText(CharSequence aCS)Check if the string isnullor empty.static booleanhasNoText(String sStr)Check if the string isnullor empty.static booleanhasNoTextAfterTrim(String s)Check if the string isnullor empty after trimming.static booleanhasText(CharSequence aCS)Check if the string contains any char.static booleanhasText(String sStr)Check if the string contains any char.static booleanhasTextAfterTrim(String s)Check if the string neithernullnor empty after trimming.static StringHelper.ImploderBuilderimploder()static StringHelper.ImploderBuilderMapimploderMap()static booleanisAllWhitespace(CharSequence s)Check if the passed character sequence is only whitespace or not.static booleanisEmpty(CharSequence aCS)Check if the string isnullor empty.static booleanisEmpty(String sStr)Check if the string isnullor empty.static booleanisEmptyAfterTrim(String s)Check if the string isnullor empty after trimming.static booleanisNotEmpty(CharSequence aCS)Check if the string contains any char.static booleanisNotEmpty(String sStr)Check if the string contains any char.static booleanisNotEmptyAfterTrim(String s)Check if the string neithernullnor empty after trimming.static voiditerateChars(String sInputString, ICharConsumer aConsumer)Iterate all characters and pass them to the provided consumer.static voiditerateCodePoints(String sInputString, IntConsumer aConsumer)Iterate all code points and pass them to the provided consumer.static StringremoveAll(String sInputString, char cRemoveChar)Remove all occurrences of the passed character from the specified input stringstatic StringremoveAll(String sInputString, String sRemoveString)Remove all occurrences of the passed character from the specified input stringstatic StringremoveMultiple(String sInputString, char[] aRemoveChars)Optimized remove method that removes a set of characters from an input string!static StringreplaceAll(String sInputString, char cSearchChar, char cReplacementChar)This is a fast replacement forString.replace(char, char)for characters.static StringreplaceAll(String sInputString, String sSearchText, CharSequence aReplacementText)This is a fast replacement forString.replace(CharSequence, CharSequence).static StringreplaceAllRepeatedly(String sInputString, String sSearchText, String sReplacementText)Just callsreplaceAllas long as there are still replacements foundstatic StringreplaceAllSafe(String sInputString, String sSearchText, CharSequence aReplacementText)Same asreplaceAll(String, String, CharSequence)but allowing for anullnew-value, which is than interpreted as an empty string instead.static char[]replaceMultiple(char[] aInput, char[] aSearchChars, char[][] aReplacementStrings)Optimized replace method that replaces a set of characters with a set of strings.static char[]replaceMultiple(String sInputString, char[] aSearchChars, char cReplacementChar)Optimized replace method that replaces a set of characters with another character.static char[]replaceMultiple(String sInputString, char[] aSearchChars, char[][] aReplacementStrings)Optimized replace method that replaces a set of characters with a set of strings.static StringreplaceMultiple(String sInputString, String[] aSearchTexts, String[] aReplacementTexts)Perform all string replacements on the input string as defined by the passed map.static StringreplaceMultiple(String sInputString, Map<String,String> aTransTable)Perform all string replacements on the input string as defined by the passed map.static StringreplaceMultipleAsString(String sInputString, char[] aSearchChars, char cReplacementChar)Optimized replace method that replaces a set of characters with another character.static intreplaceMultipleTo(char[] aInput, char[] aSearchChars, char[][] aReplacementStrings, Writer aTarget)Specialized version ofreplaceMultiple(String, char[], char[][])where the object where the output should be appended is passed in as a parameter.static intreplaceMultipleTo(char[] aInput, int nOfs, int nLen, char[] aSearchChars, char[][] aReplacementStrings, Writer aTarget)Specialized version ofreplaceMultiple(String, char[], char[][])where the object where the output should be appended is passed in as a parameter.static intreplaceMultipleTo(String sInputString, char[] aSearchChars, char[][] aReplacementStrings, Writer aTarget)Specialized version ofreplaceMultiple(String, char[], char[][])where the object where the output should be appended is passed in as a parameter.static voidreplaceMultipleTo(String sInputString, char[] aSearchChars, char cReplacementChar, Writer aTarget)Optimized replace method that replaces a set of characters with another character.static voidreplaceMultipleTo(String sInputString, char[] aSearchChars, char cReplacementChar, StringBuilder aTarget)Optimized replace method that replaces a set of characters with another character.static booleanstartsWith(CharSequence aCS, char c)static booleanstartsWith(CharSequence aCS, CharSequence aSearch)static booleanstartsWith(String sStr, String sSearch)static booleanstartsWithAny(CharSequence aCS, char[] aChars)static booleanstartsWithIgnoreCase(CharSequence aCS, char c)static booleanstartsWithIgnoreCase(String sStr, String sSearch)static Stringtrim(String s)Trim the passed string, if it is notnull.static StringtrimEnd(String sSrc, char cTail)Trim the passed tail from the source value.static StringtrimEnd(String sSrc, int nCount)Trim the passed tail from the source value.static StringtrimEnd(String sSrc, String sTail)Trim the passed tail from the source value.static StringtrimEndRepeatedly(String sSrc, char cTail)static StringtrimEndRepeatedly(String sSrc, String sTail)static StringtrimLeadingWhitespaces(String s)Remove any leading whitespaces from the passed string.static StringtrimStart(String sSrc, char cLead)Trim the passed lead from the source value.static StringtrimStart(String sSrc, int nCount)Trim the passed lead from the source value.static StringtrimStart(String sSrc, String sLead)Trim the passed lead from the source value.static StringtrimStartAndEnd(String sSrc, char cValueToTrim)Trim the passed lead and tail from the source value.static StringtrimStartAndEnd(String sSrc, char cLead, char cTail)Trim the passed lead and tail from the source value.static StringtrimStartAndEnd(String sSrc, String sValueToTrim)Trim the passed lead and tail from the source value.static StringtrimStartAndEnd(String sSrc, String sLead, String sTail)Trim the passed lead and tail from the source value.static StringtrimStartRepeatedly(String sSrc, char cLead)static StringtrimStartRepeatedly(String sSrc, String sLead)static StringtrimTrailingWhitespaces(String s)Remove any trailing whitespaces from the passed string.
-
-
-
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 isnullor empty.- Parameters:
aCS- The character sequence to check. May benull.- Returns:
trueif the string isnullor empty,falseotherwise- Since:
- 10.1.8
-
isEmpty
public static boolean isEmpty(@Nullable String sStr)
Check if the string isnullor empty.- Parameters:
sStr- The string to check. May benull.- Returns:
trueif the string isnullor empty,falseotherwise- Since:
- 10.1.8
-
isEmptyAfterTrim
public static boolean isEmptyAfterTrim(@Nullable String s)
Check if the string isnullor empty after trimming.- Parameters:
s- The string to check. May benull.- Returns:
trueif the string isnullor empty or consists only of whitespaces,falseotherwise- 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 benull.- Returns:
trueif the string contains at least one,falseotherwise- 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 benull.- Returns:
trueif the string contains at least one char,falseotherwise- Since:
- 10.1.8
-
isNotEmptyAfterTrim
public static boolean isNotEmptyAfterTrim(@Nullable String s)
Check if the string neithernullnor empty after trimming.- Parameters:
s- The string to check. May benull.- Returns:
trueif the string is neithernullnor empty nor consists only of whitespaces,falseotherwise- Since:
- 10.1.8
-
hasNoText
public static boolean hasNoText(@Nullable CharSequence aCS)
Check if the string isnullor empty.- Parameters:
aCS- The character sequence to check. May benull.- Returns:
trueif the string isnullor empty,falseotherwise
-
hasNoText
public static boolean hasNoText(@Nullable String sStr)
Check if the string isnullor empty.- Parameters:
sStr- The string to check. May benull.- Returns:
trueif the string isnullor empty,falseotherwise
-
hasNoTextAfterTrim
public static boolean hasNoTextAfterTrim(@Nullable String s)
Check if the string isnullor empty after trimming.- Parameters:
s- The string to check. May benull.- Returns:
trueif the string isnullor empty or consists only of whitespaces,falseotherwise
-
hasText
public static boolean hasText(@Nullable CharSequence aCS)
Check if the string contains any char.- Parameters:
aCS- The character sequence to check. May benull.- Returns:
trueif the string contains at least one,falseotherwise
-
hasText
public static boolean hasText(@Nullable String sStr)
Check if the string contains any char.- Parameters:
sStr- The string to check. May benull.- Returns:
trueif the string contains at least one char,falseotherwise
-
hasTextAfterTrim
public static boolean hasTextAfterTrim(@Nullable String s)
Check if the string neithernullnor empty after trimming.- Parameters:
s- The string to check. May benull.- Returns:
trueif the string is neithernullnor empty nor consists only of whitespaces,falseotherwise
-
containsAny
public static boolean containsAny(@Nullable CharSequence aCS, @Nullable ICharPredicate aFilter)
Check if the passedCharSequencecontains any character matching the provided filter.- Parameters:
aCS- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is not empty.trueif the filter is notnulland at least one character of the string matches the filter.falseotherwise.- Since:
- 9.1.7
-
containsAny
public static boolean containsAny(@Nullable String sStr, @Nullable ICharPredicate aFilter)
Check if the passedStringcontains any character matching the provided filter.- Parameters:
sStr- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is not empty.trueif the filter is notnulland at least one character of the string matches the filter.falseotherwise.- Since:
- 9.1.7
-
containsNone
public static boolean containsNone(@Nullable CharSequence aCS, @Nullable ICharPredicate aFilter)
Check if the passedCharSequencecontains no character matching the provided filter.- Parameters:
aCS- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is empty.trueif the filter is notnulland no character of the string matches the filter.falseotherwise.- Since:
- 9.1.7
-
containsNone
public static boolean containsNone(@Nullable String sStr, @Nullable ICharPredicate aFilter)
Check if the passedStringcontains no character matching the provided filter.- Parameters:
sStr- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is empty.trueif the filter is notnulland no character of the string matches the filter.falseotherwise.- Since:
- 9.1.7
-
containsOnly
public static boolean containsOnly(@Nullable CharSequence aCS, @Nullable ICharPredicate aFilter)
Check if the passedCharSequencecontains only characters matching the provided filter.- Parameters:
aCS- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is not empty.trueif the filter is notnulland the string has at least one character and all characters of the string match the filter.falseotherwise.- Since:
- 9.1.7
-
containsOnly
public static boolean containsOnly(@Nullable String sStr, @Nullable ICharPredicate aFilter)
Check if the passedStringcontains only characters matching the provided filter.- Parameters:
sStr- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is not empty.trueif the filter is notnulland the string has at least one character and all characters of the string match the filter.falseotherwise.- 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 benull.- Returns:
trueif the passed sequence is empty or if only whitespace characters are contained.- See Also:
Character.isWhitespace(char)
-
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 benull.nMinLen- Minimum length. Should be > 0.cFront- The character to be used at the beginning- Returns:
- A non-
nullstring 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 benull.nMinLen- Minimum length. Should be > 0.cFront- The character to be used at the beginning- Returns:
- A non-
nullstring 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 benull.nMinLen- Minimum length. Should be > 0.cFront- The character to be used at the beginning- Returns:
- A non-
nullstring 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 benull.nMinLen- Minimum length. Should be > 0.cEnd- The character to be used at the end- Returns:
- A non-
nullstring 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 benull.aCharset- The charset to use. May not benull.- 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 benull.- 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 benull.nOfs- Byte array offsetnLen- 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 partcLow- Low hex part- Returns:
- A value between 0 and 255, or -1 if any input character is not a hex char!
-
getHexDecoded
@Nonnull @ReturnsMutableCopy public static byte[] getHexDecoded(@Nonnull String sInput)
-
getHexDecoded
@Nonnull @ReturnsMutableCopy public static byte[] getHexDecoded(@Nonnull char[] aInput)
-
getHexDecoded
@Nonnull @ReturnsMutableCopy public static byte[] getHexDecoded(@Nonnull char[] aInput, @Nonnegative int nOfs, @Nonnegative int nLen)
-
getHexStringLeadingZero
@Nonnull public static String getHexStringLeadingZero(byte nValue, int nDigits)
-
getHexStringLeadingZero
@Nonnull public static String getHexStringLeadingZero(int nValue, int nDigits)
-
getHexStringLeadingZero
@Nonnull public static String getHexStringLeadingZero(long nValue, int nDigits)
-
getHexStringLeadingZero
@Nonnull public static String getHexStringLeadingZero(short nValue, int nDigits)
-
getLeadingWhitespaceCount
@Nonnegative public static int getLeadingWhitespaceCount(@Nullable String s)
Get the number of leading white spaces according toCharacter.isWhitespace(char)- Parameters:
s- The string to be parsed. May benull.- Returns:
- Always ≥ 0.
-
getTrailingWhitespaceCount
@Nonnegative public static int getTrailingWhitespaceCount(@Nullable String s)
Get the number of trailing white spaces according toCharacter.isWhitespace(char)- Parameters:
s- The string to be parsed. May benull.- Returns:
- Always ≥ 0.
-
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 benull.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 benull.c- The char to be searched.- Returns:
- Always ≥ 0.
-
imploder
@Nonnull public static StringHelper.ImploderBuilder imploder()
- Returns:
- A new
StringHelper.ImploderBuilder. - Since:
- 10.0.0
-
getImploded
@Nonnull public static String getImploded(@Nullable Iterable<?> aElements)
Get a concatenated String from all elements of the passed container, without a separator. Evennullelements are added.- Parameters:
aElements- The container to convert. May benullor 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. Evennullelements are added.- Type Parameters:
ELEMENTTYPE- Iterable element type- Parameters:
aElements- The container to convert. May benullor empty.aMapper- The mapping function to convert from ELEMENTTYPE to String. May not benull.- 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. Evennullelements are added.- Parameters:
sSep- The separator to use. May not benull.aElements- The container to convert. May benullor 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. Evennullelements are added.- Parameters:
cSep- The separator to use.aElements- The container to convert. May benullor 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. Evennullelements are added.- Type Parameters:
ELEMENTTYPE- The element type of the collection to be imploded- Parameters:
sSep- The separator to use. May not benull.aElements- The container to convert. May benullor empty.aMapper- The mapping function to convert from ELEMENTTYPE to String. May not benull.- 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. Evennullelements 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 benullor empty.aMapper- The mapping function to convert from ELEMENTTYPE to String. May not benull.- 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 benullor 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 benullor 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 benullor empty.aMapper- The mapping function to convert from ELEMENTTYPE to String. May not benull.- 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 benullor 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 benull.- 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 benull.aElements- The container to convert. May benullor 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 benullor 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 benull.aElements- The container to convert. May benullor 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 benull.aElements- The container to convert. May benullor empty.aMapper- The mapping function to convert from ELEMENTTYPE to String. May not benull.- 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 benullor empty.aMapper- The mapping function to convert from ELEMENTTYPE to String. May not benull.- 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 benullor 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 benull.- 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 benull.aElements- The container to convert. May benullor 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 benull.- 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 benullor 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-nulland non empty elements of the passed container without a separator string. This the very generic version ofgetConcatenatedOnDemand(String, String)for an arbitrary number of elements.- Parameters:
aElements- The container to convert. May benullor 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-nulland non empty elements of the passed container without a separator string. This the very generic version ofgetConcatenatedOnDemand(String, String)for an arbitrary number of elements.- Type Parameters:
ELEMENTTYPE- Iterable element type- Parameters:
aElements- The container to convert. May benullor empty.aMapper- The mapping function to convert from ELEMENTTYPE to String. May not benull.- 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-nulland non empty elements of the passed container without a separator string. This the very generic version ofgetConcatenatedOnDemand(String, String)for an arbitrary number of elements.- Type Parameters:
ELEMENTTYPE- Array component type- Parameters:
aElements- The array to convert. May benullor empty.aMapper- The mapping function to convert from ELEMENTTYPE to String. May not benull.- 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-nulland non empty elements of the passed container, separated by the specified separator string. This the very generic version ofgetConcatenatedOnDemand(String, String, String)for an arbitrary number of elements.- Parameters:
sSep- The separator to use. May not benull.aElements- The container to convert. May benullor empty.- Returns:
- The concatenated string.
-
getImplodedNonEmpty
@Nonnull public static String getImplodedNonEmpty(char cSep, @Nullable Iterable<String> aElements)
Get a concatenated String from all non-nulland non empty elements of the passed container, separated by the specified separator char. This the very generic version ofgetConcatenatedOnDemand(String, String, String)for an arbitrary number of elements.- Parameters:
cSep- The separator to use.aElements- The container to convert. May benullor 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-nulland non empty elements of the passed container, separated by the specified separator string. This the very generic version ofgetConcatenatedOnDemand(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 benull.aElements- The container to convert. May benullor empty.aMapper- The mapping function to convert from ELEMENTTYPE to String. May not benull.- 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-nulland non empty elements of the passed container, separated by the specified separator char. This the very generic version ofgetConcatenatedOnDemand(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 benullor empty.aMapper- The mapping function to convert from ELEMENTTYPE to String. May not benull.- 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 ofgetConcatenatedOnDemand(String, String, String)for an arbitrary number of elements.- Parameters:
sSep- The separator to use. May not benull.aElements- The container to convert. May benullor 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 ofgetConcatenatedOnDemand(String, String, String)for an arbitrary number of elements.- Parameters:
cSep- The separator to use.aElements- The container to convert. May benullor 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 ofgetConcatenatedOnDemand(String, String, String)for an arbitrary number of elements.- Type Parameters:
ELEMENTTYPE- Array component type- Parameters:
sSep- The separator to use. May not benull.aElements- The container to convert. May benullor empty.aMapper- The mapping function to convert from ELEMENTTYPE to String. May not benull.- 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 ofgetConcatenatedOnDemand(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 benullor empty.aMapper- The mapping function to convert from ELEMENTTYPE to String. May not benull.- 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 ofgetConcatenatedOnDemand(String, String, String)for an arbitrary number of elements.- Parameters:
sSep- The separator to use. May not benull.aElements- The container to convert. May benullor 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 ofgetConcatenatedOnDemand(String, String, String)for an arbitrary number of elements.- Parameters:
cSep- The separator to use.aElements- The container to convert. May benullor 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 ofgetConcatenatedOnDemand(String, String, String)for an arbitrary number of elements.- Type Parameters:
ELEMENTTYPE- Array component type- Parameters:
sSep- The separator to use. May not benull.aElements- The container to convert. May benullor 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 benull.- 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 ofgetConcatenatedOnDemand(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 benullor 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 benull.- Returns:
- The concatenated string.
- Since:
- 8.5.6
-
imploderMap
@Nonnull public static StringHelper.ImploderBuilderMap imploderMap()
- Returns:
- A new
StringHelper.ImploderBuilderMap. - Since:
- 10.0.0
-
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 typeVALUETYPE- Map value type- Parameters:
sSepOuter- The separator to use for separating the map entries. May not benull.sSepInner- The separator to use for separating the key from the value. May not benull.aElements- The map to convert. May benullor 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 typeVALUETYPE- 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 benullor 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 typeVALUETYPE- Map value type- Parameters:
sSepOuter- The separator to use for separating the map entries. May not benull.sSepInner- The separator to use for separating the key from the value. May not benull.aElements- The map to convert. May benullor empty.aKeyMapper- The mapping function to convert from KEYTYPE to String. May not benull.aValueMapper- The mapping function to convert from VALUETYPE to String. May not benull.- 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 typeVALUETYPE- 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 benullor empty.aKeyMapper- The mapping function to convert from KEYTYPE to String. May not benull.aValueMapper- The mapping function to convert from VALUETYPE to String. May not benull.- 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 benullor 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 benullor 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 benullor 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-nulltarget 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 benullor empty.aConsumer- The non-nullconsumer 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 benullor 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-nullconsumer 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 aICommonsListof all elements in the passed string, using specified separator string.- Parameters:
cSep- The separator character to use.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The
ICommonsListrepresented by the passed string. Nevernull. If the passed input string isnullor "" 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 aICommonsListof all elements in the passed string, using specified separator string.- Parameters:
cSep- The separator character to use.sElements- The concatenated String to convert. May benullor 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
ICommonsListrepresented by the passed string. Nevernull. If the passed input string isnullor "" 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 benull.sElements- The concatenated String to convert. May benullor 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-nulltarget 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 benull.sElements- The concatenated String to convert. May benullor empty.aConsumer- The non-nullconsumer 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 benull.sElements- The concatenated String to convert. May benullor 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-nullconsumer 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 aICommonsListof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The
ICommonsListrepresented by the passed string. Nevernull. If the passed input string isnullor "" 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 aICommonsListof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor 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
ICommonsListrepresented by the passed string. Nevernull. If the passed input string isnullor "" 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 aSetof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The
Setrepresented by the passed string. Nevernull. If the passed input string isnullor "" 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 orderedCommonsLinkedHashSetof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The ordered
Setrepresented by the passed string. Nevernull. If the passed input string isnullor "" 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 sortedCommonsTreeSetof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The sorted
Setrepresented by the passed string. Nevernull. If the passed input string isnullor "" 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-
nullstring 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 benull.nRepeats- The number of repetitions to retrieve. May not be < 0.- Returns:
- A non-
nullstring 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 isnullor empty only the other element is returned. If both strings arenullor empty and empty String is returned.- Parameters:
sFront- Front string. May benull.sEnd- May benull.- 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 isnullor empty, the separator is not applied.- Parameters:
sFront- Front string. May benull.sSep- Separator string. May benull.sEnd- May benull.- 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 isnullor empty, the separator is not applied.- Parameters:
sFront- Front string. May benull.cSep- Separator character.sEnd- May benull.- Returns:
- The concatenated string.
-
getQuoted
@Nonnull public static String getQuoted(@Nullable String sSource)
Get the provided string quoted or unquoted if it isnull.- Parameters:
sSource- Source string. May benull.- Returns:
- The String
"null"if the source isnull,"'" + 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 isnull.- Parameters:
aTarget- The target to write to. May not benull.sSource- Source string. May benull.- 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 isnull.- Parameters:
aTarget- The target to write to. May not benull.sSource- Source string. May benull.- Throws:
IOException- in case of IO error- Since:
- 9.2.0
- See Also:
getQuoted(String)
-
startsWith
public static boolean startsWith(@Nullable CharSequence aCS, char c)
-
startsWithAny
public static boolean startsWithAny(@Nullable CharSequence aCS, @Nullable char[] aChars)
-
startsWithIgnoreCase
public static boolean startsWithIgnoreCase(@Nullable CharSequence aCS, char c)
-
startsWith
public static boolean startsWith(@Nullable CharSequence aCS, @Nullable CharSequence aSearch)
-
startsWithIgnoreCase
public static boolean startsWithIgnoreCase(@Nullable String sStr, @Nullable String sSearch)
-
endsWith
public static boolean endsWith(@Nullable CharSequence aCS, char c)
-
endsWithAny
public static boolean endsWithAny(@Nullable CharSequence aCS, @Nullable char[] aChars)
-
endsWith
public static boolean endsWith(@Nullable CharSequence aCS, @Nullable CharSequence aSearch)
-
endsWithIgnoreCase
public static boolean endsWithIgnoreCase(@Nullable CharSequence aCS, char c)
-
endsWithIgnoreCase
public static boolean endsWithIgnoreCase(@Nullable String sStr, @Nullable String sSearch)
-
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 benull.sSearch- The text to search for. May benull.- 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 benull.nFromIndex- The index to start searching in the source stringsSearch- The text to search for. May benull.- 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 benull.sSearch- The text to search for. May benull.- 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 benull.nFromIndex- The index to start searching in the source stringsSearch- The text to search for. May benull.- 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 benull.cSearch- The character to search for. May benull.- 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 benull.nFromIndex- The index to start searching in the source stringcSearch- The character to search for. May benull.- 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 benull.cSearch- The character to search for. May benull.- 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 benull.nFromIndex- The index to start searching in the source stringcSearch- The character to search for. May benull.- 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 benull.sSearch- The text to search for. May benull.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 benull.nFromIndex- The index to start searching in the source stringsSearch- The text to search for. May benull.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 benull.sSearch- The text to search for. May benull.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 benull.nFromIndex- The index to start searching in the source stringsSearch- The text to search for. May benull.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 benull.cSearch- The char to search for. May benull.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 benull.nFromIndex- The index to start searching in the source stringcSearch- The char to search for. May benull.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 benull.cSearch- The char to search for. May benull.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 benull.nFromIndex- The index to start searching in the source stringcSearch- The char to search for. May benull.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 benull.sSearch- The text to search for. May benull.- Returns:
trueif sSearch is contained in sText,falseotherwise.- 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 benull.cSearch- The character to search for. May benull.- Returns:
trueif cSearch is contained in sText,falseotherwise.- 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 benull.sSearch- The text to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
trueif sSearch is contained in sText,falseotherwise.- 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 benull.cSearch- The char to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
trueif sSearch is contained in sText,falseotherwise.- 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 benull.aSearchChars- The char array to search. May not benull.- Returns:
trueif at least any of the search char is contained in the input char array,falseotherwise.
-
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 benull.aSearchChars- The char array to search. May not benull.- Returns:
trueif at least any of the search char is contained in the input char array,falseotherwise.
-
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 benull.sSearch- The text to search for. May benull.- 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 benull.sSearch- The text to search for. May benull.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 benull.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 benull.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, @Nullable String sLead)
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 stringsLead- The string to be trimmed of the beginning- Returns:
- The trimmed string, or the original input string, if the lead was not found
- See Also:
trimEnd(String, String),trimStartAndEnd(String, String),trimStartAndEnd(String, String, String)
-
trimStartRepeatedly
@Nullable @CheckReturnValue public static String trimStartRepeatedly(@Nullable String sSrc, @Nullable String sLead)
-
trimStart
@Nullable @CheckReturnValue public static String trimStart(@Nullable String sSrc, char cLead)
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 stringcLead- The char to be trimmed of the beginning- Returns:
- The trimmed string, or the original input string, if the lead was not found
- See Also:
trimEnd(String, String),trimStartAndEnd(String, String),trimStartAndEnd(String, String, String)
-
trimStartRepeatedly
@Nullable @CheckReturnValue public static String trimStartRepeatedly(@Nullable String sSrc, char cLead)
-
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 stringnCount- 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, @Nullable String sTail)
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 stringsTail- The string to be trimmed of the end- Returns:
- The trimmed string, or the original input string, if the tail was not found
- See Also:
trimStart(String, String),trimStartAndEnd(String, String),trimStartAndEnd(String, String, String)
-
trimEndRepeatedly
@Nullable @CheckReturnValue public static String trimEndRepeatedly(@Nullable String sSrc, @Nullable String sTail)
-
trimEnd
@Nullable @CheckReturnValue public static String trimEnd(@Nullable String sSrc, char cTail)
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 stringcTail- The char to be trimmed of the end- Returns:
- The trimmed string, or the original input string, if the tail was not found
- See Also:
trimStart(String, String),trimStartAndEnd(String, String),trimStartAndEnd(String, String, String)
-
trimEndRepeatedly
@Nullable @CheckReturnValue public static String trimEndRepeatedly(@Nullable String sSrc, char cTail)
-
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 stringnCount- 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, @Nullable String sValueToTrim)
Trim the passed lead and tail from the source value. If the source value does not start with the passed trimmed value, nothing happens.- Parameters:
sSrc- The input source stringsValueToTrim- The string to be trimmed of the beginning and the end- Returns:
- The trimmed string, or the original input string, if the value to trim was not found
- See Also:
trimStart(String, String),trimEnd(String, String),trimStartAndEnd(String, String, String)
-
trimStartAndEnd
@Nullable @CheckReturnValue public static String trimStartAndEnd(@Nullable String sSrc, @Nullable String sLead, @Nullable String sTail)
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 stringsLead- The string to be trimmed of the beginningsTail- The string 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, String),trimEnd(String, String),trimStartAndEnd(String, String)
-
trimStartAndEnd
@Nullable @CheckReturnValue public static String trimStartAndEnd(@Nullable String sSrc, char cValueToTrim)
Trim the passed lead and tail from the source value. If the source value does not start with the passed trimmed value, nothing happens.- Parameters:
sSrc- The input source stringcValueToTrim- The char to be trimmed of the beginning and the end- Returns:
- The trimmed string, or the original input string, if the value to trim was not found
- See Also:
trimStart(String, String),trimEnd(String, String),trimStartAndEnd(String, String, 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 stringcLead- The char to be trimmed of the beginningcTail- 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)
-
trim
@Nullable @CheckReturnValue public static String trim(@Nullable String s)
Trim the passed string, if it is notnull.- Parameters:
s- The string to be trimmed. May benull.- Returns:
nullif the input string wasnull, the non-nulltrimmed string otherwise.- See Also:
String.trim()
-
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_CHARif 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_CHARif 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_CHARif 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_CHARif the passed array was empty
-
getCharCount
@Nonnegative public static int getCharCount(@Nullable String s, char cSearch)
-
getCharCount
@Nonnegative public static int getCharCount(@Nullable char[] aChars, char cSearch)
-
getLineCount
@Nonnegative public static int getLineCount(@Nullable String s)
-
getLineCount
@Nonnegative public static int getLineCount(@Nullable String s, char cLineSep)
-
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.
-
getCutAfterLength
@Nonnull public static String getCutAfterLength(@Nonnull String sValue, @Nonnegative int nMaxLength)
-
getCutAfterLength
@Nonnull public static String getCutAfterLength(@Nonnull String sValue, @Nonnegative int nMaxLength, @Nullable String sNewSuffix)
-
replaceAllSafe
public static String replaceAllSafe(@Nullable String sInputString, @Nonnull String sSearchText, @Nullable CharSequence aReplacementText)
Same asreplaceAll(String, String, CharSequence)but allowing for anullnew-value, which is than interpreted as an empty string instead.- Parameters:
sInputString- The input string where the text should be replace. If this parameter isnullor empty, no replacement is done.sSearchText- The string to be replaced. May neither benullnor empty.aReplacementText- The string with the replacement. May benullor 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 forString.replace(CharSequence, CharSequence). The problem with the mentionedStringmethod is, that is uses internally regular expressions which use a synchronized block to compile the patterns. This method is inherently thread safe sinceStringis immutable and we're operating on different temporaryStringBuilderobjects.- Parameters:
sInputString- The input string where the text should be replace. If this parameter isnullor empty, no replacement is done.sSearchText- The string to be replaced. May neither benullnor empty.aReplacementText- The string with the replacement. May not benullbut 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 forString.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 sinceStringis immutable and we're operating on different temporaryStringBuilderobjects.- Parameters:
sInputString- The input string where the text should be replace. If this parameter isnullor 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 callsreplaceAllas long as there are still replacements found- Parameters:
sInputString- The input string where the text should be replace. If this parameter isnullor empty, no replacement is done.sSearchText- The string to be replaced. May neither benullnor empty.sReplacementText- The string with the replacement. May not benullbut 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 benull.aSearchChars- The one-character search patterns. May not benull.aReplacementStrings- The replacements to be performed. May not benull. The first dimension of this array must have exactly the same amount of elements as the patterns parameter array.- Returns:
CGlobal.ILLEGAL_UINTif 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 ofreplaceMultiple(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 benull.- 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 ofreplaceMultiple(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 benull.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 benull.- 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 ofreplaceMultiple(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 benull.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 benull.- 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 benull.
-
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 benull.- 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 usingreplaceAll(String,String,CharSequence)which is ok.- Parameters:
sInputString- The input string where the text should be replaced. May benull.aTransTable- The map with the replacements to execute. Ifnullis passed, the input string is not altered.- Returns:
nullif the input string wasnull.
-
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 usingreplaceAll(String,String,CharSequence)which is ok.- Parameters:
sInputString- The input string where the text should be replaced. May benull.aSearchTexts- The texts to be searched. Ifnullis 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! Ifnullis passed, the input string is not altered.- Returns:
nullif the input string wasnull. 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 isnullor 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 isnullor empty, no removing is done.sRemoveString- The String to be removed. May benullor 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 benull.- 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 returnnull. If the passed parameter isnullan empty string is returned.- Parameters:
s- The parameter to be notnull.- 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 returnnull. If the passed parameter isnullthe second parameter is returned.- Parameters:
s- The parameter to be notnull.sDefaultIfNull- The value to be used if the first parameter isnull. May benullbut 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 returnnull. If the passed parameter isnullthe second parameter is returned.- Parameters:
s- The parameter to be notnull.aDefaultIfNull- The value supplier to be used if the first parameter isnull. May not benull.- 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 passedCharSequencebut never returnnull. If the passed parameter isnullan empty string is returned.- Parameters:
s- The parameter to be notnull.- Returns:
- An empty string if the passed parameter is
null, the passedCharSequenceotherwise.
-
getNotNull
@Nullable public static CharSequence getNotNull(@Nullable CharSequence s, @Nullable CharSequence sDefaultIfNull)
Get the passedCharSequencebut never returnnull. If the passed parameter isnullthe second parameter is returned.- Parameters:
s- The parameter to be notnull.sDefaultIfNull- The value to be used if the first parameter isnull. May benullbut in this case the call to this method is obsolete.- Returns:
- The passed default value if the string is
null, otherwise the inputCharSequence.
-
getNotNull
@Nullable public static CharSequence getNotNull(@Nullable CharSequence s, @Nonnull Supplier<? extends CharSequence> aDefaultIfNull)
Get the passedCharSequencebut never returnnull. If the passed parameter isnullthe second parameter is returned.- Parameters:
s- The parameter to be notnull.aDefaultIfNull- The value supplier to be used if the first parameter isnull. May not benull.- Returns:
- The passed default value if the string is
null, otherwise the inputCharSequence. - 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 isnullor empty the second parameter is returned.- Parameters:
s- The parameter to be notnullnor empty.sDefaultIfEmpty- The value to be used if the first parameter isnullor empty. May benullbut in this case the call to this method is obsolete.- Returns:
- The passed default value if the string is
nullor 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 isnullor empty the second parameter is returned.- Parameters:
s- The parameter to be notnullnor empty.aDefaultIfEmpty- The value supplier to be used if the first parameter isnullor empty. May not benull.- Returns:
- The passed default value if the string is
nullor 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 isnullor empty the second parameter is returned.- Parameters:
s- The parameter to be notnullnor empty.sDefaultIfEmpty- The value to be used if the first parameter isnullor empty. May benullbut in this case the call to this method is obsolete.- Returns:
- The passed default value if the char sequence is
nullor 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 isnullor empty the second parameter is returned.- Parameters:
s- The parameter to be notnullnor empty.aDefaultIfEmpty- The value supplier to be used if the first parameter isnullor empty. May not benull.- Returns:
- The passed default value if the char sequence is
nullor 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 theObject.toString()method.- Parameters:
aObject- The value to be converted. May benull.- Returns:
- An empty string in case the passed object was
null. Nevernull. - See Also:
Object.toString()
-
getToString
@Nullable public static String getToString(@Nullable Object aObject, @Nullable String sNullValue)
Convert the passed object to a string using theObject.toString()method or otherwise return the passed default value.- Parameters:
aObject- The value to be converted. May benull.sNullValue- The value to be returned in case the passed object isnull. May benullitself.- Returns:
- The passed default value in case the passed object was
nullor the result ofObject.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 benull.- Returns:
- An empty, non-
nullstring 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 benull.nCount- The number of chars to remove.- Returns:
- An empty, non-
nullstring 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 benull.- Returns:
- An empty, non-
nullstring 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 benull.nCount- The number of chars to remove.- Returns:
- An empty, non-
nullstring 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 benull- Returns:
- A non-
nullstring 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 benull.cSearch- The character to search.- Returns:
nullif 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 benull.cSearch- The character to search.- Returns:
nullif 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 benull.sSearch- The string to search. May benull.- Returns:
nullif 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 benull.sSearch- The string to search. May benull.- Returns:
nullif 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 benull.cSearch- The character to search.- Returns:
nullif 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 benull.cSearch- The character to search.- Returns:
nullif 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 benull.sSearch- The string to search. May benull.- Returns:
nullif 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 benull.sSearch- The string to search. May benull.- Returns:
nullif 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 benull.cSearch- The character to search.- Returns:
nullif 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 benull.cSearch- The character to search.- Returns:
nullif 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 benull.sSearch- The string to search. May benull.- Returns:
nullif 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 benull.sSearch- The string to search. May benull.- Returns:
nullif 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 benull.cSearch- The character to search.- Returns:
nullif 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 benull.cSearch- The character to search.- Returns:
nullif 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 benull.sSearch- The string to search. May benull.- Returns:
nullif 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 benull.sSearch- The string to search. May benull.- Returns:
nullif 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 benull.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 benull.sSearch- The search string. May benull.- 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 benull.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 benull.sSearch- The search string. May benull.- 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 benull.- 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 benullor empty.aConsumer- The consumer to be used. May not benull.
-
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 thanCharSequence.codePoints().forEachOrdered(c)- Parameters:
sInputString- Input String to use. May benullor empty.aConsumer- The consumer to be used. May not benull.
-
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 asnew String (aCharArray).getBytes (aCharset)just without the intermediate objects.- Parameters:
aCharset- Charset to be used. May not benull.aCharArray- The char array to be encoded. May not benull.- 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 asnew String (aCharArray).getBytes (aCharset)just without the intermediate objects.- Parameters:
aCharset- Charset to be used. May not benull.aCharArray- The char array to be encoded. May not benull.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 asnew String (aByteArray, aCharset)just without the intermediate objects.- Parameters:
aByteArray- The byte array to be decoded. May not benull.aCharset- Charset to be used. May not benull.- 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 asnew String (aByteArray, aCharset)just without the intermediate objects.- Parameters:
aByteArray- The byte array to be decoded. May not benull.nOfs- Offset into byte array. Must be ≥ 0.nLen- Bytes to encode. Must be ≥ 0.aCharset- Charset to be used. May not benull.- Returns:
- The created char array. Never
null. - Since:
- 8.6.4
-
-