@Immutable public final class StringHelper extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
STRING_NOT_FOUND
The constant to be returned if an String.indexOf call did not find a match!
|
| Modifier and Type | Method and Description |
|---|---|
static void |
appendQuoted(Appendable aTarget,
String sSource)
Append the provided string quoted or unquoted if it is
null. |
static void |
appendQuoted(StringBuilder aTarget,
String sSource)
Append the provided string quoted or unquoted if it is
null. |
static boolean |
contains(String sText,
char cSearch)
Check if cSearch is contained within sText.
|
static boolean |
contains(String sText,
String sSearch)
Check if sSearch is contained within sText.
|
static boolean |
containsAny(char[] aInput,
char[] aSearchChars)
Check if any of the passed searched characters is contained in the input
char array.
|
static boolean |
containsAny(CharSequence aCS,
ICharPredicate aFilter)
Check if the passed
CharSequence contains any character matching
the provided filter. |
static boolean |
containsAny(String sInput,
char[] aSearchChars)
Check if any of the passed searched characters in contained in the input
string.
|
static boolean |
containsAny(String sStr,
ICharPredicate aFilter)
Check if the passed
String contains any character matching the
provided filter. |
static boolean |
containsIgnoreCase(String sText,
char cSearch,
Locale aSortLocale)
Check if cSearch is contained within sText ignoring case.
|
static boolean |
containsIgnoreCase(String sText,
String sSearch,
Locale aSortLocale)
Check if sSearch is contained within sText ignoring case.
|
static boolean |
containsNone(CharSequence aCS,
ICharPredicate aFilter)
Check if the passed
CharSequence contains no character matching the
provided filter. |
static boolean |
containsNone(String sStr,
ICharPredicate aFilter)
Check if the passed
String contains no character matching the
provided filter. |
static boolean |
containsOnly(CharSequence aCS,
ICharPredicate aFilter)
Check if the passed
CharSequence contains only characters matching
the provided filter. |
static boolean |
containsOnly(String sStr,
ICharPredicate aFilter)
Check if the passed
String contains only characters matching the
provided filter. |
static char[] |
decodeBytesToChars(byte[] aByteArray,
Charset aCharset)
Decode a byte array to a char array using the provided charset.
|
static char[] |
decodeBytesToChars(byte[] aByteArray,
int nOfs,
int nLen,
Charset aCharset)
Decode a byte array to a char 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 byte[] |
encodeCharToBytes(char[] aCharArray,
int nOfs,
int nLen,
Charset aCharset)
Encode a char array to a byte array using the provided charset.
|
static boolean |
endsWith(CharSequence aCS,
char c) |
static boolean |
endsWith(CharSequence aCS,
CharSequence aSearch) |
static boolean |
endsWith(String sStr,
String sSearch) |
static boolean |
endsWithAny(CharSequence aCS,
char[] aChars) |
static boolean |
endsWithIgnoreCase(CharSequence aCS,
char c) |
static boolean |
endsWithIgnoreCase(String sStr,
String sSearch) |
static void |
explode(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 void |
explode(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 void |
explode(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 void |
explode(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 int |
getCharacterCount(int nValue)
Get the number of characters the passed value would occupy in a string
representation.
|
static int |
getCharacterCount(long nValue)
Get the number of characters the passed value would occupy in a string
representation.
|
static int |
getCharCount(char[] aChars,
char cSearch) |
static int |
getCharCount(String s,
char cSearch) |
static String |
getConcatenatedOnDemand(String sFront,
char cSep,
String sEnd)
Concatenate the strings sFront and sEnd by the "cSep" separator.
|
static String |
getConcatenatedOnDemand(String sFront,
String sEnd)
Concatenate the strings sFront and sEnd.
|
static String |
getConcatenatedOnDemand(String sFront,
String sSep,
String sEnd)
Concatenate the strings sFront and sEnd by the "sSep" string.
|
static String |
getCutAfterLength(String sValue,
int nMaxLength) |
static String |
getCutAfterLength(String sValue,
int nMaxLength,
String sNewSuffix) |
static ICommonsList<String> |
getExploded(char cSep,
String sElements)
Take a concatenated String and return a
ICommonsList of 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 a
ICommonsList of all
elements in the passed string, using specified separator string. |
static <COLLTYPE extends Collection<String>> |
getExploded(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 a
ICommonsList of 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 a
ICommonsList of all
elements in the passed string, using specified separator string. |
static <COLLTYPE extends Collection<String>> |
getExploded(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 ordered
CommonsLinkedHashSet of all elements in the passed string, using
specified separator string. |
static CommonsHashSet<String> |
getExplodedToSet(String sSep,
String sElements)
Take a concatenated String and return a
Set of 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 sorted
CommonsTreeSet of
all elements in the passed string, using specified separator string. |
static char |
getFirstChar(char[] aChars)
Get the first character of the passed array
|
static char |
getFirstChar(CharSequence aCS)
Get the first character of the passed character sequence
|
static String |
getFirstToken(String sStr,
char cSearch)
Get the first token up to (and excluding) the separating character.
|
static String |
getFirstToken(String sStr,
String sSearch)
Get the first token up to (and excluding) the separating string.
|
static String |
getFromFirstExcl(String sStr,
char cSearch)
Get everything from the string from and excluding the first passed char.
|
static String |
getFromFirstExcl(String sStr,
String sSearch)
Get everything from the string from and excluding the passed string.
|
static String |
getFromFirstIncl(String sStr,
char cSearch)
Get everything from the string from and including the first passed char.
|
static String |
getFromFirstIncl(String sStr,
String sSearch)
Get everything from the string from and including the passed string.
|
static String |
getFromLastExcl(String sStr,
char cSearch)
Get everything from the string from and excluding the first passed char.
|
static String |
getFromLastExcl(String sStr,
String sSearch)
Get everything from the string from and excluding the passed string.
|
static String |
getFromLastIncl(String sStr,
char cSearch)
Get everything from the string from and including the first passed char.
|
static String |
getFromLastIncl(String sStr,
String sSearch)
Get everything from the string from and including the passed string.
|
static int |
getHexByte(char cHigh,
char cLow) |
static char |
getHexChar(int n)
Get the matching hex digit as a lower case character.
|
static char |
getHexCharUpperCase(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 String |
getHexEncoded(byte[] aInput)
Convert a byte array to a hexadecimal encoded string.
|
static String |
getHexEncoded(byte[] aInput,
int nOfs,
int nLen)
Convert a byte array to a hexadecimal encoded string.
|
static String |
getHexEncoded(String sInput,
Charset aCharset)
Convert a string to a byte array and than to a hexadecimal encoded string.
|
static String |
getHexString(byte nValue) |
static String |
getHexString(int nValue) |
static String |
getHexString(long nValue) |
static String |
getHexString(short nValue) |
static String |
getHexStringLeadingZero(byte nValue,
int nDigits) |
static String |
getHexStringLeadingZero(int nValue,
int nDigits) |
static String |
getHexStringLeadingZero(long nValue,
int nDigits) |
static String |
getHexStringLeadingZero(short nValue,
int nDigits) |
static String |
getHexStringLeadingZero2(byte nValue) |
static int |
getHexValue(char c)
Get the decimal value of the passed hex character
|
static <KEYTYPE,VALUETYPE> |
getImploded(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> |
getImploded(char cSep,
ELEMENTTYPE... aElements)
Get a concatenated String from all elements of the passed array, separated
by the specified separator char.
|
static <ELEMENTTYPE> |
getImploded(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 String |
getImploded(char cSep,
Iterable<?> aElements)
Get a concatenated String from all elements of the passed container,
separated by the specified separator char.
|
static <ELEMENTTYPE> |
getImploded(ELEMENTTYPE... aElements)
Get a concatenated String from all elements of the passed array, without a
separator.
|
static <ELEMENTTYPE> |
getImploded(ELEMENTTYPE[] aElements,
int nOfs,
int nLen)
Get a concatenated String from all elements of the passed array, without a
separator.
|
static String |
getImploded(Iterable<?> aElements)
Get a concatenated String from all elements of the passed container,
without a separator.
|
static <ELEMENTTYPE> |
getImploded(String sSep,
ELEMENTTYPE... aElements)
Get a concatenated String from all elements of the passed array, separated
by the specified separator string.
|
static <ELEMENTTYPE> |
getImploded(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 String |
getImploded(String sSep,
Iterable<?> aElements)
Get a concatenated String from all elements of the passed container,
separated by the specified separator string.
|
static <KEYTYPE,VALUETYPE> |
getImploded(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> |
getImplodedMapped(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> |
getImplodedMapped(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> |
getImplodedMapped(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> |
getImplodedMapped(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> |
getImplodedMapped(ELEMENTTYPE[] aElements,
Function<? super ELEMENTTYPE,String> aMapper)
Get a concatenated String from all elements of the passed array, without a
separator.
|
static <ELEMENTTYPE> |
getImplodedMapped(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> |
getImplodedMapped(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> |
getImplodedMapped(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> |
getImplodedMapped(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> |
getImplodedMapped(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> |
getImplodedMapped(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> |
getImplodedMappedNonEmpty(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> |
getImplodedMappedNonEmpty(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> |
getImplodedMappedNonEmpty(char cSep,
Iterable<? extends ELEMENTTYPE> aElements,
Function<? super ELEMENTTYPE,String> aMapper)
Get a concatenated String from all non-
null and non empty
elements of the passed container, separated by the specified separator
char. |
static <ELEMENTTYPE> |
getImplodedMappedNonEmpty(ELEMENTTYPE[] aElements,
Function<? super ELEMENTTYPE,String> aMapper)
Get a concatenated String from all non-
null and non empty
elements of the passed container without a separator string. |
static <ELEMENTTYPE> |
getImplodedMappedNonEmpty(Iterable<? extends ELEMENTTYPE> aElements,
Function<? super ELEMENTTYPE,String> aMapper)
Get a concatenated String from all non-
null and non empty
elements of the passed container without a separator string. |
static <ELEMENTTYPE> |
getImplodedMappedNonEmpty(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> |
getImplodedMappedNonEmpty(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> |
getImplodedMappedNonEmpty(String sSep,
Iterable<? extends ELEMENTTYPE> aElements,
Function<? super ELEMENTTYPE,String> aMapper)
Get a concatenated String from all non-
null and non empty
elements of the passed container, separated by the specified separator
string. |
static String |
getImplodedNonEmpty(char cSep,
Iterable<String> aElements)
Get a concatenated String from all non-
null and non empty
elements of the passed container, separated by the specified separator
char. |
static String |
getImplodedNonEmpty(char cSep,
String... aElements)
Get a concatenated String from all elements of the passed array, separated
by the specified separator char.
|
static String |
getImplodedNonEmpty(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 String |
getImplodedNonEmpty(Iterable<String> aElements)
Get a concatenated String from all non-
null and non empty
elements of the passed container without a separator string. |
static String |
getImplodedNonEmpty(String sSep,
Iterable<String> aElements)
Get a concatenated String from all non-
null and non empty
elements of the passed container, separated by the specified separator
string. |
static String |
getImplodedNonEmpty(String sSep,
String... aElements)
Get a concatenated String from all elements of the passed array, separated
by the specified separator string.
|
static String |
getImplodedNonEmpty(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 int |
getIndexOf(String sText,
char cSearch)
Get the first index of cSearch within sText.
|
static int |
getIndexOf(String sText,
int nFromIndex,
char cSearch)
Get the first index of cSearch within sText starting at index nFromIndex.
|
static int |
getIndexOf(String sText,
int nFromIndex,
String sSearch)
Get the first index of sSearch within sText starting at index nFromIndex.
|
static int |
getIndexOf(String sText,
String sSearch)
Get the first index of sSearch within sText.
|
static int |
getIndexOfIgnoreCase(String sText,
char cSearch,
Locale aSortLocale)
Get the first index of cSearch within sText ignoring case.
|
static int |
getIndexOfIgnoreCase(String sText,
int nFromIndex,
char cSearch,
Locale aSortLocale)
Get the first index of cSearch within sText ignoring case starting at index
nFromIndex.
|
static int |
getIndexOfIgnoreCase(String sText,
int nFromIndex,
String sSearch,
Locale aSortLocale)
Get the first index of sSearch within sText ignoring case starting at index
nFromIndex.
|
static int |
getIndexOfIgnoreCase(String sText,
String sSearch,
Locale aSortLocale)
Get the first index of sSearch within sText ignoring case.
|
static char |
getLastChar(char[] aChars)
Get the last character of the passed array
|
static char |
getLastChar(CharSequence aCS)
Get the last character of the passed character sequence
|
static int |
getLastIndexOf(String sText,
char cSearch)
Get the last index of cSearch within sText.
|
static int |
getLastIndexOf(String sText,
int nFromIndex,
char cSearch)
Get the last index of cSearch within sText starting at index nFromIndex.
|
static int |
getLastIndexOf(String sText,
int nFromIndex,
String sSearch)
Get the last index of sSearch within sText starting at index nFromIndex.
|
static int |
getLastIndexOf(String sText,
String sSearch)
Get the last index of sSearch within sText.
|
static int |
getLastIndexOfIgnoreCase(String sText,
char cSearch,
Locale aSortLocale)
Get the last index of cSearch within sText ignoring case.
|
static int |
getLastIndexOfIgnoreCase(String sText,
int nFromIndex,
char cSearch,
Locale aSortLocale)
Get the last index of cSearch within sText ignoring case starting at index
nFromIndex.
|
static int |
getLastIndexOfIgnoreCase(String sText,
int nFromIndex,
String sSearch,
Locale aSortLocale)
Get the last index of sSearch within sText ignoring case starting at index
nFromIndex.
|
static int |
getLastIndexOfIgnoreCase(String sText,
String sSearch,
Locale aSortLocale)
Get the last index of sSearch within sText ignoring case.
|
static String |
getLastToken(String sStr,
char cSearch)
Get the last token from (and excluding) the separating character.
|
static String |
getLastToken(String sStr,
String sSearch)
Get the last token from (and excluding) the separating string.
|
static int |
getLeadingCharCount(String s,
char c)
Get the number of specified chars, the passed string starts with.
|
static int |
getLeadingWhitespaceCount(String s)
Get the number of leading white spaces according to
Character.isWhitespace(char) |
static String |
getLeadingZero(Byte aValue,
int nChars) |
static String |
getLeadingZero(Integer aValue,
int nChars) |
static String |
getLeadingZero(int nValue,
int nChars) |
static String |
getLeadingZero(long nValue,
int nChars) |
static String |
getLeadingZero(Long aValue,
int nChars) |
static String |
getLeadingZero(Short aValue,
int nChars) |
static String |
getLeadingZero(String sValue,
int nChars) |
static int |
getLength(CharSequence aCS)
Get the length of the passed character sequence.
|
static int |
getLineCount(String s) |
static int |
getLineCount(String s,
char cLineSep) |
static CharSequence |
getNotEmpty(CharSequence s,
CharSequence sDefaultIfEmpty)
Get the passed string but never return an empty char sequence.
|
static String |
getNotEmpty(String s,
String sDefaultIfEmpty)
Get the passed string but never return an empty string.
|
static CharSequence |
getNotNull(CharSequence s)
Get the passed
CharSequence but never return null. |
static CharSequence |
getNotNull(CharSequence s,
CharSequence sDefaultIfNull)
Get the passed
CharSequence but never return null. |
static String |
getNotNull(String s)
Get the passed string but never return
null. |
static String |
getNotNull(String s,
String sDefaultIfNull)
Get the passed string but never return
null. |
static int |
getOccurrenceCount(String sText,
char cSearch)
Count the number of occurrences of cSearch within sText.
|
static int |
getOccurrenceCount(String sText,
String sSearch)
Count the number of occurrences of sSearch within sText.
|
static int |
getOccurrenceCountIgnoreCase(String sText,
char cSearch,
Locale aSortLocale)
Count the number of occurrences of cSearch within sText ignoring case.
|
static int |
getOccurrenceCountIgnoreCase(String sText,
String sSearch,
Locale aSortLocale)
Count the number of occurrences of sSearch within sText ignoring case.
|
static String |
getQuoted(String sSource)
Get the provided string quoted or unquoted if it is
null. |
static String |
getRepeated(char cElement,
int nRepeats)
Get the passed string element repeated for a certain number of times.
|
static String |
getRepeated(String sElement,
int nRepeats)
Get the passed string element repeated for a certain number of times.
|
static int |
getReplaceMultipleResultLength(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 String |
getReverse(String sStr) |
static String |
getToString(Object aObject)
Convert the passed object to a string using the
Object.toString()
method. |
static String |
getToString(Object aObject,
String sNullValue)
Convert the passed object to a string using the
Object.toString()
method or otherwise return the passed default value. |
static int |
getTrailingCharCount(String s,
char c)
Get the number of specified chars, the passed string ends with.
|
static int |
getTrailingWhitespaceCount(String s)
Get the number of trailing white spaces according to
Character.isWhitespace(char) |
static String |
getUntilFirstExcl(String sStr,
char cSearch)
Get everything from the string up to and excluding first the passed char.
|
static String |
getUntilFirstExcl(String sStr,
String sSearch)
Get everything from the string up to and excluding the first passed string.
|
static String |
getUntilFirstIncl(String sStr,
char cSearch)
Get everything from the string up to and including the first passed char.
|
static String |
getUntilFirstIncl(String sStr,
String sSearch)
Get everything from the string up to and including the first passed string.
|
static String |
getUntilLastExcl(String sStr,
char cSearch)
Get everything from the string up to and excluding first the passed char.
|
static String |
getUntilLastExcl(String sStr,
String sSearch)
Get everything from the string up to and excluding the first passed string.
|
static String |
getUntilLastIncl(String sStr,
char cSearch)
Get everything from the string up to and including the first passed char.
|
static String |
getUntilLastIncl(String sStr,
String sSearch)
Get everything from the string up to and including the first passed string.
|
static String |
getWithLeading(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 String |
getWithLeading(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 String |
getWithLeading(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 String |
getWithoutAnySpaces(String sStr)
Get the passed string where all spaces (white spaces or unicode spaces)
have been removed.
|
static String |
getWithoutLeadingChar(String sStr)
Get the passed string without the first char.
|
static String |
getWithoutLeadingChars(String sStr,
int nCount)
Get the passed string without the specified number of leading chars.
|
static String |
getWithoutTrailingChar(String sStr)
Get the passed string without the last char.
|
static String |
getWithoutTrailingChars(String sStr,
int nCount)
Get the passed string without the specified number of trailing chars.
|
static String |
getWithTrailing(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 boolean |
hasNoText(CharSequence aCS)
Check if the string is
null or empty. |
static boolean |
hasNoText(String sStr)
Check if the string is
null or empty. |
static boolean |
hasNoTextAfterTrim(String s)
Check if the string is
null or empty after trimming. |
static boolean |
hasText(CharSequence aCS)
Check if the string contains any char.
|
static boolean |
hasText(String sStr)
Check if the string contains any char.
|
static boolean |
hasTextAfterTrim(String s)
Check if the string neither
null nor empty after trimming. |
static boolean |
isAllWhitespace(CharSequence s)
Check if the passed character sequence is only whitespace or not.
|
static void |
iterateChars(String sInputString,
ICharConsumer aConsumer)
Iterate all characters and pass them to the provided consumer.
|
static void |
iterateCodePoints(String sInputString,
IntConsumer aConsumer)
Iterate all code points and pass them to the provided consumer.
|
static String |
removeAll(String sInputString,
char cRemoveChar)
Remove all occurrences of the passed character from the specified input
string
|
static String |
removeAll(String sInputString,
String sRemoveString)
Remove all occurrences of the passed character from the specified input
string
|
static String |
removeMultiple(String sInputString,
char[] aRemoveChars)
Optimized remove method that removes a set of characters from an input
string!
|
static String |
replaceAll(String sInputString,
char cSearchChar,
char cReplacementChar)
This is a fast replacement for
String.replace(char, char) for
characters. |
static String |
replaceAll(String sInputString,
String sSearchText,
CharSequence aReplacementText)
This is a fast replacement for
String.replace(CharSequence, CharSequence). |
static String |
replaceAllRepeatedly(String sInputString,
String sSearchText,
String sReplacementText)
Just calls
replaceAll as long as there are still replacements
found |
static String |
replaceAllSafe(String sInputString,
String sSearchText,
CharSequence aReplacementText)
Same as
replaceAll(String, String, CharSequence) but allowing for
a null new-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 String |
replaceMultiple(String sInputString,
Map<String,String> aTransTable)
Perform all string replacements on the input string as defined by the
passed map.
|
static String |
replaceMultiple(String sInputString,
String[] aSearchTexts,
String[] aReplacementTexts)
Perform all string replacements on the input string as defined by the
passed map.
|
static String |
replaceMultipleAsString(String sInputString,
char[] aSearchChars,
char cReplacementChar)
Optimized replace method that replaces a set of characters with another
character.
|
static int |
replaceMultipleTo(char[] aInput,
char[] aSearchChars,
char[][] aReplacementStrings,
Writer aTarget)
Specialized version of
replaceMultiple(String, char[], char[][])
where the object where the output should be appended is passed in as a
parameter. |
static int |
replaceMultipleTo(char[] aInput,
int nOfs,
int nLen,
char[] aSearchChars,
char[][] aReplacementStrings,
Writer aTarget)
Specialized version of
replaceMultiple(String, char[], char[][])
where the object where the output should be appended is passed in as a
parameter. |
static int |
replaceMultipleTo(String sInputString,
char[] aSearchChars,
char[][] aReplacementStrings,
Writer aTarget)
Specialized version of
replaceMultiple(String, char[], char[][])
where the object where the output should be appended is passed in as a
parameter. |
static void |
replaceMultipleTo(String sInputString,
char[] aSearchChars,
char cReplacementChar,
StringBuilder aTarget)
Optimized replace method that replaces a set of characters with another
character.
|
static void |
replaceMultipleTo(String sInputString,
char[] aSearchChars,
char cReplacementChar,
Writer aTarget)
Optimized replace method that replaces a set of characters with another
character.
|
static boolean |
startsWith(CharSequence aCS,
char c) |
static boolean |
startsWith(CharSequence aCS,
CharSequence aSearch) |
static boolean |
startsWith(String sStr,
String sSearch) |
static boolean |
startsWithAny(CharSequence aCS,
char[] aChars) |
static boolean |
startsWithIgnoreCase(CharSequence aCS,
char c) |
static boolean |
startsWithIgnoreCase(String sStr,
String sSearch) |
static String |
trim(String s)
Trim the passed string, if it is not
null. |
static String |
trimEnd(String sSrc,
char cTail)
Trim the passed tail from the source value.
|
static String |
trimEnd(String sSrc,
int nCount)
Trim the passed tail from the source value.
|
static String |
trimEnd(String sSrc,
String sTail)
Trim the passed tail from the source value.
|
static String |
trimEndRepeatedly(String sSrc,
char cTail) |
static String |
trimEndRepeatedly(String sSrc,
String sTail) |
static String |
trimLeadingWhitespaces(String s)
Remove any leading whitespaces from the passed string.
|
static String |
trimStart(String sSrc,
char cLead)
Trim the passed lead from the source value.
|
static String |
trimStart(String sSrc,
int nCount)
Trim the passed lead from the source value.
|
static String |
trimStart(String sSrc,
String sLead)
Trim the passed lead from the source value.
|
static String |
trimStartAndEnd(String sSrc,
char cValueToTrim)
Trim the passed lead and tail from the source value.
|
static String |
trimStartAndEnd(String sSrc,
char cLead,
char cTail)
Trim the passed lead and tail from the source value.
|
static String |
trimStartAndEnd(String sSrc,
String sValueToTrim)
Trim the passed lead and tail from the source value.
|
static String |
trimStartAndEnd(String sSrc,
String sLead,
String sTail)
Trim the passed lead and tail from the source value.
|
static String |
trimStartRepeatedly(String sSrc,
char cLead) |
static String |
trimStartRepeatedly(String sSrc,
String sLead) |
static String |
trimTrailingWhitespaces(String s)
Remove any trailing whitespaces from the passed string.
|
public static final int STRING_NOT_FOUND
public static boolean hasNoText(@Nullable CharSequence aCS)
null or empty.aCS - The character sequence to check. May be null.true if the string is null or empty,
false otherwisepublic static boolean hasNoText(@Nullable String sStr)
null or empty.sStr - The string to check. May be null.true if the string is null or empty,
false otherwisepublic static boolean hasNoTextAfterTrim(@Nullable String s)
null or empty after trimming.s - The string to check. May be null.true if the string is null or empty or
consists only of whitespaces, false otherwisepublic static boolean hasText(@Nullable CharSequence aCS)
aCS - The character sequence to check. May be null.true if the string contains at least one,
false otherwisepublic static boolean hasText(@Nullable String sStr)
sStr - The string to check. May be null.true if the string contains at least one char,
false otherwisepublic static boolean hasTextAfterTrim(@Nullable String s)
null nor empty after trimming.s - The string to check. May be null.true if the string is neither null nor
empty nor consists only of whitespaces, false
otherwisepublic static boolean containsAny(@Nullable CharSequence aCS, @Nullable ICharPredicate aFilter)
CharSequence contains any character matching
the provided filter.aCS - String to check. May be null.aFilter - The filter to use. May be null.true if the filter is null and the string
is not empty. true if the filter is not
null and at least one character of the string matches
the filter. false otherwise.public static boolean containsAny(@Nullable String sStr, @Nullable ICharPredicate aFilter)
String contains any character matching the
provided filter.sStr - String to check. May be null.aFilter - The filter to use. May be null.true if the filter is null and the string
is not empty. true if the filter is not
null and at least one character of the string matches
the filter. false otherwise.public static boolean containsNone(@Nullable CharSequence aCS, @Nullable ICharPredicate aFilter)
CharSequence contains no character matching the
provided filter.aCS - String to check. May be null.aFilter - The filter to use. May be null.true if the filter is null and the string
is empty. true if the filter is not null
and no character of the string matches the filter.
false otherwise.public static boolean containsNone(@Nullable String sStr, @Nullable ICharPredicate aFilter)
String contains no character matching the
provided filter.sStr - String to check. May be null.aFilter - The filter to use. May be null.true if the filter is null and the string
is empty. true if the filter is not null
and no character of the string matches the filter.
false otherwise.public static boolean containsOnly(@Nullable CharSequence aCS, @Nullable ICharPredicate aFilter)
CharSequence contains only characters matching
the provided filter.aCS - String to check. May be null.aFilter - The filter to use. May be null.true if the filter is null and the string
is not empty. true if the filter is not
null and the string has at least one character and all
characters of the string match the filter. false
otherwise.public static boolean containsOnly(@Nullable String sStr, @Nullable ICharPredicate aFilter)
String contains only characters matching the
provided filter.sStr - String to check. May be null.aFilter - The filter to use. May be null.true if the filter is null and the string
is not empty. true if the filter is not
null and the string has at least one character and all
characters of the string match the filter. false
otherwise.public static boolean isAllWhitespace(@Nullable CharSequence s)
s - The character sequence to be checked. May be null.true if the passed sequence is empty or if only
whitespace characters are contained.Character.isWhitespace(char)@Nonnull public static String getWithLeading(@Nullable String sSrc, @Nonnegative int nMinLen, char cFront)
sSrc - Source string. May be null.nMinLen - Minimum length. Should be > 0.cFront - The character to be used at the beginningnull string that has at least nLen chars@Nonnull public static String getWithLeading(int nValue, @Nonnegative int nMinLen, char cFront)
nValue - Source string. May be null.nMinLen - Minimum length. Should be > 0.cFront - The character to be used at the beginningnull string that has at least nLen charsgetWithLeading(String, int, char)@Nonnull public static String getWithLeading(long nValue, @Nonnegative int nMinLen, char cFront)
nValue - Source string. May be null.nMinLen - Minimum length. Should be > 0.cFront - The character to be used at the beginningnull string that has at least nLen charsgetWithLeading(String, int, char)@Nonnull public static String getWithTrailing(@Nullable String sSrc, @Nonnegative int nMinLen, char cEnd)
sSrc - Source string. May be null.nMinLen - Minimum length. Should be > 0.cEnd - The character to be used at the endnull string that has at least nLen charspublic static char getHexChar(int n)
n - The value to get the hex digit from. Must be between 0 and 15.public static char getHexCharUpperCase(int n)
n - The value to get the hex digit from. Must be between 0 and 15.@Nonnull public static String getHexEncoded(@Nonnull String sInput, @Nonnull Charset aCharset)
sInput - The source string. May not be null.aCharset - The charset to use. May not be null.@Nonnull public static String getHexEncoded(@Nonnull byte[] aInput)
aInput - The byte array to be converted to a String. May not be
null.@Nonnull public static String getHexEncoded(@Nonnull byte[] aInput, int nOfs, int nLen)
aInput - The byte array to be converted to a String. May not be
null.nOfs - Byte array offsetnLen - Number of bytes to encode@CheckForSigned public static int getHexValue(@Nonnegative char c)
c - The hex char to convertpublic static int getHexByte(@Nonnegative char cHigh, @Nonnegative char cLow)
cHigh - High hex partcLow - Low hex part@Nonnull @ReturnsMutableCopy public static byte[] getHexDecoded(@Nonnull String sInput)
@Nonnull @ReturnsMutableCopy public static byte[] getHexDecoded(@Nonnull char[] aInput)
@Nonnull @ReturnsMutableCopy public static byte[] getHexDecoded(@Nonnull char[] aInput, @Nonnegative int nOfs, @Nonnegative int nLen)
@Nonnull public static String getHexStringLeadingZero(byte nValue, int nDigits)
@Nonnull public static String getHexStringLeadingZero(int nValue, int nDigits)
@Nonnull public static String getHexStringLeadingZero(long nValue, int nDigits)
@Nonnull public static String getHexStringLeadingZero(short nValue, int nDigits)
@Nonnegative public static int getLeadingWhitespaceCount(@Nullable String s)
Character.isWhitespace(char)s - The string to be parsed. May be null.@Nonnegative public static int getTrailingWhitespaceCount(@Nullable String s)
Character.isWhitespace(char)s - The string to be parsed. May be null.@Nonnegative public static int getLeadingCharCount(@Nullable String s, char c)
s - The string to be parsed. May be null.c - The char to be searched.@Nonnegative public static int getTrailingCharCount(@Nullable String s, char c)
s - The string to be parsed. May be null.c - The char to be searched.@Nonnull public static String getImploded(@Nullable Iterable<?> aElements)
null elements are added.aElements - The container to convert. May be null or empty.@Nonnull public static <ELEMENTTYPE> String getImplodedMapped(@Nullable Iterable<? extends ELEMENTTYPE> aElements, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
null elements are added.ELEMENTTYPE - Iterable element typeaElements - The container to convert. May be null or empty.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static String getImploded(@Nonnull String sSep, @Nullable Iterable<?> aElements)
null
elements are added.sSep - The separator to use. May not be null.aElements - The container to convert. May be null or empty.@Nonnull public static String getImploded(char cSep, @Nullable Iterable<?> aElements)
null elements
are added.cSep - The separator to use.aElements - The container to convert. May be null or empty.@Nonnull public static <ELEMENTTYPE> String getImplodedMapped(@Nonnull String sSep, @Nullable Iterable<? extends ELEMENTTYPE> aElements, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
null
elements are added.ELEMENTTYPE - The element type of the collection to be implodedsSep - The separator to use. May not be null.aElements - The container to convert. May be null or empty.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static <ELEMENTTYPE> String getImplodedMapped(char cSep, @Nullable Iterable<? extends ELEMENTTYPE> aElements, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
null elements
are added.ELEMENTTYPE - The element type of the collection to be implodedcSep - The separator to use.aElements - The container to convert. May be null or empty.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static <KEYTYPE,VALUETYPE> String getImploded(@Nonnull String sSepOuter, @Nonnull String sSepInner, @Nullable Map<KEYTYPE,VALUETYPE> aElements)
KEYTYPE - Map key typeVALUETYPE - Map value typesSepOuter - The separator to use for separating the map entries. May not be
null.sSepInner - The separator to use for separating the key from the value. May not
be null.aElements - The map to convert. May be null or empty.@Nonnull public static <KEYTYPE,VALUETYPE> String getImploded(char cSepOuter, char cSepInner, @Nullable Map<KEYTYPE,VALUETYPE> aElements)
KEYTYPE - Map key typeVALUETYPE - Map value typecSepOuter - The separator to use for separating the map entries.cSepInner - The separator to use for separating the key from the value.aElements - The map to convert. May be null or empty.@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)
KEYTYPE - Map key typeVALUETYPE - Map value typesSepOuter - The separator to use for separating the map entries. May not be
null.sSepInner - The separator to use for separating the key from the value. May not
be null.aElements - The map to convert. May be null or empty.aKeyMapper - The mapping function to convert from KEYTYPE to String. May not be
null.aValueMapper - The mapping function to convert from VALUETYPE to String. May not be
null.@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)
KEYTYPE - Map key typeVALUETYPE - Map value typecSepOuter - The separator to use for separating the map entries.cSepInner - The separator to use for separating the key from the value.aElements - The map to convert. May be null or empty.aKeyMapper - The mapping function to convert from KEYTYPE to String. May not be
null.aValueMapper - The mapping function to convert from VALUETYPE to String. May not be
null.@Nonnull @SafeVarargs public static <ELEMENTTYPE> String getImploded(@Nullable ELEMENTTYPE... aElements)
ELEMENTTYPE - The type of elements to be imploded.aElements - The container to convert. May be null or empty.@Nonnull public static <ELEMENTTYPE> String getImploded(@Nullable ELEMENTTYPE[] aElements, @Nonnegative int nOfs, @Nonnegative int nLen)
ELEMENTTYPE - The type of elements to be imploded.aElements - The container to convert. May be null or empty.nOfs - The offset to start from.nLen - The number of elements to implode.@Nonnull public static <ELEMENTTYPE> String getImplodedMapped(@Nullable ELEMENTTYPE[] aElements, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
ELEMENTTYPE - The type of elements to be imploded.aElements - The container to convert. May be null or empty.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static <ELEMENTTYPE> String getImplodedMapped(@Nullable ELEMENTTYPE[] aElements, @Nonnegative int nOfs, @Nonnegative int nLen, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
ELEMENTTYPE - The type of elements to be imploded.aElements - The container to convert. May be null or empty.nOfs - The offset to start from.nLen - The number of elements to implode.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull @SafeVarargs public static <ELEMENTTYPE> String getImploded(@Nonnull String sSep, @Nullable ELEMENTTYPE... aElements)
ELEMENTTYPE - The type of elements to be imploded.sSep - The separator to use. May not be null.aElements - The container to convert. May be null or empty.@Nonnull @SafeVarargs public static <ELEMENTTYPE> String getImploded(char cSep, @Nullable ELEMENTTYPE... aElements)
ELEMENTTYPE - The type of elements to be imploded.cSep - The separator to use.aElements - The container to convert. May be null or empty.@Nonnull public static <ELEMENTTYPE> String getImploded(@Nonnull String sSep, @Nullable ELEMENTTYPE[] aElements, @Nonnegative int nOfs, @Nonnegative int nLen)
ELEMENTTYPE - The type of elements to be imploded.sSep - The separator to use. May not be null.aElements - The container to convert. May be null or empty.nOfs - The offset to start from.nLen - The number of elements to implode.@Nonnull public static <ELEMENTTYPE> String getImplodedMapped(@Nonnull String sSep, @Nullable ELEMENTTYPE[] aElements, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
ELEMENTTYPE - The type of elements to be imploded.sSep - The separator to use. May not be null.aElements - The container to convert. May be null or empty.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static <ELEMENTTYPE> String getImplodedMapped(char cSep, @Nullable ELEMENTTYPE[] aElements, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
ELEMENTTYPE - The type of elements to be imploded.cSep - The separator to use.aElements - The container to convert. May be null or empty.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static <ELEMENTTYPE> String getImplodedMapped(char cSep, @Nullable ELEMENTTYPE[] aElements, @Nonnegative int nOfs, @Nonnegative int nLen, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
ELEMENTTYPE - The type of elements to be imploded.cSep - The separator to use.aElements - The container to convert. May be null or empty.nOfs - The offset to start from.nLen - The number of elements to implode.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static <ELEMENTTYPE> String getImplodedMapped(@Nonnull String sSep, @Nullable ELEMENTTYPE[] aElements, @Nonnegative int nOfs, @Nonnegative int nLen, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
ELEMENTTYPE - The type of elements to be imploded.sSep - The separator to use. May not be null.aElements - The container to convert. May be null or empty.nOfs - The offset to start from.nLen - The number of elements to implode.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static <ELEMENTTYPE> String getImploded(char cSep, @Nullable ELEMENTTYPE[] aElements, @Nonnegative int nOfs, @Nonnegative int nLen)
ELEMENTTYPE - The type of elements to be imploded.cSep - The separator to use.aElements - The container to convert. May be null or empty.nOfs - The offset to start from.nLen - The number of elements to implode.@Nonnull public static String getImplodedNonEmpty(@Nullable Iterable<String> aElements)
null and non empty
elements of the passed container without a separator string. This the very
generic version of getConcatenatedOnDemand(String, String) for an
arbitrary number of elements.aElements - The container to convert. May be null or empty.@Nonnull public static <ELEMENTTYPE> String getImplodedMappedNonEmpty(@Nullable Iterable<? extends ELEMENTTYPE> aElements, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
null and non empty
elements of the passed container without a separator string. This the very
generic version of getConcatenatedOnDemand(String, String) for an
arbitrary number of elements.ELEMENTTYPE - Iterable element typeaElements - The container to convert. May be null or empty.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static <ELEMENTTYPE> String getImplodedMappedNonEmpty(@Nullable ELEMENTTYPE[] aElements, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
null and non empty
elements of the passed container without a separator string. This the very
generic version of getConcatenatedOnDemand(String, String) for an
arbitrary number of elements.ELEMENTTYPE - Array component typeaElements - The array to convert. May be null or empty.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static String getImplodedNonEmpty(@Nonnull String sSep, @Nullable Iterable<String> aElements)
null and non empty
elements of the passed container, separated by the specified separator
string. This the very generic version of
getConcatenatedOnDemand(String, String, String) for an arbitrary
number of elements.sSep - The separator to use. May not be null.aElements - The container to convert. May be null or empty.@Nonnull public static String getImplodedNonEmpty(char cSep, @Nullable Iterable<String> aElements)
null and non empty
elements of the passed container, separated by the specified separator
char. This the very generic version of
getConcatenatedOnDemand(String, String, String) for an arbitrary
number of elements.cSep - The separator to use.aElements - The container to convert. May be null or empty.@Nonnull public static <ELEMENTTYPE> String getImplodedMappedNonEmpty(@Nonnull String sSep, @Nullable Iterable<? extends ELEMENTTYPE> aElements, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
null and non empty
elements of the passed container, separated by the specified separator
string. This the very generic version of
getConcatenatedOnDemand(String, String, String) for an arbitrary
number of elements.ELEMENTTYPE - The element type of the collection to be implodedsSep - The separator to use. May not be null.aElements - The container to convert. May be null or empty.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static <ELEMENTTYPE> String getImplodedMappedNonEmpty(char cSep, @Nullable Iterable<? extends ELEMENTTYPE> aElements, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
null and non empty
elements of the passed container, separated by the specified separator
char. This the very generic version of
getConcatenatedOnDemand(String, String, String) for an arbitrary
number of elements.ELEMENTTYPE - The element type of the collection to be implodedcSep - The separator to use.aElements - The container to convert. May be null or empty.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static String getImplodedNonEmpty(@Nonnull String sSep, @Nullable String... aElements)
getConcatenatedOnDemand(String, String, String) for an arbitrary
number of elements.sSep - The separator to use. May not be null.aElements - The container to convert. May be null or empty.@Nonnull public static String getImplodedNonEmpty(char cSep, @Nullable String... aElements)
getConcatenatedOnDemand(String, String, String) for an arbitrary
number of elements.cSep - The separator to use.aElements - The container to convert. May be null or empty.@Nonnull public static <ELEMENTTYPE> String getImplodedMappedNonEmpty(@Nonnull String sSep, @Nullable ELEMENTTYPE[] aElements, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
getConcatenatedOnDemand(String, String, String) for an arbitrary
number of elements.ELEMENTTYPE - Array component typesSep - The separator to use. May not be null.aElements - The container to convert. May be null or empty.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static <ELEMENTTYPE> String getImplodedMappedNonEmpty(char cSep, @Nullable ELEMENTTYPE[] aElements, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
getConcatenatedOnDemand(String, String, String) for an arbitrary
number of elements.ELEMENTTYPE - Array component typecSep - The separator to use.aElements - The container to convert. May be null or empty.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static String getImplodedNonEmpty(@Nonnull String sSep, @Nullable String[] aElements, @Nonnegative int nOfs, @Nonnegative int nLen)
getConcatenatedOnDemand(String, String, String) for an arbitrary
number of elements.sSep - The separator to use. May not be null.aElements - The container to convert. May be null or empty.nOfs - The offset to start from.nLen - The number of elements to implode.@Nonnull public static String getImplodedNonEmpty(char cSep, @Nullable String[] aElements, @Nonnegative int nOfs, @Nonnegative int nLen)
getConcatenatedOnDemand(String, String, String) for an arbitrary
number of elements.cSep - The separator to use.aElements - The container to convert. May be null or empty.nOfs - The offset to start from.nLen - The number of elements to implode.@Nonnull public static <ELEMENTTYPE> String getImplodedMappedNonEmpty(@Nonnull String sSep, @Nullable ELEMENTTYPE[] aElements, @Nonnegative int nOfs, @Nonnegative int nLen, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
getConcatenatedOnDemand(String, String, String) for an arbitrary
number of elements.ELEMENTTYPE - Array component typesSep - The separator to use. May not be null.aElements - The container to convert. May be null or empty.nOfs - The offset to start from.nLen - The number of elements to implode.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static <ELEMENTTYPE> String getImplodedMappedNonEmpty(char cSep, @Nullable ELEMENTTYPE[] aElements, @Nonnegative int nOfs, @Nonnegative int nLen, @Nonnull Function<? super ELEMENTTYPE,String> aMapper)
getConcatenatedOnDemand(String, String, String) for an arbitrary
number of elements.ELEMENTTYPE - Array component typecSep - The separator to use.aElements - The container to convert. May be null or empty.nOfs - The offset to start from.nLen - The number of elements to implode.aMapper - The mapping function to convert from ELEMENTTYPE to String. May not
be null.@Nonnull public static String[] getExplodedArray(char cSep, @Nullable String sElements, @CheckForSigned int nMaxItems)
cSep - The separator to use.sElements - The concatenated String to convert. May be null or
empty.nMaxItems - The maximum number of items to explode. If the passed value is ≤
0 all items are used. If max items is 1, than the result string is
returned as is. If max items is larger than the number of elements
found, it has no effect.null.@Nonnull public static String[] getExplodedArray(char cSep, @Nullable String sElements)
cSep - The separator to use.sElements - The concatenated String to convert. May be null or
empty.null.@Nonnull @ReturnsMutableObject(value="The passed parameter") @CodingStyleguideUnaware public static <COLLTYPE extends Collection<String>> COLLTYPE getExploded(char cSep, @Nullable String sElements, int nMaxItems, @Nonnull COLLTYPE aCollection)
COLLTYPE - The collection type to be passed and returnedcSep - The separator to use.sElements - The concatenated String to convert. May be null or
empty.nMaxItems - The maximum number of items to explode. If the passed value is ≤
0 all items are used. If max items is 1, than the result string is
returned as is. If max items is larger than the number of elements
found, it has no effect.aCollection - The non-null target collection that should be filled
with the exploded elementsnull.public static void explode(char cSep,
@Nullable
String sElements,
@Nonnull
Consumer<? super String> aConsumer)
cSep - The separator to use.sElements - The concatenated String to convert. May be null or
empty.aConsumer - The non-null consumer that is invoked for each exploded
elementpublic static void explode(char cSep,
@Nullable
String sElements,
int nMaxItems,
@Nonnull
Consumer<? super String> aConsumer)
cSep - The separator to use.sElements - The concatenated String to convert. May be null or
empty.nMaxItems - The maximum number of items to explode. If the passed value is ≤
0 all items are used. If max items is 1, than the result string is
returned as is. If max items is larger than the number of elements
found, it has no effect.aConsumer - The non-null consumer that is invoked for each exploded
element@Nonnull @ReturnsMutableCopy public static ICommonsList<String> getExploded(char cSep, @Nullable String sElements)
ICommonsList of all
elements in the passed string, using specified separator string.cSep - The separator character to use.sElements - The concatenated String to convert. May be null or
empty.ICommonsList represented by the passed string. Never
null. If the passed input string is null
or "" an empty list is returned.@Nonnull @ReturnsMutableCopy public static ICommonsList<String> getExploded(char cSep, @Nullable String sElements, int nMaxItems)
ICommonsList of all
elements in the passed string, using specified separator string.cSep - The separator character to use.sElements - The concatenated String to convert. May be null or
empty.nMaxItems - The maximum number of items to explode. If the passed value is ≤
0 all items are used. If max items is 1, than the result string is
returned as is. If max items is larger than the number of elements
found, it has no effect.ICommonsList represented by the passed string. Never
null. If the passed input string is null
or "" an empty list is returned.@Nonnull @CodingStyleguideUnaware public static <COLLTYPE extends Collection<String>> COLLTYPE getExploded(@Nonnull String sSep, @Nullable String sElements, int nMaxItems, @Nonnull COLLTYPE aCollection)
COLLTYPE - The collection type to be used and returnedsSep - The separator to use. May not be null.sElements - The concatenated String to convert. May be null or
empty.nMaxItems - The maximum number of items to explode. If the passed value is ≤
0 all items are used. If max items is 1, than the result string is
returned as is. If max items is larger than the number of elements
found, it has no effect.aCollection - The non-null target collection that should be filled
with the exploded elementsnull.public static void explode(@Nonnull String sSep, @Nullable String sElements, @Nonnull Consumer<? super String> aConsumer)
sSep - The separator to use. May not be null.sElements - The concatenated String to convert. May be null or
empty.aConsumer - The non-null consumer that is invoked for each exploded
elementpublic static void explode(@Nonnull String sSep, @Nullable String sElements, int nMaxItems, @Nonnull Consumer<? super String> aConsumer)
sSep - The separator to use. May not be null.sElements - The concatenated String to convert. May be null or
empty.nMaxItems - The maximum number of items to explode. If the passed value is ≤
0 all items are used. If max items is 1, than the result string is
returned as is. If max items is larger than the number of elements
found, it has no effect.aConsumer - The non-null consumer that is invoked for each exploded
element@Nonnull @ReturnsMutableCopy public static ICommonsList<String> getExploded(@Nonnull String sSep, @Nullable String sElements)
ICommonsList of all
elements in the passed string, using specified separator string.sSep - The separator to use. May not be null.sElements - The concatenated String to convert. May be null or
empty.ICommonsList represented by the passed string. Never
null. If the passed input string is null
or "" an empty list is returned.@Nonnull @ReturnsMutableCopy public static ICommonsList<String> getExploded(@Nonnull String sSep, @Nullable String sElements, int nMaxItems)
ICommonsList of all
elements in the passed string, using specified separator string.sSep - The separator to use. May not be null.sElements - The concatenated String to convert. May be null or
empty.nMaxItems - The maximum number of items to explode. If the passed value is ≤
0 all items are used. If max items is 1, than the result string is
returned as is. If max items is larger than the number of elements
found, it has no effect.ICommonsList represented by the passed string. Never
null. If the passed input string is null
or "" an empty list is returned.@Nonnull @ReturnsMutableCopy public static CommonsHashSet<String> getExplodedToSet(@Nonnull String sSep, @Nullable String sElements)
Set of all elements in the
passed string, using specified separator string.sSep - The separator to use. May not be null.sElements - The concatenated String to convert. May be null or
empty.Set represented by the passed string. Never
null. If the passed input string is null
or "" an empty list is returned.@Nonnull @ReturnsMutableCopy public static CommonsLinkedHashSet<String> getExplodedToOrderedSet(@Nonnull String sSep, @Nullable String sElements)
CommonsLinkedHashSet of all elements in the passed string, using
specified separator string.sSep - The separator to use. May not be null.sElements - The concatenated String to convert. May be null or
empty.Set represented by the passed string. Never
null. If the passed input string is null
or "" an empty list is returned.@Nonnull @ReturnsMutableCopy public static CommonsTreeSet<String> getExplodedToSortedSet(@Nonnull String sSep, @Nullable String sElements)
CommonsTreeSet of
all elements in the passed string, using specified separator string.sSep - The separator to use. May not be null.sElements - The concatenated String to convert. May be null or
empty.Set represented by the passed string. Never
null. If the passed input string is null
or "" an empty list is returned.@Nonnull public static String getRepeated(char cElement, @Nonnegative int nRepeats)
cElement - The character to get repeated.nRepeats - The number of repetitions to retrieve. May not be < 0.null string containing the string element for
the given number of times.@Nonnull public static String getRepeated(@Nonnull String sElement, @Nonnegative int nRepeats)
sElement - The string to get repeated. May not be null.nRepeats - The number of repetitions to retrieve. May not be < 0.null string containing the string element for
the given number of times.@Nonnull public static String getConcatenatedOnDemand(@Nullable String sFront, @Nullable String sEnd)
null or empty only the other element is returned. If both
strings are null or empty and empty String is returned.sFront - Front string. May be null.sEnd - May be null.null.@Nonnull public static String getConcatenatedOnDemand(@Nullable String sFront, @Nullable String sSep, @Nullable String sEnd)
null or empty, the separator is not applied.sFront - Front string. May be null.sSep - Separator string. May be null.sEnd - May be null.@Nonnull public static String getConcatenatedOnDemand(@Nullable String sFront, char cSep, @Nullable String sEnd)
null or empty, the separator is not applied.sFront - Front string. May be null.cSep - Separator character.sEnd - May be null.@Nonnull public static String getQuoted(@Nullable String sSource)
null.sSource - Source string. May be null."null" if the source is null,
"'" + sSource + "'" otherwise.public static void appendQuoted(@Nonnull StringBuilder aTarget, @Nullable String sSource)
null.aTarget - The target to write to. May not be null.sSource - Source string. May be null.getQuoted(String)public static void appendQuoted(@Nonnull Appendable aTarget, @Nullable String sSource) throws IOException
null.aTarget - The target to write to. May not be null.sSource - Source string. May be null.IOException - in case of IO errorgetQuoted(String)public static boolean startsWith(@Nullable CharSequence aCS, char c)
public static boolean startsWithAny(@Nullable CharSequence aCS, @Nullable char[] aChars)
public static boolean startsWithIgnoreCase(@Nullable CharSequence aCS, char c)
public static boolean startsWith(@Nullable CharSequence aCS, @Nullable CharSequence aSearch)
public static boolean startsWithIgnoreCase(@Nullable String sStr, @Nullable String sSearch)
public static boolean endsWith(@Nullable CharSequence aCS, char c)
public static boolean endsWithAny(@Nullable CharSequence aCS, @Nullable char[] aChars)
public static boolean endsWith(@Nullable CharSequence aCS, @Nullable CharSequence aSearch)
public static boolean endsWithIgnoreCase(@Nullable CharSequence aCS, char c)
public static boolean endsWithIgnoreCase(@Nullable String sStr, @Nullable String sSearch)
public static int getIndexOf(@Nullable String sText, @Nullable String sSearch)
sText - The text to search in. May be null.sSearch - The text to search for. May be null.null.String.indexOf(String)public static int getIndexOf(@Nullable String sText, @Nonnegative int nFromIndex, @Nullable String sSearch)
sText - The text to search in. May be null.nFromIndex - The index to start searching in the source stringsSearch - The text to search for. May be null.null.String.indexOf(String,int)public static int getLastIndexOf(@Nullable String sText, @Nullable String sSearch)
sText - The text to search in. May be null.sSearch - The text to search for. May be null.null.String.lastIndexOf(String)public static int getLastIndexOf(@Nullable String sText, @Nonnegative int nFromIndex, @Nullable String sSearch)
sText - The text to search in. May be null.nFromIndex - The index to start searching in the source stringsSearch - The text to search for. May be null.null.String.lastIndexOf(String,int)public static int getIndexOf(@Nullable String sText, char cSearch)
sText - The text to search in. May be null.cSearch - The character to search for. May be null.null.String.indexOf(int)public static int getIndexOf(@Nullable String sText, @Nonnegative int nFromIndex, char cSearch)
sText - The text to search in. May be null.nFromIndex - The index to start searching in the source stringcSearch - The character to search for. May be null.null.String.indexOf(int,int)public static int getLastIndexOf(@Nullable String sText, char cSearch)
sText - The text to search in. May be null.cSearch - The character to search for. May be null.null.String.lastIndexOf(int)public static int getLastIndexOf(@Nullable String sText, @Nonnegative int nFromIndex, char cSearch)
sText - The text to search in. May be null.nFromIndex - The index to start searching in the source stringcSearch - The character to search for. May be null.null.String.lastIndexOf(int,int)public static int getIndexOfIgnoreCase(@Nullable String sText, @Nullable String sSearch, @Nonnull Locale aSortLocale)
sText - The text to search in. May be null.sSearch - The text to search for. May be null.aSortLocale - The locale to be used for case unifying.null.String.indexOf(String)public static int getIndexOfIgnoreCase(@Nullable String sText, @Nonnegative int nFromIndex, @Nullable String sSearch, @Nonnull Locale aSortLocale)
sText - The text to search in. May be null.nFromIndex - The index to start searching in the source stringsSearch - The text to search for. May be null.aSortLocale - The locale to be used for case unifying.null.String.indexOf(String)public static int getLastIndexOfIgnoreCase(@Nullable String sText, @Nullable String sSearch, @Nonnull Locale aSortLocale)
sText - The text to search in. May be null.sSearch - The text to search for. May be null.aSortLocale - The locale to be used for case unifying.null.String.lastIndexOf(String)public static int getLastIndexOfIgnoreCase(@Nullable String sText, @Nonnegative int nFromIndex, @Nullable String sSearch, @Nonnull Locale aSortLocale)
sText - The text to search in. May be null.nFromIndex - The index to start searching in the source stringsSearch - The text to search for. May be null.aSortLocale - The locale to be used for case unifying.null.String.lastIndexOf(String)public static int getIndexOfIgnoreCase(@Nullable String sText, char cSearch, @Nonnull Locale aSortLocale)
sText - The text to search in. May be null.cSearch - The char to search for. May be null.aSortLocale - The locale to be used for case unifying.null.String.indexOf(int)public static int getIndexOfIgnoreCase(@Nullable String sText, @Nonnegative int nFromIndex, char cSearch, @Nonnull Locale aSortLocale)
sText - The text to search in. May be null.nFromIndex - The index to start searching in the source stringcSearch - The char to search for. May be null.aSortLocale - The locale to be used for case unifying.null.String.indexOf(int)public static int getLastIndexOfIgnoreCase(@Nullable String sText, char cSearch, @Nonnull Locale aSortLocale)
sText - The text to search in. May be null.cSearch - The char to search for. May be null.aSortLocale - The locale to be used for case unifying.null.String.lastIndexOf(int)public static int getLastIndexOfIgnoreCase(@Nullable String sText, @Nonnegative int nFromIndex, char cSearch, @Nonnull Locale aSortLocale)
sText - The text to search in. May be null.nFromIndex - The index to start searching in the source stringcSearch - The char to search for. May be null.aSortLocale - The locale to be used for case unifying.null.String.lastIndexOf(int)public static boolean contains(@Nullable String sText, @Nullable String sSearch)
sText - The text to search in. May be null.sSearch - The text to search for. May be null.true if sSearch is contained in sText,
false otherwise.String.contains(CharSequence)public static boolean contains(@Nullable String sText, char cSearch)
sText - The text to search in. May be null.cSearch - The character to search for. May be null.true if cSearch is contained in sText,
false otherwise.String.contains(CharSequence)public static boolean containsIgnoreCase(@Nullable String sText, @Nullable String sSearch, @Nonnull Locale aSortLocale)
sText - The text to search in. May be null.sSearch - The text to search for. May be null.aSortLocale - The locale to be used for case unifying.true if sSearch is contained in sText,
false otherwise.String.contains(CharSequence)public static boolean containsIgnoreCase(@Nullable String sText, char cSearch, @Nonnull Locale aSortLocale)
sText - The text to search in. May be null.cSearch - The char to search for. May be null.aSortLocale - The locale to be used for case unifying.true if sSearch is contained in sText,
false otherwise.String.indexOf(int)public static boolean containsAny(@Nullable char[] aInput, @Nonnull char[] aSearchChars)
aInput - The input char array. May be null.aSearchChars - The char array to search. May not be null.true if at least any of the search char is contained
in the input char array, false otherwise.public static boolean containsAny(@Nullable String sInput, @Nonnull char[] aSearchChars)
sInput - The input string. May be null.aSearchChars - The char array to search. May not be null.true if at least any of the search char is contained
in the input char array, false otherwise.@Nonnegative public static int getOccurrenceCount(@Nullable String sText, @Nullable String sSearch)
sText - The text to search in. May be null.sSearch - The text to search for. May be null.@Nonnegative public static int getOccurrenceCountIgnoreCase(@Nullable String sText, @Nullable String sSearch, @Nonnull Locale aSortLocale)
sText - The text to search in. May be null.sSearch - The text to search for. May be null.aSortLocale - The locale to be used for case unifying.@Nonnegative public static int getOccurrenceCount(@Nullable String sText, char cSearch)
sText - The text to search in. May be null.cSearch - The character to search for.@Nonnegative public static int getOccurrenceCountIgnoreCase(@Nullable String sText, char cSearch, @Nonnull Locale aSortLocale)
sText - The text to search in. May be null.cSearch - The character to search for.aSortLocale - The locale to be used for case unifying.@Nullable @CheckReturnValue public static String trimLeadingWhitespaces(@Nullable String s)
s - the String to be trimmed@Nullable @CheckReturnValue public static String trimTrailingWhitespaces(@Nullable String s)
s - the String to be cut@Nullable @CheckReturnValue public static String trimStart(@Nullable String sSrc, @Nullable String sLead)
sSrc - The input source stringsLead - The string to be trimmed of the beginningtrimEnd(String, String),
trimStartAndEnd(String, String),
trimStartAndEnd(String, String, String)@Nullable @CheckReturnValue public static String trimStartRepeatedly(@Nullable String sSrc, @Nullable String sLead)
@Nullable @CheckReturnValue public static String trimStart(@Nullable String sSrc, char cLead)
sSrc - The input source stringcLead - The char to be trimmed of the beginningtrimEnd(String, String),
trimStartAndEnd(String, String),
trimStartAndEnd(String, String, String)@Nullable @CheckReturnValue public static String trimStartRepeatedly(@Nullable String sSrc, char cLead)
@Nullable @CheckReturnValue public static String trimStart(@Nullable String sSrc, @Nonnegative int nCount)
sSrc - The input source stringnCount - The number of characters to trim at the end.@Nullable @CheckReturnValue public static String trimEnd(@Nullable String sSrc, @Nullable String sTail)
sSrc - The input source stringsTail - The string to be trimmed of the endtrimStart(String, String),
trimStartAndEnd(String, String),
trimStartAndEnd(String, String, String)@Nullable @CheckReturnValue public static String trimEndRepeatedly(@Nullable String sSrc, @Nullable String sTail)
@Nullable @CheckReturnValue public static String trimEnd(@Nullable String sSrc, char cTail)
sSrc - The input source stringcTail - The char to be trimmed of the endtrimStart(String, String),
trimStartAndEnd(String, String),
trimStartAndEnd(String, String, String)@Nullable @CheckReturnValue public static String trimEndRepeatedly(@Nullable String sSrc, char cTail)
@Nullable @CheckReturnValue public static String trimEnd(@Nullable String sSrc, @Nonnegative int nCount)
sSrc - The input source stringnCount - The number of characters to trim at the end.@Nullable @CheckReturnValue public static String trimStartAndEnd(@Nullable String sSrc, @Nullable String sValueToTrim)
sSrc - The input source stringsValueToTrim - The string to be trimmed of the beginning and the endtrimStart(String, String),
trimEnd(String, String),
trimStartAndEnd(String, String, String)@Nullable @CheckReturnValue public static String trimStartAndEnd(@Nullable String sSrc, @Nullable String sLead, @Nullable String sTail)
sSrc - The input source stringsLead - The string to be trimmed of the beginningsTail - The string to be trimmed of the endtrimStart(String, String),
trimEnd(String, String),
trimStartAndEnd(String, String)@Nullable @CheckReturnValue public static String trimStartAndEnd(@Nullable String sSrc, char cValueToTrim)
sSrc - The input source stringcValueToTrim - The char to be trimmed of the beginning and the endtrimStart(String, String),
trimEnd(String, String),
trimStartAndEnd(String, String, String)@Nullable @CheckReturnValue public static String trimStartAndEnd(@Nullable String sSrc, char cLead, char cTail)
sSrc - The input source stringcLead - The char to be trimmed of the beginningcTail - The char to be trimmed of the endtrimStart(String, char),
trimEnd(String, char),
trimStartAndEnd(String, char)@Nullable @CheckReturnValue public static String trim(@Nullable String s)
null.s - The string to be trimmed. May be null.null if the input string was null, the
non-null trimmed string otherwise.String.trim()public static char getFirstChar(@Nullable CharSequence aCS)
aCS - The source character sequenceCGlobal.ILLEGAL_CHAR if the passed sequence was emptypublic static char getFirstChar(@Nullable char[] aChars)
aChars - The character arrayCGlobal.ILLEGAL_CHAR if the passed array was emptypublic static char getLastChar(@Nullable CharSequence aCS)
aCS - The source character sequenceCGlobal.ILLEGAL_CHAR if the passed sequence was emptypublic static char getLastChar(@Nullable char[] aChars)
aChars - The character arrayCGlobal.ILLEGAL_CHAR if the passed array was empty@Nonnegative public static int getCharCount(@Nullable String s, char cSearch)
@Nonnegative public static int getCharCount(@Nullable char[] aChars, char cSearch)
@Nonnegative public static int getLineCount(@Nullable String s)
@Nonnegative public static int getLineCount(@Nullable String s, char cLineSep)
@Nonnegative public static int getCharacterCount(int nValue)
nValue - The integer value to check. May be be positive or negative.@Nonnegative public static int getCharacterCount(long nValue)
nValue - The long value to check. May be be positive or negative.@Nonnull public static String getCutAfterLength(@Nonnull String sValue, @Nonnegative int nMaxLength)
@Nonnull public static String getCutAfterLength(@Nonnull String sValue, @Nonnegative int nMaxLength, @Nullable String sNewSuffix)
public static String replaceAllSafe(@Nullable String sInputString, @Nonnull String sSearchText, @Nullable CharSequence aReplacementText)
replaceAll(String, String, CharSequence) but allowing for
a null new-value, which is than interpreted as an empty string
instead.sInputString - The input string where the text should be replace. If this parameter
is null or empty, no replacement is done.sSearchText - The string to be replaced. May neither be null nor
empty.aReplacementText - The string with the replacement. May be null or empty.@Nullable public static String replaceAll(@Nullable String sInputString, @Nonnull String sSearchText, @Nonnull CharSequence aReplacementText)
String.replace(CharSequence, CharSequence). The problem with the
mentioned String method is, that is uses internally regular
expressions which use a synchronized block to compile the patterns. This
method is inherently thread safe since String is immutable and
we're operating on different temporary StringBuilder objects.sInputString - The input string where the text should be replace. If this parameter
is null or empty, no replacement is done.sSearchText - The string to be replaced. May neither be null nor
empty.aReplacementText - The string with the replacement. May not be null but
may be empty.@Nullable public static String replaceAll(@Nullable String sInputString, char cSearchChar, char cReplacementChar)
String.replace(char, char) for
characters. The problem with the mentioned String method is, that is uses
internally regular expressions which use a synchronized block to compile
the patterns. This method is inherently thread safe since String is
immutable and we're operating on different temporary StringBuilder
objects.sInputString - The input string where the text should be replace. If this parameter
is null or empty, no replacement is done.cSearchChar - The character to be replaced.cReplacementChar - The character with the replacement.@Nullable public static String replaceAllRepeatedly(@Nullable String sInputString, @Nonnull String sSearchText, @Nonnull String sReplacementText)
replaceAll as long as there are still replacements
foundsInputString - The input string where the text should be replace. If this parameter
is null or empty, no replacement is done.sSearchText - The string to be replaced. May neither be null nor
empty.sReplacementText - The string with the replacement. May not be null but
may be empty.public static int getReplaceMultipleResultLength(@Nonnull char[] aInputString, @Nonnull @Nonempty char[] aSearchChars, @Nonnull @Nonempty char[][] aReplacementStrings)
aInputString - Input char array. May not be null.aSearchChars - The one-character search patterns. May not be null.aReplacementStrings - The replacements to be performed. May not be null. The
first dimension of this array must have exactly the same amount of
elements as the patterns parameter array.CGlobal.ILLEGAL_UINT if no replacement was needed, and
therefore the length of the input array could be used.@Nonnull public static char[] replaceMultiple(@Nullable String sInputString, @Nonnull char[] aSearchChars, @Nonnull char[][] aReplacementStrings)
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.null.@Nonnull public static char[] replaceMultiple(@Nullable char[] aInput, @Nonnull char[] aSearchChars, @Nonnull char[][] aReplacementStrings)
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.null.@Nonnegative public static int replaceMultipleTo(@Nullable String sInputString, @Nonnull char[] aSearchChars, @Nonnull char[][] aReplacementStrings, @Nonnull Writer aTarget) throws IOException
replaceMultiple(String, char[], char[][])
where the object where the output should be appended is passed in as a
parameter. This has the advantage, that not length calculation needs to
take place!sInputString - The input string.aSearchChars - The characters to replace.aReplacementStrings - The new strings to be inserted instead. Must have the same array
length as aPatterns.aTarget - Where the replaced objects should be written to. May not be
null.IOException - In case writing to the Writer fails@Nonnegative public static int replaceMultipleTo(@Nullable char[] aInput, @Nonnull char[] aSearchChars, @Nonnull char[][] aReplacementStrings, @Nonnull Writer aTarget) throws IOException
replaceMultiple(String, char[], char[][])
where the object where the output should be appended is passed in as a
parameter. This has the advantage, that not length calculation needs to
take place!aInput - The input char array. May not be null.aSearchChars - The characters to replace.aReplacementStrings - The new strings to be inserted instead. Must have the same array
length as aPatterns.aTarget - Where the replaced objects should be written to. May not be
null.IOException - In case writing to the Writer fails@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
replaceMultiple(String, char[], char[][])
where the object where the output should be appended is passed in as a
parameter. This has the advantage, that not length calculation needs to
take place!aInput - The input char array. May be null.nOfs - Offset into input array. Must be ≥ 0.nLen - Number of characters from input array. Must be ≥ 0.aSearchChars - The characters to replace.aReplacementStrings - The new strings to be inserted instead. Must have the same array
length as aPatterns.aTarget - Where the replaced objects should be written to. May not be
null.IOException - In case writing to the Writer fails@Nonnull public static char[] replaceMultiple(@Nullable String sInputString, @Nonnull char[] aSearchChars, char cReplacementChar)
sInputString - The input string.aSearchChars - The characters to replace.cReplacementChar - The new char to be used instead of the search chars.null.public static void replaceMultipleTo(@Nullable String sInputString, @Nonnull char[] aSearchChars, char cReplacementChar, @Nonnull StringBuilder aTarget)
sInputString - The input string.aSearchChars - The characters to replace.cReplacementChar - The new char to be used instead of the search chars.aTarget - The target StringBuilder to write the result to. May not be
null.public static void replaceMultipleTo(@Nullable String sInputString, @Nonnull char[] aSearchChars, char cReplacementChar, @Nonnull Writer aTarget) throws IOException
sInputString - The input string.aSearchChars - The characters to replace.cReplacementChar - The new char to be used instead of the search chars.aTarget - The target writer to write the result to. May not be
null.IOException - in case writing to the Writer fails@Nonnull public static String replaceMultipleAsString(@Nullable String sInputString, @Nonnull char[] aSearchChars, char cReplacementChar)
sInputString - The input string.aSearchChars - The characters to replace.cReplacementChar - The new char to be used instead of the search chars.null.@Nullable public static String replaceMultiple(@Nullable String sInputString, @Nullable Map<String,String> aTransTable)
replaceAll(String,String,CharSequence) which is ok.sInputString - The input string where the text should be replaced. May be
null.aTransTable - The map with the replacements to execute. If null is
passed, the input string is not altered.null if the input string was null.@Nullable public static String replaceMultiple(@Nullable String sInputString, @Nullable String[] aSearchTexts, @Nullable String[] aReplacementTexts)
replaceAll(String,String,CharSequence) which is ok.sInputString - The input string where the text should be replaced. May be
null.aSearchTexts - The texts to be searched. If null is passed, the input
string is not altered.aReplacementTexts - The texts to be used as the replacements. This array must have
exactly the same number of elements than the searched texts! If
null is passed, the input string is not altered.null if the input string was null. The
unmodified input string if no search/replace patterns where
provided.@Nullable public static String removeAll(@Nullable String sInputString, char cRemoveChar)
sInputString - The input string where the character should be removed. If this
parameter is null or empty, no removing is done.cRemoveChar - The character to be removed.@Nullable public static String removeAll(@Nullable String sInputString, @Nullable String sRemoveString)
sInputString - The input string where the character should be removed. If this
parameter is null or empty, no removing is done.sRemoveString - The String to be removed. May be null or empty in which
case nothing happens.@Nonnegative public static int getLength(@Nullable CharSequence aCS)
aCS - The character sequence who's length is to be determined. May be
null.null, its length otherwise.CharSequence.length()@Nonnull public static String getNotNull(@Nullable String s)
null. If the passed
parameter is null an empty string is returned.s - The parameter to be not null.null, the
passed string otherwise.@Nullable public static String getNotNull(@Nullable String s, String sDefaultIfNull)
null. If the passed
parameter is null the second parameter is returned.s - The parameter to be not null.sDefaultIfNull - The value to be used of the first parameter is null.
May be null but in this case the call to this method is
obsolete.null,
otherwise the input string.@Nonnull public static CharSequence getNotNull(@Nullable CharSequence s)
CharSequence but never return null. If
the passed parameter is null an empty string is returned.s - The parameter to be not null.null, the
passed CharSequence otherwise.@Nullable public static CharSequence getNotNull(@Nullable CharSequence s, CharSequence sDefaultIfNull)
CharSequence but never return null. If
the passed parameter is null the second parameter is returned.s - The parameter to be not null.sDefaultIfNull - The value to be used of the first parameter is null.
May be null but in this case the call to this method is
obsolete.null,
otherwise the input CharSequence.@Nullable public static String getNotEmpty(@Nullable String s, @Nullable String sDefaultIfEmpty)
null or empty the second parameter is returned.s - The parameter to be not null nor empty.sDefaultIfEmpty - The value to be used of the first parameter is null or
empty. May be null but in this case the call to this
method is obsolete.null or
empty, otherwise the input string.@Nullable public static CharSequence getNotEmpty(@Nullable CharSequence s, @Nullable CharSequence sDefaultIfEmpty)
null or empty the second parameter is
returned.s - The parameter to be not null nor empty.sDefaultIfEmpty - The value to be used of the first parameter is null or
empty. May be null but in this case the call to this
method is obsolete.null
or empty, otherwise the input char sequence.@Nonnull public static String getToString(@Nullable Object aObject)
Object.toString()
method.aObject - The value to be converted. May be null.null.
Never null.Object.toString()@Nullable public static String getToString(@Nullable Object aObject, @Nullable String sNullValue)
Object.toString()
method or otherwise return the passed default value.aObject - The value to be converted. May be null.sNullValue - The value to be returned in case the passed object is
null. May be null itself.null or the result of Object.toString() on the
passed object.Object.toString()@Nonnull public static String getWithoutLeadingChar(@Nullable String sStr)
sStr - The source string. May be null.null string if the passed string has a
length ≤ 1.@Nonnull public static String getWithoutLeadingChars(@Nullable String sStr, @Nonnegative int nCount)
sStr - The source string. May be null.nCount - The number of chars to remove.null string if the passed string has a
length ≤ nCount.@Nonnull public static String getWithoutTrailingChar(@Nullable String sStr)
sStr - The source string. May be null.null string if the passed string has a
length ≤ 1.@Nonnull public static String getWithoutTrailingChars(@Nullable String sStr, @Nonnegative int nCount)
sStr - The source string. May be null.nCount - The number of chars to remove.null string if the passed string has a
length ≤ nCount.@Nonnull public static String getWithoutAnySpaces(@Nullable String sStr)
sStr - The source string. May be nullnull string representing the passed string
without any spaces@Nullable public static String getUntilFirstIncl(@Nullable String sStr, char cSearch)
sStr - The source string. May be null.cSearch - The character to search.null if the passed string does not contain the search
character.@Nullable public static String getUntilFirstExcl(@Nullable String sStr, char cSearch)
sStr - The source string. May be null.cSearch - The character to search.null if the passed string does not contain the search
character.@Nullable public static String getUntilFirstIncl(@Nullable String sStr, @Nullable String sSearch)
sStr - The source string. May be null.sSearch - The string to search. May be null.null if the passed string does not contain the search
string. If the search string is empty, the empty string is
returned.@Nullable public static String getUntilFirstExcl(@Nullable String sStr, @Nullable String sSearch)
sStr - The source string. May be null.sSearch - The string to search. May be null.null if the passed string does not contain the search
string. If the search string is empty, the empty string is
returned.@Nullable public static String getUntilLastIncl(@Nullable String sStr, char cSearch)
sStr - The source string. May be null.cSearch - The character to search.null if the passed string does not contain the search
character.@Nullable public static String getUntilLastExcl(@Nullable String sStr, char cSearch)
sStr - The source string. May be null.cSearch - The character to search.null if the passed string does not contain the search
character.@Nullable public static String getUntilLastIncl(@Nullable String sStr, @Nullable String sSearch)
sStr - The source string. May be null.sSearch - The string to search. May be null.null if the passed string does not contain the search
string. If the search string is empty, the empty string is
returned.@Nullable public static String getUntilLastExcl(@Nullable String sStr, @Nullable String sSearch)
sStr - The source string. May be null.sSearch - The string to search. May be null.null if the passed string does not contain the search
string. If the search string is empty, the empty string is
returned.@Nullable public static String getFromFirstIncl(@Nullable String sStr, char cSearch)
sStr - The source string. May be null.cSearch - The character to search.null if the passed string does not contain the search
character.@Nullable public static String getFromFirstExcl(@Nullable String sStr, char cSearch)
sStr - The source string. May be null.cSearch - The character to search.null if the passed string does not contain the search
character.@Nullable public static String getFromFirstIncl(@Nullable String sStr, @Nullable String sSearch)
sStr - The source string. May be null.sSearch - The string to search. May be null.null if the passed string does not contain the search
string. If the search string is empty, the input string is returned
unmodified.@Nullable public static String getFromFirstExcl(@Nullable String sStr, @Nullable String sSearch)
sStr - The source string. May be null.sSearch - The string to search. May be null.null if the passed string does not contain the search
string. If the search string is empty, the input string is returned
unmodified.@Nullable public static String getFromLastIncl(@Nullable String sStr, char cSearch)
sStr - The source string. May be null.cSearch - The character to search.null if the passed string does not contain the search
character.@Nullable public static String getFromLastExcl(@Nullable String sStr, char cSearch)
sStr - The source string. May be null.cSearch - The character to search.null if the passed string does not contain the search
character.@Nullable public static String getFromLastIncl(@Nullable String sStr, @Nullable String sSearch)
sStr - The source string. May be null.sSearch - The string to search. May be null.null if the passed string does not contain the search
string. If the search string is empty, the input string is returned
unmodified.@Nullable public static String getFromLastExcl(@Nullable String sStr, @Nullable String sSearch)
sStr - The source string. May be null.sSearch - The string to search. May be null.null if the passed string does not contain the search
string. If the search string is empty, the input string is returned
unmodified.@Nullable public static String getFirstToken(@Nullable String sStr, char cSearch)
sStr - The string to search. May be null.cSearch - The search character.@Nullable public static String getFirstToken(@Nullable String sStr, @Nullable String sSearch)
sStr - The string to search. May be null.sSearch - The search string. May be null.@Nullable public static String getLastToken(@Nullable String sStr, char cSearch)
sStr - The string to search. May be null.cSearch - The search character.@Nullable public static String getLastToken(@Nullable String sStr, @Nullable String sSearch)
sStr - The string to search. May be null.sSearch - The search string. May be null.@Nonnull public static String removeMultiple(@Nullable String sInputString, @Nonnull char[] aRemoveChars)
sInputString - The input string.aRemoveChars - The characters to remove. May not be null.null.public static void iterateChars(@Nullable String sInputString, @Nonnull ICharConsumer aConsumer)
sInputString - Input String to use. May be null or empty.aConsumer - The consumer to be used. May not be null.public static void iterateCodePoints(@Nullable String sInputString, @Nonnull IntConsumer aConsumer)
CharSequence.codePoints().forEachOrdered(c)sInputString - Input String to use. May be null or empty.aConsumer - The consumer to be used. May not be null.@Nonnull @ReturnsMutableCopy public static byte[] encodeCharToBytes(@Nonnull char[] aCharArray, @Nonnull Charset aCharset)
new String (aCharArray).getBytes (aCharset) just
without the intermediate objects.aCharset - Charset to be used. May not be null.aCharArray - The char array to be encoded. May not be null.null.@Nonnull @ReturnsMutableCopy public static byte[] encodeCharToBytes(@Nonnull char[] aCharArray, @Nonnegative int nOfs, @Nonnegative int nLen, @Nonnull Charset aCharset)
new String (aCharArray).getBytes (aCharset) just
without the intermediate objects.aCharset - Charset to be used. May not be null.aCharArray - The char array to be encoded. May not be null.nOfs - Offset into char array. Must be ≥ 0.nLen - Chars to encode. Must be ≥ 0.null.@Nonnull public static char[] decodeBytesToChars(@Nonnull byte[] aByteArray, @Nonnull Charset aCharset)
new String (aByteArray, aCharset) just without the
intermediate objects.aByteArray - The byte array to be decoded. May not be null.aCharset - Charset to be used. May not be null.null.@Nonnull public static char[] decodeBytesToChars(@Nonnull byte[] aByteArray, @Nonnegative int nOfs, @Nonnegative int nLen, @Nonnull Charset aCharset)
new String (aByteArray, aCharset) just without the
intermediate objects.aByteArray - The byte array to be decoded. May not be null.nOfs - Offset into byte array. Must be ≥ 0.nLen - Bytes to encode. Must be ≥ 0.aCharset - Charset to be used. May not be null.null.Copyright © 2014–2020 Philip Helger. All rights reserved.