Package com.helger.base.string
Class StringHelper
java.lang.Object
com.helger.base.string.StringHelper
Simple string utility methods, originally in StringHelper.
- Since:
- v12.0.0
- Author:
- Philip Helger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendQuoted(@NonNull Appendable aTarget, @Nullable String sSource) Append the provided string quoted or unquoted if it isnull.static voidappendQuoted(@NonNull StringBuilder aTarget, @Nullable String sSource) Append the provided string quoted or unquoted if it isnull.static booleanCheck if cSearch is contained within sText.static booleanCheck if sSearch is contained within sText.static booleancontainsAny(char @Nullable [] aInput, char @NonNull [] aSearchChars) Check if any of the passed searched characters is contained in the input char array.static booleancontainsAny(@Nullable CharSequence aCS, @Nullable ICharPredicate aFilter) Check if the passedCharSequencecontains any character matching the provided filter.static booleancontainsAny(@Nullable String sInput, char @NonNull [] aSearchChars) Check if any of the passed searched characters in contained in the input string.static booleancontainsAny(@Nullable String sStr, @Nullable ICharPredicate aFilter) Check if the passedStringcontains any character matching the provided filter.static booleancontainsIgnoreCase(@Nullable String sText, char cSearch, @NonNull Locale aSortLocale) Check if cSearch is contained within sText ignoring case.static booleancontainsIgnoreCase(@Nullable String sText, @Nullable String sSearch, @NonNull Locale aSortLocale) Check if sSearch is contained within sText ignoring case.static booleancontainsNone(@Nullable CharSequence aCS, @Nullable ICharPredicate aFilter) Check if the passedCharSequencecontains no character matching the provided filter.static booleancontainsNone(@Nullable String sStr, @Nullable ICharPredicate aFilter) Check if the passedStringcontains no character matching the provided filter.static booleancontainsOnly(@Nullable CharSequence aCS, @Nullable ICharPredicate aFilter) Check if the passedCharSequencecontains only characters matching the provided filter.static booleancontainsOnly(@Nullable String sStr, @Nullable ICharPredicate aFilter) Check if the passedStringcontains only characters matching the provided filter.static booleanendsWith(@Nullable CharSequence aCS, char c) Check if the passed character sequence ends with the passed character.static booleanendsWith(@Nullable CharSequence aCS, @Nullable CharSequence aSearch) Check if the passed character sequence ends with the passed search sequence.static booleanCheck if the passed string ends with the passed search string.static booleanendsWithAny(@Nullable CharSequence aCS, char @Nullable [] aChars) Check if the passed character sequence ends with any of the passed characters.static booleanendsWithIgnoreCase(@Nullable CharSequence aCS, char c) Check if the passed character sequence ends with the passed character, ignoring case.static booleanendsWithIgnoreCase(@Nullable String sStr, @Nullable String sSearch) Check if the passed string ends with the passed search string, ignoring case.static voidexplode(char cSep, @Nullable String sElements, int nMaxItems, @NonNull Consumer<? super String> aConsumer) Split the provided string by the provided separator and invoke the consumer for each matched element.static voidSplit the provided string by the provided separator and invoke the consumer for each matched element.static voidexplode(@NonNull String sSep, @Nullable String sElements, int nMaxItems, @NonNull Consumer<? super String> aConsumer) Split the provided string by the provided separator and invoke the consumer for each matched element.static voidexplode(@NonNull String sSep, @Nullable String sElements, @NonNull Consumer<? super String> aConsumer) Split the provided string by the provided separator and invoke the consumer for each matched element.static @NonNull StringgetConcatenatedOnDemand(@Nullable String sFront, char cSep, @Nullable String sEnd) Concatenate the strings sFront and sEnd by the "cSep" separator.static @NonNull StringgetConcatenatedOnDemand(@Nullable String sFront, @Nullable String sEnd) Concatenate the strings sFront and sEnd.static @NonNull StringgetConcatenatedOnDemand(@Nullable String sFront, @Nullable String sSep, @Nullable String sEnd) Concatenate the strings sFront and sEnd by the "sSep" string.static @NonNull StringgetCutAfterLength(@NonNull String sValue, int nMaxLength) Cut the passed string after the specified length.static @NonNull StringgetCutAfterLength(@NonNull String sValue, int nMaxLength, @Nullable String sNewSuffix) Cut the passed string after the specified length, optionally appending a suffix (e.ggetExploded(char cSep, @Nullable String sElements) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.getExploded(char cSep, @Nullable String sElements, int nMaxItems) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.static <COLLTYPE extends Collection<String>>
@NonNull COLLTYPEgetExploded(char cSep, @Nullable String sElements, int nMaxItems, @NonNull COLLTYPE aCollection) Take a concatenated String and return the passed Collection of all elements in the passed string, using specified separator string.getExploded(@NonNull String sSep, @Nullable String sElements) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.getExploded(@NonNull String sSep, @Nullable String sElements, int nMaxItems) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.static <COLLTYPE extends Collection<String>>
@NonNull COLLTYPEgetExploded(@NonNull String sSep, @Nullable String sElements, int nMaxItems, @NonNull COLLTYPE aCollection) Take a concatenated String and return the passed Collection of all elements in the passed string, using specified separator string.static @NonNull String[]getExplodedArray(char cSep, @Nullable String sElements) Take a concatenated String and return the passed String array of all elements in the passed string, using specified separator char.static @NonNull String[]getExplodedArray(char cSep, @Nullable 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 @NonNull LinkedHashSet<String> getExplodedToOrderedSet(@NonNull String sSep, @Nullable String sElements) Take a concatenated String and return an orderedLinkedHashSetof all elements in the passed string, using specified separator string.getExplodedToSet(@NonNull String sSep, @Nullable String sElements) Take a concatenated String and return aSetof all elements in the passed string, using specified separator string.getExplodedToSortedSet(@NonNull String sSep, @Nullable String sElements) Take a concatenated String and return a sortedTreeSetof all elements in the passed string, using specified separator string.static chargetFirstChar(char @Nullable [] aChars) Get the first character of the passed arraystatic chargetFirstChar(@Nullable CharSequence aCS) Get the first character of the passed character sequencestatic @Nullable StringgetFirstToken(@Nullable String sStr, char cSearch) Get the first token up to (and excluding) the separating character.static @Nullable StringgetFirstToken(@Nullable String sStr, @Nullable String sSearch) Get the first token up to (and excluding) the separating string.static @Nullable StringgetFromFirstExcl(@Nullable String sStr, char cSearch) Get everything from the string from and excluding the first passed char.static @Nullable StringgetFromFirstExcl(@Nullable String sStr, @Nullable String sSearch) Get everything from the string from and excluding the passed string.static @Nullable StringgetFromFirstIncl(@Nullable String sStr, char cSearch) Get everything from the string from and including the first passed char.static @Nullable StringgetFromFirstIncl(@Nullable String sStr, @Nullable String sSearch) Get everything from the string from and including the passed string.static @Nullable StringgetFromLastExcl(@Nullable String sStr, char cSearch) Get everything from the string from and excluding the first passed char.static @Nullable StringgetFromLastExcl(@Nullable String sStr, @Nullable String sSearch) Get everything from the string from and excluding the passed string.static @Nullable StringgetFromLastIncl(@Nullable String sStr, char cSearch) Get everything from the string from and including the first passed char.static @Nullable StringgetFromLastIncl(@Nullable String sStr, @Nullable String sSearch) Get everything from the string from and including the passed string.static intgetIndexOf(@Nullable String sText, char cSearch) Get the first index of cSearch within sText.static intgetIndexOf(@Nullable String sText, int nFromIndex, char cSearch) Get the first index of cSearch within sText starting at index nFromIndex.static intgetIndexOf(@Nullable String sText, int nFromIndex, @Nullable String sSearch) Get the first index of sSearch within sText starting at index nFromIndex.static intgetIndexOf(@Nullable String sText, @Nullable String sSearch) Get the first index of sSearch within sText.static intgetIndexOfIgnoreCase(@Nullable String sText, char cSearch, @NonNull Locale aSortLocale) Get the first index of cSearch within sText ignoring case.static intgetIndexOfIgnoreCase(@Nullable String sText, int nFromIndex, char cSearch, @NonNull Locale aSortLocale) Get the first index of cSearch within sText ignoring case starting at index nFromIndex.static intgetIndexOfIgnoreCase(@Nullable String sText, int nFromIndex, @Nullable String sSearch, @NonNull Locale aSortLocale) Get the first index of sSearch within sText ignoring case starting at index nFromIndex.static intgetIndexOfIgnoreCase(@Nullable String sText, @Nullable String sSearch, @NonNull Locale aSortLocale) Get the first index of sSearch within sText ignoring case.static chargetLastChar(char @Nullable [] aChars) Get the last character of the passed arraystatic chargetLastChar(@Nullable CharSequence aCS) Get the last character of the passed character sequencestatic intgetLastIndexOf(@Nullable String sText, char cSearch) Get the last index of cSearch within sText.static intgetLastIndexOf(@Nullable String sText, int nFromIndex, char cSearch) Get the last index of cSearch within sText starting at index nFromIndex.static intgetLastIndexOf(@Nullable String sText, int nFromIndex, @Nullable String sSearch) Get the last index of sSearch within sText starting at index nFromIndex.static intgetLastIndexOf(@Nullable String sText, @Nullable String sSearch) Get the last index of sSearch within sText.static intgetLastIndexOfIgnoreCase(@Nullable String sText, char cSearch, @NonNull Locale aSortLocale) Get the last index of cSearch within sText ignoring case.static intgetLastIndexOfIgnoreCase(@Nullable String sText, int nFromIndex, char cSearch, @NonNull Locale aSortLocale) Get the last index of cSearch within sText ignoring case starting at index nFromIndex.static intgetLastIndexOfIgnoreCase(@Nullable String sText, int nFromIndex, @Nullable String sSearch, @NonNull Locale aSortLocale) Get the last index of sSearch within sText ignoring case starting at index nFromIndex.static intgetLastIndexOfIgnoreCase(@Nullable String sText, @Nullable String sSearch, @NonNull Locale aSortLocale) Get the last index of sSearch within sText ignoring case.static @Nullable StringgetLastToken(@Nullable String sStr, char cSearch) Get the last token from (and excluding) the separating character.static @Nullable StringgetLastToken(@Nullable String sStr, @Nullable String sSearch) Get the last token from (and excluding) the separating string.static @NonNull StringgetLeadingZero(int nValue, int nChars) Get a string representation of the passedintvalue with leading zeros.static @NonNull StringgetLeadingZero(long nValue, int nChars) Get a string representation of the passedlongvalue with leading zeros.static @NonNull StringgetLeadingZero(@NonNull String sValue, int nChars) Get the passed string padded with leading zeros until the minimum number of characters is reached.static @Nullable StringgetLeadingZero(@Nullable Byte aValue, int nChars) Get a string representation of the passedBytevalue with leading zeros.static @Nullable StringgetLeadingZero(@Nullable Integer aValue, int nChars) Get a string representation of the passedIntegervalue with leading zeros.static @Nullable StringgetLeadingZero(@Nullable Long aValue, int nChars) Get a string representation of the passedLongvalue with leading zeros.static @Nullable StringgetLeadingZero(@Nullable Short aValue, int nChars) Get a string representation of the passedShortvalue with leading zeros.static intgetLength(@Nullable CharSequence aCS) Get the length of the passed character sequence.static @Nullable CharSequencegetNotEmpty(@Nullable CharSequence s, @Nullable CharSequence sDefaultIfEmpty) Get the passed char sequence but never return an empty char sequence.static @Nullable CharSequencegetNotEmpty(@Nullable CharSequence s, @Nullable Supplier<? extends CharSequence> aDefaultIfEmpty) Get the passed char sequence but never return an empty char sequence.static @Nullable StringgetNotEmpty(@Nullable String s, @Nullable String sDefaultIfEmpty) Get the passed string but never return an empty string.static @Nullable StringgetNotEmpty(@Nullable String s, @NonNull Supplier<String> aDefaultIfEmpty) Get the passed string but never return an empty string.static @NonNull CharSequencegetNotNull(@Nullable CharSequence s) Get the passedCharSequencebut never returnnull.static @Nullable CharSequencegetNotNull(@Nullable CharSequence s, @Nullable CharSequence sDefaultIfNull) Get the passedCharSequencebut never returnnull.static @Nullable CharSequencegetNotNull(@Nullable CharSequence s, @NonNull Supplier<? extends CharSequence> aDefaultIfNull) Get the passedCharSequencebut never returnnull.static @NonNull StringgetNotNull(@Nullable String s) Get the passed string but never returnnull.static @Nullable StringgetNotNull(@Nullable String s, @Nullable String sDefaultIfNull) Get the passed string but never returnnull.static @Nullable StringgetNotNull(@Nullable String s, @NonNull Supplier<String> aDefaultIfNull) Get the passed string but never returnnull.static @NonNull StringGet the provided string quoted or unquoted if it isnull.static @NonNull StringgetRepeated(char cElement, int nRepeats) Get the passed string element repeated for a certain number of times.static @NonNull StringgetRepeated(@NonNull String sElement, int nRepeats) Get the passed string element repeated for a certain number of times.static @Nullable StringgetReverse(@Nullable String sStr) Get the reversed version of the passed string.static @NonNull StringgetToString(@Nullable Object aObject) Convert the passed object to a string using theObject.toString()method.static @Nullable StringgetToString(@Nullable Object aObject, @Nullable String sNullValue) Convert the passed object to a string using theObject.toString()method or otherwise return the passed default value.static @Nullable StringgetUntilFirstExcl(@Nullable String sStr, char cSearch) Get everything from the string up to and excluding first the passed char.static @Nullable StringgetUntilFirstExcl(@Nullable String sStr, @Nullable String sSearch) Get everything from the string up to and excluding the first passed string.static @Nullable StringgetUntilFirstIncl(@Nullable String sStr, char cSearch) Get everything from the string up to and including the first passed char.static @Nullable StringgetUntilFirstIncl(@Nullable String sStr, @Nullable String sSearch) Get everything from the string up to and including the first passed string.static @Nullable StringgetUntilLastExcl(@Nullable String sStr, char cSearch) Get everything from the string up to and excluding first the passed char.static @Nullable StringgetUntilLastExcl(@Nullable String sStr, @Nullable String sSearch) Get everything from the string up to and excluding the first passed string.static @Nullable StringgetUntilLastIncl(@Nullable String sStr, char cSearch) Get everything from the string up to and including the first passed char.static @Nullable StringgetUntilLastIncl(@Nullable String sStr, @Nullable String sSearch) Get everything from the string up to and including the first passed string.static @NonNull StringgetWithLeading(int nValue, int nMinLen, char cFront) Get a string that is filled at the beginning with the passed character until the minimum length is reached.static @NonNull StringgetWithLeading(long nValue, int nMinLen, char cFront) Get a string that is filled at the beginning with the passed character until the minimum length is reached.static @NonNull StringgetWithLeading(@Nullable 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 @NonNull StringgetWithoutAnySpaces(@Nullable String sStr) Get the passed string where all spaces (white spaces or unicode spaces) have been removed.static @NonNull StringgetWithoutLeadingChar(@Nullable String sStr) Get the passed string without the first char.static @NonNull StringgetWithoutLeadingChars(@Nullable String sStr, int nCount) Get the passed string without the specified number of leading chars.static @NonNull StringgetWithoutTrailingChar(@Nullable String sStr) Get the passed string without the last char.static @NonNull StringgetWithoutTrailingChars(@Nullable String sStr, int nCount) Get the passed string without the specified number of trailing chars.static @NonNull StringgetWithTrailing(@Nullable String sSrc, int nMinLen, char cEnd) Get a string that is filled at the end with the passed character until the minimum length is reached.static booleanhasNoText(@Nullable CharSequence aCS) Deprecated, for removal: This API element is subject to removal in a future version.static booleanDeprecated, for removal: This API element is subject to removal in a future version.UseisEmpty(String)insteadstatic booleanhasText(@Nullable CharSequence aCS) Deprecated, for removal: This API element is subject to removal in a future version.UseisNotEmpty(CharSequence)insteadstatic booleanDeprecated, for removal: This API element is subject to removal in a future version.UseisNotEmpty(String)insteadstatic booleanhasTextAfterTrim(@Nullable String s) Deprecated, for removal: This API element is subject to removal in a future version.UseisNotEmptyAfterTrim(String)insteadstatic booleanisAllWhitespace(@Nullable CharSequence s) Check if the passed character sequence is only whitespace or not.static booleanisEmpty(@Nullable CharSequence aCS) Check if the string isnullor empty.static booleanCheck if the string isnullor empty.static booleanisEmptyAfterTrim(@Nullable String s) Check if the string isnullor empty after trimming.static booleanisNotEmpty(@Nullable CharSequence aCS) Check if the string contains any char.static booleanisNotEmpty(@Nullable String sStr) Check if the string contains any char.static booleanisNotEmptyAfterTrim(@Nullable String s) Check if the string neithernullnor empty after trimming.static voiditerateChars(@Nullable String sInputString, @NonNull ICharConsumer aConsumer) Iterate all characters and pass them to the provided consumer.static voiditerateCodePoints(@Nullable String sInputString, @NonNull IntConsumer aConsumer) Iterate all code points and pass them to the provided consumer.static booleanstartsWith(@Nullable CharSequence aCS, char c) Check if the passed character sequence starts with the passed character.static booleanstartsWith(@Nullable CharSequence aCS, @Nullable CharSequence aSearch) Check if the passed character sequence starts with the passed search sequence.static booleanstartsWith(@Nullable String sStr, @Nullable String sSearch) Check if the passed string starts with the passed search string.static booleanstartsWithAny(@Nullable CharSequence aCS, char @Nullable [] aChars) Check if the passed character sequence starts with any of the passed characters.static booleanstartsWithIgnoreCase(@Nullable CharSequence aCS, char c) Check if the passed character sequence starts with the passed character, ignoring case.static booleanstartsWithIgnoreCase(@Nullable String sStr, @Nullable String sSearch) Check if the passed string starts with the passed search string, ignoring case.static @Nullable StringTrim the passed string, if it is notnull.static @Nullable StringTrim the passed tail from the source value.static @Nullable StringTrim the passed tail from the source value.static @Nullable StringTrim the passed tail from the source value.static @Nullable StringtrimEndRepeatedly(@Nullable String sSrc, char cTail) Trim the passed tail character from the source value repeatedly until the source no longer ends with the tail.static @Nullable StringtrimEndRepeatedly(@Nullable String sSrc, @Nullable String sTail) Trim the passed tail from the source value repeatedly until the source no longer ends with the tail.static @Nullable StringtrimLeadingWhitespaces(@Nullable String s) Remove any leading whitespaces from the passed string.static @Nullable StringTrim the passed lead from the source value.static @Nullable StringTrim the passed lead from the source value.static @Nullable StringTrim the passed lead from the source value.static @Nullable StringtrimStartAndEnd(@Nullable String sSrc, char cValueToTrim) Trim the passed lead and tail from the source value.static @Nullable StringtrimStartAndEnd(@Nullable String sSrc, char cLead, char cTail) Trim the passed lead and tail from the source value.static @Nullable StringtrimStartAndEnd(@Nullable String sSrc, @Nullable String sValueToTrim) Trim the passed lead and tail from the source value.static @Nullable StringtrimStartAndEnd(@Nullable String sSrc, @Nullable String sLead, @Nullable String sTail) Trim the passed lead and tail from the source value.static @Nullable StringtrimStartRepeatedly(@Nullable String sSrc, char cLead) Trim the passed lead character from the source value repeatedly until the source no longer starts with the lead.static @Nullable StringtrimStartRepeatedly(@Nullable String sSrc, @Nullable String sLead) Trim the passed lead from the source value repeatedly until the source no longer starts with the lead.static @Nullable StringtrimTrailingWhitespaces(@Nullable String s) Remove any trailing whitespaces from the passed string.
-
Constructor Details
-
StringHelper
protected StringHelper()
-
-
Method Details
-
isEmpty
Check if the string isnullor empty.- Parameters:
aCS- The character sequence to check. May benull.- Returns:
trueif the string isnullor empty,falseotherwise- Since:
- 10.1.8
-
isEmpty
Check if the string isnullor empty.- Parameters:
sStr- The string to check. May benull.- Returns:
trueif the string isnullor empty,falseotherwise- Since:
- 10.1.8
-
isEmptyAfterTrim
Check if the string isnullor empty after trimming.- Parameters:
s- The string to check. May benull.- Returns:
trueif the string isnullor empty or consists only of whitespaces,falseotherwise- Since:
- 10.1.8
-
isNotEmpty
Check if the string contains any char.- Parameters:
aCS- The character sequence to check. May benull.- Returns:
trueif the string contains at least one,falseotherwise- Since:
- 10.1.8
-
isNotEmpty
Check if the string contains any char.- Parameters:
sStr- The string to check. May benull.- Returns:
trueif the string contains at least one char,falseotherwise- Since:
- 10.1.8
-
isNotEmptyAfterTrim
Check if the string neithernullnor empty after trimming.- Parameters:
s- The string to check. May benull.- Returns:
trueif the string is neithernullnor empty nor consists only of whitespaces,falseotherwise- Since:
- 10.1.8
-
hasNoText
@Deprecated(forRemoval=true, since="12.0.0") public static boolean hasNoText(@Nullable CharSequence aCS) Deprecated, for removal: This API element is subject to removal in a future version.UseisEmpty(CharSequence)insteadCheck if the string isnullor empty.- Parameters:
aCS- The character sequence to check. May benull.- Returns:
trueif the string isnullor empty,falseotherwise
-
hasNoText
Deprecated, for removal: This API element is subject to removal in a future version.UseisEmpty(String)insteadCheck if the string isnullor empty.- Parameters:
sStr- The string to check. May benull.- Returns:
trueif the string isnullor empty,falseotherwise
-
hasText
@Deprecated(forRemoval=true, since="12.0.0") public static boolean hasText(@Nullable CharSequence aCS) Deprecated, for removal: This API element is subject to removal in a future version.UseisNotEmpty(CharSequence)insteadCheck if the string contains any char.- Parameters:
aCS- The character sequence to check. May benull.- Returns:
trueif the string contains at least one,falseotherwise
-
hasText
Deprecated, for removal: This API element is subject to removal in a future version.UseisNotEmpty(String)insteadCheck if the string contains any char.- Parameters:
sStr- The string to check. May benull.- Returns:
trueif the string contains at least one char,falseotherwise
-
hasTextAfterTrim
@Deprecated(forRemoval=true, since="12.0.0") public static boolean hasTextAfterTrim(@Nullable String s) Deprecated, for removal: This API element is subject to removal in a future version.UseisNotEmptyAfterTrim(String)insteadCheck if the string neithernullnor empty after trimming.- Parameters:
s- The string to check. May benull.- Returns:
trueif the string is neithernullnor empty nor consists only of whitespaces,falseotherwise
-
getLength
Get the length of the passed character sequence.- Parameters:
aCS- The character sequence who's length is to be determined. May benull.- Returns:
- 0 if the parameter is
null, its length otherwise. - See Also:
-
getNotNull
Get the passed string but never returnnull. If the passed parameter isnullan empty string is returned.- Parameters:
s- The parameter to be notnull.- Returns:
- An empty string if the passed parameter is
null, the passed string otherwise.
-
getNotNull
Get the passed string but never returnnull. If the passed parameter isnullthe second parameter is returned.- Parameters:
s- The parameter to be notnull.sDefaultIfNull- The value to be used if the first parameter isnull. May benullbut in this case the call to this method is obsolete.- Returns:
- The passed default value if the string is
null, otherwise the input string.
-
getNotNull
public static @Nullable String getNotNull(@Nullable String s, @NonNull Supplier<String> aDefaultIfNull) Get the passed string but never returnnull. If the passed parameter isnullthe second parameter is returned.- Parameters:
s- The parameter to be notnull.aDefaultIfNull- The value supplier to be used if the first parameter isnull. May not benull.- Returns:
- The passed default value if the string is
null, otherwise the input string. - Since:
- 10.2.0
-
getNotNull
Get the passedCharSequencebut never returnnull. If the passed parameter isnullan empty string is returned.- Parameters:
s- The parameter to be notnull.- Returns:
- An empty string if the passed parameter is
null, the passedCharSequenceotherwise.
-
getNotNull
public static @Nullable CharSequence getNotNull(@Nullable CharSequence s, @Nullable CharSequence sDefaultIfNull) Get the passedCharSequencebut never returnnull. If the passed parameter isnullthe second parameter is returned.- Parameters:
s- The parameter to be notnull.sDefaultIfNull- The value to be used if the first parameter isnull. May benullbut in this case the call to this method is obsolete.- Returns:
- The passed default value if the string is
null, otherwise the inputCharSequence.
-
getNotNull
public static @Nullable CharSequence getNotNull(@Nullable CharSequence s, @NonNull Supplier<? extends CharSequence> aDefaultIfNull) Get the passedCharSequencebut never returnnull. If the passed parameter isnullthe second parameter is returned.- Parameters:
s- The parameter to be notnull.aDefaultIfNull- The value supplier to be used if the first parameter isnull. May not benull.- Returns:
- The passed default value if the string is
null, otherwise the inputCharSequence. - Since:
- 10.2.0
-
getNotEmpty
Get the passed string but never return an empty string. If the passed parameter isnullor empty the second parameter is returned.- Parameters:
s- The parameter to be notnullnor empty.sDefaultIfEmpty- The value to be used if the first parameter isnullor empty. May benullbut in this case the call to this method is obsolete.- Returns:
- The passed default value if the string is
nullor empty, otherwise the input string.
-
getNotEmpty
public static @Nullable String getNotEmpty(@Nullable String s, @NonNull Supplier<String> aDefaultIfEmpty) Get the passed string but never return an empty string. If the passed parameter isnullor empty the second parameter is returned.- Parameters:
s- The parameter to be notnullnor empty.aDefaultIfEmpty- The value supplier to be used if the first parameter isnullor empty. May not benull.- Returns:
- The passed default value if the string is
nullor empty, otherwise the input string. - Since:
- 10.2.0
-
getNotEmpty
public static @Nullable CharSequence getNotEmpty(@Nullable CharSequence s, @Nullable CharSequence sDefaultIfEmpty) Get the passed char sequence but never return an empty char sequence. If the passed parameter isnullor empty the second parameter is returned.- Parameters:
s- The parameter to be notnullnor empty.sDefaultIfEmpty- The value to be used if the first parameter isnullor empty. May benullbut in this case the call to this method is obsolete.- Returns:
- The passed default value if the char sequence is
nullor empty, otherwise the input char sequence.
-
getNotEmpty
public static @Nullable CharSequence getNotEmpty(@Nullable CharSequence s, @Nullable Supplier<? extends CharSequence> aDefaultIfEmpty) Get the passed char sequence but never return an empty char sequence. If the passed parameter isnullor empty the second parameter is returned.- Parameters:
s- The parameter to be notnullnor empty.aDefaultIfEmpty- The value supplier to be used if the first parameter isnullor empty. May not benull.- Returns:
- The passed default value if the char sequence is
nullor empty, otherwise the input char sequence. - Since:
- 10.2.0
-
getRepeated
Get the passed string element repeated for a certain number of times. Each string element is simply appended at the end of the string.- Parameters:
cElement- The character to get repeated.nRepeats- The number of repetitions to retrieve. May not be < 0.- Returns:
- A non-
nullstring containing the string element for the given number of times.
-
getRepeated
Get the passed string element repeated for a certain number of times. Each string element is simply appended at the end of the string.- Parameters:
sElement- The string to get repeated. May not benull.nRepeats- The number of repetitions to retrieve. May not be < 0.- Returns:
- A non-
nullstring containing the string element for the given number of times.
-
getWithLeading
public static @NonNull String getWithLeading(@Nullable String sSrc, @Nonnegative int nMinLen, char cFront) Get a string that is filled at the beginning with the passed character until the minimum length is reached. If the input string is empty, the result is a string with the provided len only consisting of the passed characters. If the input String is longer than the provided length, it is returned unchanged.- Parameters:
sSrc- Source string. May benull.nMinLen- Minimum length. Should be > 0.cFront- The character to be used at the beginning- Returns:
- A non-
nullstring that has at least nLen chars
-
getWithLeading
Get a string that is filled at the beginning with the passed character until the minimum length is reached. If the input String is longer than the provided length, it is returned unchanged.- Parameters:
nValue- Source string. May benull.nMinLen- Minimum length. Should be > 0.cFront- The character to be used at the beginning- Returns:
- A non-
nullstring that has at least nLen chars - See Also:
-
getWithLeading
Get a string that is filled at the beginning with the passed character until the minimum length is reached. If the input String is longer than the provided length, it is returned unchanged.- Parameters:
nValue- Source string. May benull.nMinLen- Minimum length. Should be > 0.cFront- The character to be used at the beginning- Returns:
- A non-
nullstring that has at least nLen chars - See Also:
-
getWithTrailing
public static @NonNull String getWithTrailing(@Nullable String sSrc, @Nonnegative int nMinLen, char cEnd) Get a string that is filled at the end with the passed character until the minimum length is reached. If the input string is empty, the result is a string with the provided len only consisting of the passed characters. If the input String is longer than the provided length, it is returned unchanged.- Parameters:
sSrc- Source string. May benull.nMinLen- Minimum length. Should be > 0.cEnd- The character to be used at the end- Returns:
- A non-
nullstring that has at least nLen chars
-
getLeadingZero
Get a string representation of the passedBytevalue with leading zeros.- Parameters:
aValue- The value to be formatted. May benull.nChars- The minimum number of characters to return.- Returns:
nullif the passed value isnull, the formatted string otherwise.
-
getLeadingZero
Get a string representation of the passedIntegervalue with leading zeros.- Parameters:
aValue- The value to be formatted. May benull.nChars- The minimum number of characters to return.- Returns:
nullif the passed value isnull, the formatted string otherwise.
-
getLeadingZero
Get a string representation of the passedLongvalue with leading zeros.- Parameters:
aValue- The value to be formatted. May benull.nChars- The minimum number of characters to return.- Returns:
nullif the passed value isnull, the formatted string otherwise.
-
getLeadingZero
Get a string representation of the passedShortvalue with leading zeros.- Parameters:
aValue- The value to be formatted. May benull.nChars- The minimum number of characters to return.- Returns:
nullif the passed value isnull, the formatted string otherwise.
-
getLeadingZero
Get a string representation of the passedintvalue with leading zeros. Negative values are prefixed with a minus sign.- Parameters:
nValue- The value to be formatted.nChars- The minimum number of characters to return (excluding the minus sign for negative values).- Returns:
- A non-
nullstring with at leastnCharscharacters.
-
getLeadingZero
Get a string representation of the passedlongvalue with leading zeros. Negative values are prefixed with a minus sign.- Parameters:
nValue- The value to be formatted.nChars- The minimum number of characters to return (excluding the minus sign for negative values).- Returns:
- A non-
nullstring with at leastnCharscharacters.
-
getLeadingZero
Get the passed string padded with leading zeros until the minimum number of characters is reached.- Parameters:
sValue- The value to be padded. May not benull.nChars- The minimum number of characters to return.- Returns:
- A non-
nullstring with at leastnCharscharacters. - See Also:
-
getReverse
Get the reversed version of the passed string.- Parameters:
sStr- The source string. May benull.- Returns:
nullif the input string isnull, the reversed string otherwise.
-
getFirstChar
Get the first character of the passed character sequence- Parameters:
aCS- The source character sequence- Returns:
CGlobal.ILLEGAL_CHARif the passed sequence was empty
-
getFirstChar
public static char getFirstChar(char @Nullable [] aChars) Get the first character of the passed array- Parameters:
aChars- The character array- Returns:
CGlobal.ILLEGAL_CHARif the passed array was empty
-
getLastChar
Get the last character of the passed character sequence- Parameters:
aCS- The source character sequence- Returns:
CGlobal.ILLEGAL_CHARif the passed sequence was empty
-
getLastChar
public static char getLastChar(char @Nullable [] aChars) Get the last character of the passed array- Parameters:
aChars- The character array- Returns:
CGlobal.ILLEGAL_CHARif the passed array was empty
-
getIndexOf
Get the first index of sSearch within sText.- Parameters:
sText- The text to search in. May benull.sSearch- The text to search for. May benull.- Returns:
- The first index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getIndexOf
public static int getIndexOf(@Nullable String sText, @Nonnegative int nFromIndex, @Nullable String sSearch) Get the first index of sSearch within sText starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringsSearch- The text to search for. May benull.- Returns:
- The first index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOf
Get the last index of sSearch within sText.- Parameters:
sText- The text to search in. May benull.sSearch- The text to search for. May benull.- Returns:
- The last index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOf
public static int getLastIndexOf(@Nullable String sText, @Nonnegative int nFromIndex, @Nullable String sSearch) Get the last index of sSearch within sText starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringsSearch- The text to search for. May benull.- Returns:
- The last index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getIndexOf
Get the first index of cSearch within sText.- Parameters:
sText- The text to search in. May benull.cSearch- The character to search for. May benull.- Returns:
- The first index of sSearch within sText or -1 if cSearch
was not found or if any parameter was
null. - See Also:
-
getIndexOf
Get the first index of cSearch within sText starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringcSearch- The character to search for. May benull.- Returns:
- The first index of sSearch within sText or -1 if cSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOf
Get the last index of cSearch within sText.- Parameters:
sText- The text to search in. May benull.cSearch- The character to search for. May benull.- Returns:
- The last index of sSearch within sText or -1 if cSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOf
Get the last index of cSearch within sText starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringcSearch- The character to search for. May benull.- Returns:
- The last index of sSearch within sText or -1 if cSearch
was not found or if any parameter was
null. - See Also:
-
getIndexOfIgnoreCase
public static int getIndexOfIgnoreCase(@Nullable String sText, @Nullable String sSearch, @NonNull Locale aSortLocale) Get the first index of sSearch within sText ignoring case.- Parameters:
sText- The text to search in. May benull.sSearch- The text to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The first index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getIndexOfIgnoreCase
public static int getIndexOfIgnoreCase(@Nullable String sText, @Nonnegative int nFromIndex, @Nullable String sSearch, @NonNull Locale aSortLocale) Get the first index of sSearch within sText ignoring case starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringsSearch- The text to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The first index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOfIgnoreCase
public static int getLastIndexOfIgnoreCase(@Nullable String sText, @Nullable String sSearch, @NonNull Locale aSortLocale) Get the last index of sSearch within sText ignoring case.- Parameters:
sText- The text to search in. May benull.sSearch- The text to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The last index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOfIgnoreCase
public static int getLastIndexOfIgnoreCase(@Nullable String sText, @Nonnegative int nFromIndex, @Nullable String sSearch, @NonNull Locale aSortLocale) Get the last index of sSearch within sText ignoring case starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringsSearch- The text to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The last index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getIndexOfIgnoreCase
public static int getIndexOfIgnoreCase(@Nullable String sText, char cSearch, @NonNull Locale aSortLocale) Get the first index of cSearch within sText ignoring case.- Parameters:
sText- The text to search in. May benull.cSearch- The char to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The first index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getIndexOfIgnoreCase
public static int getIndexOfIgnoreCase(@Nullable String sText, @Nonnegative int nFromIndex, char cSearch, @NonNull Locale aSortLocale) Get the first index of cSearch within sText ignoring case starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringcSearch- The char to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The first index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOfIgnoreCase
public static int getLastIndexOfIgnoreCase(@Nullable String sText, char cSearch, @NonNull Locale aSortLocale) Get the last index of cSearch within sText ignoring case.- Parameters:
sText- The text to search in. May benull.cSearch- The char to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The last index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
getLastIndexOfIgnoreCase
public static int getLastIndexOfIgnoreCase(@Nullable String sText, @Nonnegative int nFromIndex, char cSearch, @NonNull Locale aSortLocale) Get the last index of cSearch within sText ignoring case starting at index nFromIndex.- Parameters:
sText- The text to search in. May benull.nFromIndex- The index to start searching in the source stringcSearch- The char to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
- The last index of sSearch within sText or -1 if sSearch
was not found or if any parameter was
null. - See Also:
-
contains
Check if sSearch is contained within sText.- Parameters:
sText- The text to search in. May benull.sSearch- The text to search for. May benull.- Returns:
trueif sSearch is contained in sText,falseotherwise.- See Also:
-
contains
Check if cSearch is contained within sText.- Parameters:
sText- The text to search in. May benull.cSearch- The character to search for. May benull.- Returns:
trueif cSearch is contained in sText,falseotherwise.- See Also:
-
containsIgnoreCase
public static boolean containsIgnoreCase(@Nullable String sText, @Nullable String sSearch, @NonNull Locale aSortLocale) Check if sSearch is contained within sText ignoring case.- Parameters:
sText- The text to search in. May benull.sSearch- The text to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
trueif sSearch is contained in sText,falseotherwise.- See Also:
-
containsIgnoreCase
public static boolean containsIgnoreCase(@Nullable String sText, char cSearch, @NonNull Locale aSortLocale) Check if cSearch is contained within sText ignoring case.- Parameters:
sText- The text to search in. May benull.cSearch- The char to search for. May benull.aSortLocale- The locale to be used for case unifying.- Returns:
trueif sSearch is contained in sText,falseotherwise.- See Also:
-
containsAny
public static boolean containsAny(char @Nullable [] aInput, char @NonNull [] aSearchChars) Check if any of the passed searched characters is contained in the input char array.- Parameters:
aInput- The input char array. May benull.aSearchChars- The char array to search. May not benull.- Returns:
trueif at least any of the search char is contained in the input char array,falseotherwise.
-
containsAny
Check if any of the passed searched characters in contained in the input string.- Parameters:
sInput- The input string. May benull.aSearchChars- The char array to search. May not benull.- Returns:
trueif at least any of the search char is contained in the input char array,falseotherwise.
-
iterateChars
Iterate all characters and pass them to the provided consumer.- Parameters:
sInputString- Input String to use. May benullor empty.aConsumer- The consumer to be used. May not benull.
-
containsAny
Check if the passedCharSequencecontains any character matching the provided filter.- Parameters:
aCS- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is not empty.trueif the filter is notnulland at least one character of the string matches the filter.falseotherwise.- Since:
- 9.1.7
-
containsAny
Check if the passedStringcontains any character matching the provided filter.- Parameters:
sStr- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is not empty.trueif the filter is notnulland at least one character of the string matches the filter.falseotherwise.- Since:
- 9.1.7
-
containsNone
Check if the passedCharSequencecontains no character matching the provided filter.- Parameters:
aCS- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is empty.trueif the filter is notnulland no character of the string matches the filter.falseotherwise.- Since:
- 9.1.7
-
containsNone
Check if the passedStringcontains no character matching the provided filter.- Parameters:
sStr- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is empty.trueif the filter is notnulland no character of the string matches the filter.falseotherwise.- Since:
- 9.1.7
-
containsOnly
Check if the passedCharSequencecontains only characters matching the provided filter.- Parameters:
aCS- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is not empty.trueif the filter is notnulland the string has at least one character and all characters of the string match the filter.falseotherwise.- Since:
- 9.1.7
-
containsOnly
Check if the passedStringcontains only characters matching the provided filter.- Parameters:
sStr- String to check. May benull.aFilter- The filter to use. May benull.- Returns:
trueif the filter isnulland the string is not empty.trueif the filter is notnulland the string has at least one character and all characters of the string match the filter.falseotherwise.- Since:
- 9.1.7
-
isAllWhitespace
Check if the passed character sequence is only whitespace or not.- Parameters:
s- The character sequence to be checked. May benull.- Returns:
trueif the passed sequence is empty or if only whitespace characters are contained.- See Also:
-
startsWith
Check if the passed character sequence starts with the passed character.- Parameters:
aCS- The character sequence to check. May benull.c- The character to search for.- Returns:
trueif the character sequence starts with the passed character,falseotherwise.
-
startsWithAny
Check if the passed character sequence starts with any of the passed characters.- Parameters:
aCS- The character sequence to check. May benull.aChars- The characters to search for. May benull.- Returns:
trueif the character sequence starts with any of the passed characters,falseotherwise.
-
startsWithIgnoreCase
Check if the passed character sequence starts with the passed character, ignoring case.- Parameters:
aCS- The character sequence to check. May benull.c- The character to search for.- Returns:
trueif the character sequence starts with the passed character (ignoring case),falseotherwise.
-
startsWith
Check if the passed character sequence starts with the passed search sequence.- Parameters:
aCS- The character sequence to check. May benull.aSearch- The character sequence to search for. May benull.- Returns:
trueif the character sequence starts with the search sequence,falseotherwise.
-
startsWith
Check if the passed string starts with the passed search string.- Parameters:
sStr- The string to check. May benull.sSearch- The string to search for. May benull.- Returns:
trueif the string starts with the search string,falseotherwise.
-
startsWithIgnoreCase
Check if the passed string starts with the passed search string, ignoring case.- Parameters:
sStr- The string to check. May benull.sSearch- The string to search for. May benull.- Returns:
trueif the string starts with the search string (ignoring case),falseotherwise.
-
endsWith
Check if the passed character sequence ends with the passed character.- Parameters:
aCS- The character sequence to check. May benull.c- The character to search for.- Returns:
trueif the character sequence ends with the passed character,falseotherwise.
-
endsWithAny
Check if the passed character sequence ends with any of the passed characters.- Parameters:
aCS- The character sequence to check. May benull.aChars- The characters to search for. May benull.- Returns:
trueif the character sequence ends with any of the passed characters,falseotherwise.
-
endsWith
Check if the passed character sequence ends with the passed search sequence.- Parameters:
aCS- The character sequence to check. May benull.aSearch- The character sequence to search for. May benull.- Returns:
trueif the character sequence ends with the search sequence,falseotherwise.
-
endsWith
Check if the passed string ends with the passed search string.- Parameters:
sStr- The string to check. May benull.sSearch- The string to search for. May benull.- Returns:
trueif the string ends with the search string,falseotherwise.
-
endsWithIgnoreCase
Check if the passed character sequence ends with the passed character, ignoring case.- Parameters:
aCS- The character sequence to check. May benull.c- The character to search for.- Returns:
trueif the character sequence ends with the passed character (ignoring case),falseotherwise.
-
endsWithIgnoreCase
Check if the passed string ends with the passed search string, ignoring case.- Parameters:
sStr- The string to check. May benull.sSearch- The string to search for. May benull.- Returns:
trueif the string ends with the search string (ignoring case),falseotherwise.
-
iterateCodePoints
Iterate all code points and pass them to the provided consumer. This implementation is approximately 20% quicker thanCharSequence.codePoints().forEachOrdered(c)- Parameters:
sInputString- Input String to use. May benullor empty.aConsumer- The consumer to be used. May not benull.
-
explode
public static void explode(char cSep, @Nullable String sElements, @NonNull Consumer<? super String> aConsumer) Split the provided string by the provided separator and invoke the consumer for each matched element. The number of returned items is unlimited.- Parameters:
cSep- The separator to use.sElements- The concatenated String to convert. May benullor empty.aConsumer- The non-nullconsumer that is invoked for each exploded element
-
explode
public static void explode(char cSep, @Nullable String sElements, int nMaxItems, @NonNull Consumer<? super String> aConsumer) Split the provided string by the provided separator and invoke the consumer for each matched element. The maximum number of elements can be specified.- Parameters:
cSep- The separator to use.sElements- The concatenated String to convert. May benullor empty.nMaxItems- The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.aConsumer- The non-nullconsumer that is invoked for each exploded element
-
explode
public static void explode(@NonNull String sSep, @Nullable String sElements, @NonNull Consumer<? super String> aConsumer) Split the provided string by the provided separator and invoke the consumer for each matched element.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.aConsumer- The non-nullconsumer that is invoked for each exploded element
-
explode
public static void explode(@NonNull String sSep, @Nullable String sElements, int nMaxItems, @NonNull Consumer<? super String> aConsumer) Split the provided string by the provided separator and invoke the consumer for each matched element. The maximum number of elements can be specified.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.nMaxItems- The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.aConsumer- The non-nullconsumer that is invoked for each exploded element
-
getExplodedArray
public static @NonNull String[] getExplodedArray(char cSep, @Nullable String sElements, @CheckForSigned int nMaxItems) Take a concatenated String and return the passed String array of all elements in the passed string, using specified separator char.- Parameters:
cSep- The separator to use.sElements- The concatenated String to convert. May benullor empty.nMaxItems- The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.- Returns:
- The passed collection and never
null.
-
getExplodedArray
Take a concatenated String and return the passed String array of all elements in the passed string, using specified separator char.- Parameters:
cSep- The separator to use.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The passed collection and never
null.
-
getExploded
@ReturnsMutableObject("The passed parameter") @CodingStyleguideUnaware public static <COLLTYPE extends Collection<String>> @NonNull COLLTYPE getExploded(char cSep, @Nullable String sElements, int nMaxItems, @NonNull COLLTYPE aCollection) Take a concatenated String and return the passed Collection of all elements in the passed string, using specified separator string.- Type Parameters:
COLLTYPE- The collection type to be passed and returned- Parameters:
cSep- The separator to use.sElements- The concatenated String to convert. May benullor empty.nMaxItems- The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.aCollection- The non-nulltarget collection that should be filled with the exploded elements- Returns:
- The passed collection and never
null.
-
getExploded
@ReturnsMutableCopy public static @NonNull List<String> getExploded(char cSep, @Nullable String sElements) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.- Parameters:
cSep- The separator character to use.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The
Listrepresented by the passed string. Nevernull. If the passed input string isnullor "" an empty list is returned.
-
getExploded
@ReturnsMutableCopy public static @NonNull List<String> getExploded(char cSep, @Nullable String sElements, int nMaxItems) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.- Parameters:
cSep- The separator character to use.sElements- The concatenated String to convert. May benullor empty.nMaxItems- The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.- Returns:
- The
Listrepresented by the passed string. Nevernull. If the passed input string isnullor "" an empty list is returned.
-
getExploded
@CodingStyleguideUnaware public static <COLLTYPE extends Collection<String>> @NonNull COLLTYPE getExploded(@NonNull String sSep, @Nullable String sElements, int nMaxItems, @NonNull COLLTYPE aCollection) Take a concatenated String and return the passed Collection of all elements in the passed string, using specified separator string.- Type Parameters:
COLLTYPE- The collection type to be used and returned- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.nMaxItems- The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.aCollection- The non-nulltarget collection that should be filled with the exploded elements- Returns:
- The passed collection and never
null.
-
getExploded
@ReturnsMutableCopy public static @NonNull List<String> getExploded(@NonNull String sSep, @Nullable String sElements) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The
Listrepresented by the passed string. Nevernull. If the passed input string isnullor "" an empty list is returned.
-
getExploded
@ReturnsMutableCopy public static @NonNull List<String> getExploded(@NonNull String sSep, @Nullable String sElements, int nMaxItems) Take a concatenated String and return aListof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.nMaxItems- The maximum number of items to explode. If the passed value is ≤ 0 all items are used. If max items is 1, than the result string is returned as is. If max items is larger than the number of elements found, it has no effect.- Returns:
- The
Listrepresented by the passed string. Nevernull. If the passed input string isnullor "" an empty list is returned.
-
getExplodedToSet
@ReturnsMutableCopy public static @NonNull HashSet<String> getExplodedToSet(@NonNull String sSep, @Nullable String sElements) Take a concatenated String and return aSetof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The
Setrepresented by the passed string. Nevernull. If the passed input string isnullor "" an empty list is returned.
-
getExplodedToOrderedSet
@ReturnsMutableCopy public static @NonNull LinkedHashSet<String> getExplodedToOrderedSet(@NonNull String sSep, @Nullable String sElements) Take a concatenated String and return an orderedLinkedHashSetof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The ordered
Setrepresented by the passed string. Nevernull. If the passed input string isnullor "" an empty list is returned.
-
getExplodedToSortedSet
@ReturnsMutableCopy public static @NonNull TreeSet<String> getExplodedToSortedSet(@NonNull String sSep, @Nullable String sElements) Take a concatenated String and return a sortedTreeSetof all elements in the passed string, using specified separator string.- Parameters:
sSep- The separator to use. May not benull.sElements- The concatenated String to convert. May benullor empty.- Returns:
- The sorted
Setrepresented by the passed string. Nevernull. If the passed input string isnullor "" an empty list is returned.
-
getConcatenatedOnDemand
public static @NonNull String getConcatenatedOnDemand(@Nullable String sFront, @Nullable String sEnd) Concatenate the strings sFront and sEnd. If either front or back isnullor empty only the other element is returned. If both strings arenullor empty and empty String is returned.- Parameters:
sFront- Front string. May benull.sEnd- May benull.- Returns:
- The concatenated string. Never
null.
-
getConcatenatedOnDemand
public static @NonNull String getConcatenatedOnDemand(@Nullable String sFront, @Nullable String sSep, @Nullable String sEnd) Concatenate the strings sFront and sEnd by the "sSep" string. If either front or back isnullor empty, the separator is not applied.- Parameters:
sFront- Front string. May benull.sSep- Separator string. May benull.sEnd- May benull.- Returns:
- The concatenated string.
-
getConcatenatedOnDemand
public static @NonNull String getConcatenatedOnDemand(@Nullable String sFront, char cSep, @Nullable String sEnd) Concatenate the strings sFront and sEnd by the "cSep" separator. If either front or back isnullor empty, the separator is not applied.- Parameters:
sFront- Front string. May benull.cSep- Separator character.sEnd- May benull.- Returns:
- The concatenated string.
-
getQuoted
Get the provided string quoted or unquoted if it isnull.- Parameters:
sSource- Source string. May benull.- Returns:
- The String
"null"if the source isnull,"'" + sSource + "'"otherwise. - Since:
- 9.2.0
-
appendQuoted
Append the provided string quoted or unquoted if it isnull.- Parameters:
aTarget- The target to write to. May not benull.sSource- Source string. May benull.- Since:
- 9.2.0
- See Also:
-
appendQuoted
public static void appendQuoted(@NonNull Appendable aTarget, @Nullable String sSource) throws IOException Append the provided string quoted or unquoted if it isnull.- Parameters:
aTarget- The target to write to. May not benull.sSource- Source string. May benull.- Throws:
IOException- in case of IO error- Since:
- 9.2.0
- See Also:
-
trimLeadingWhitespaces
Remove any leading whitespaces from the passed string.- Parameters:
s- the String to be trimmed- Returns:
- the original String with all leading whitespaces removed
-
trimTrailingWhitespaces
Remove any trailing whitespaces from the passed string.- Parameters:
s- the String to be cut- Returns:
- the original String with all trailing whitespaces removed
-
trimStart
@CheckReturnValue public static @Nullable String trimStart(@Nullable String sSrc, @Nullable String sLead) Trim the passed lead from the source value. If the source value does not start with the passed lead, nothing happens.- Parameters:
sSrc- The input source stringsLead- The string to be trimmed of the beginning- Returns:
- The trimmed string, or the original input string, if the lead was not found
- See Also:
-
trimStartRepeatedly
@CheckReturnValue public static @Nullable String trimStartRepeatedly(@Nullable String sSrc, @Nullable String sLead) Trim the passed lead from the source value repeatedly until the source no longer starts with the lead. If the source value does not start with the passed lead, nothing happens.- Parameters:
sSrc- The input source string. May benull.sLead- The string to be trimmed of the beginning repeatedly. May benull.- Returns:
- The trimmed string, or the original input string, if the lead was not found.
- See Also:
-
trimStart
Trim the passed lead from the source value. If the source value does not start with the passed lead, nothing happens.- Parameters:
sSrc- The input source stringcLead- The char to be trimmed of the beginning- Returns:
- The trimmed string, or the original input string, if the lead was not found
- See Also:
-
trimStartRepeatedly
@CheckReturnValue public static @Nullable String trimStartRepeatedly(@Nullable String sSrc, char cLead) Trim the passed lead character from the source value repeatedly until the source no longer starts with the lead. If the source value does not start with the passed lead, nothing happens.- Parameters:
sSrc- The input source string. May benull.cLead- The character to be trimmed of the beginning repeatedly.- Returns:
- The trimmed string, or the original input string, if the lead was not found.
- See Also:
-
trimStart
@CheckReturnValue public static @Nullable String trimStart(@Nullable String sSrc, @Nonnegative int nCount) Trim the passed lead from the source value. If the source value does not start with the passed lead, nothing happens.- Parameters:
sSrc- The input source stringnCount- The number of characters to trim at the end.- Returns:
- The trimmed string, or an empty string if nCount is ≥ the length of the source string
-
trimEnd
@CheckReturnValue public static @Nullable String trimEnd(@Nullable String sSrc, @Nullable String sTail) Trim the passed tail from the source value. If the source value does not end with the passed tail, nothing happens.- Parameters:
sSrc- The input source stringsTail- The string to be trimmed of the end- Returns:
- The trimmed string, or the original input string, if the tail was not found
- See Also:
-
trimEndRepeatedly
@CheckReturnValue public static @Nullable String trimEndRepeatedly(@Nullable String sSrc, @Nullable String sTail) Trim the passed tail from the source value repeatedly until the source no longer ends with the tail. If the source value does not end with the passed tail, nothing happens.- Parameters:
sSrc- The input source string. May benull.sTail- The string to be trimmed of the end repeatedly. May benull.- Returns:
- The trimmed string, or the original input string, if the tail was not found.
- See Also:
-
trimEnd
Trim the passed tail from the source value. If the source value does not end with the passed tail, nothing happens.- Parameters:
sSrc- The input source stringcTail- The char to be trimmed of the end- Returns:
- The trimmed string, or the original input string, if the tail was not found
- See Also:
-
trimEndRepeatedly
@CheckReturnValue public static @Nullable String trimEndRepeatedly(@Nullable String sSrc, char cTail) Trim the passed tail character from the source value repeatedly until the source no longer ends with the tail. If the source value does not end with the passed tail, nothing happens.- Parameters:
sSrc- The input source string. May benull.cTail- The character to be trimmed of the end repeatedly.- Returns:
- The trimmed string, or the original input string, if the tail was not found.
- See Also:
-
trimEnd
@CheckReturnValue public static @Nullable String trimEnd(@Nullable String sSrc, @Nonnegative int nCount) Trim the passed tail from the source value. If the source value does not end with the passed tail, nothing happens.- Parameters:
sSrc- The input source stringnCount- The number of characters to trim at the end.- Returns:
- The trimmed string, or an empty string if nCount is ≥ the length of the source string
-
trimStartAndEnd
@CheckReturnValue public static @Nullable String trimStartAndEnd(@Nullable String sSrc, @Nullable String sValueToTrim) Trim the passed lead and tail from the source value. If the source value does not start with the passed trimmed value, nothing happens.- Parameters:
sSrc- The input source stringsValueToTrim- The string to be trimmed of the beginning and the end- Returns:
- The trimmed string, or the original input string, if the value to trim was not found
- See Also:
-
trimStartAndEnd
@CheckReturnValue public static @Nullable String trimStartAndEnd(@Nullable String sSrc, @Nullable String sLead, @Nullable String sTail) Trim the passed lead and tail from the source value. If the source value does not start with the passed lead and does not end with the passed tail, nothing happens.- Parameters:
sSrc- The input source stringsLead- The string to be trimmed of the beginningsTail- The string to be trimmed of the end- Returns:
- The trimmed string, or the original input string, if the lead and the tail were not found
- See Also:
-
trimStartAndEnd
@CheckReturnValue public static @Nullable String trimStartAndEnd(@Nullable String sSrc, char cValueToTrim) Trim the passed lead and tail from the source value. If the source value does not start with the passed trimmed value, nothing happens.- Parameters:
sSrc- The input source stringcValueToTrim- The char to be trimmed of the beginning and the end- Returns:
- The trimmed string, or the original input string, if the value to trim was not found
- See Also:
-
trimStartAndEnd
@CheckReturnValue public static @Nullable String trimStartAndEnd(@Nullable String sSrc, char cLead, char cTail) Trim the passed lead and tail from the source value. If the source value does not start with the passed lead and does not end with the passed tail, nothing happens.- Parameters:
sSrc- The input source stringcLead- The char to be trimmed of the beginningcTail- The char to be trimmed of the end- Returns:
- The trimmed string, or the original input string, if the lead and the tail were not found
- See Also:
-
trim
Trim the passed string, if it is notnull.- Parameters:
s- The string to be trimmed. May benull.- Returns:
nullif the input string wasnull, the non-nulltrimmed string otherwise.- See Also:
-
getCutAfterLength
public static @NonNull String getCutAfterLength(@NonNull String sValue, @Nonnegative int nMaxLength) Cut the passed string after the specified length.- Parameters:
sValue- The value to be cut. May not benull.nMaxLength- The maximum number of characters to keep. Must be ≥ 0.- Returns:
- The original string if it is shorter than or equal to the max length, otherwise the
string cut after the specified length. Never
null. - See Also:
-
getCutAfterLength
public static @NonNull String getCutAfterLength(@NonNull String sValue, @Nonnegative int nMaxLength, @Nullable String sNewSuffix) Cut the passed string after the specified length, optionally appending a suffix (e.g. "...").- Parameters:
sValue- The value to be cut. May not benull.nMaxLength- The maximum number of characters to keep. Must be ≥ 0.sNewSuffix- An optional suffix to append if the string was cut. May benull.- Returns:
- The original string if it is shorter than or equal to the max length, otherwise the
string cut after the specified length with the optional suffix appended. Never
null.
-
getToString
Convert the passed object to a string using theObject.toString()method.- Parameters:
aObject- The value to be converted. May benull.- Returns:
- An empty string in case the passed object was
null. Nevernull. - See Also:
-
getToString
Convert the passed object to a string using theObject.toString()method or otherwise return the passed default value.- Parameters:
aObject- The value to be converted. May benull.sNullValue- The value to be returned in case the passed object isnull. May benullitself.- Returns:
- The passed default value in case the passed object was
nullor the result ofObject.toString()on the passed object. - See Also:
-
getWithoutLeadingChar
Get the passed string without the first char.- Parameters:
sStr- The source string. May benull.- Returns:
- An empty, non-
nullstring if the passed string has a length ≤ 1.
-
getWithoutLeadingChars
public static @NonNull String getWithoutLeadingChars(@Nullable String sStr, @Nonnegative int nCount) Get the passed string without the specified number of leading chars.- Parameters:
sStr- The source string. May benull.nCount- The number of chars to remove.- Returns:
- An empty, non-
nullstring if the passed string has a length ≤nCount.
-
getWithoutTrailingChar
Get the passed string without the last char.- Parameters:
sStr- The source string. May benull.- Returns:
- An empty, non-
nullstring if the passed string has a length ≤ 1.
-
getWithoutTrailingChars
public static @NonNull String getWithoutTrailingChars(@Nullable String sStr, @Nonnegative int nCount) Get the passed string without the specified number of trailing chars.- Parameters:
sStr- The source string. May benull.nCount- The number of chars to remove.- Returns:
- An empty, non-
nullstring if the passed string has a length ≤nCount.
-
getWithoutAnySpaces
Get the passed string where all spaces (white spaces or unicode spaces) have been removed.- Parameters:
sStr- The source string. May benull- Returns:
- A non-
nullstring representing the passed string without any spaces
-
getUntilFirstIncl
Get everything from the string up to and including the first passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getUntilFirstExcl
Get everything from the string up to and excluding first the passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getUntilFirstIncl
Get everything from the string up to and including the first passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the empty string is returned.
-
getUntilFirstExcl
Get everything from the string up to and excluding the first passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the empty string is returned.
-
getUntilLastIncl
Get everything from the string up to and including the first passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getUntilLastExcl
Get everything from the string up to and excluding first the passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getUntilLastIncl
Get everything from the string up to and including the first passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the empty string is returned.
-
getUntilLastExcl
Get everything from the string up to and excluding the first passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the empty string is returned.
-
getFromFirstIncl
Get everything from the string from and including the first passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getFromFirstExcl
Get everything from the string from and excluding the first passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getFromFirstIncl
Get everything from the string from and including the passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
-
getFromFirstExcl
Get everything from the string from and excluding the passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
-
getFromLastIncl
Get everything from the string from and including the first passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getFromLastExcl
Get everything from the string from and excluding the first passed char.- Parameters:
sStr- The source string. May benull.cSearch- The character to search.- Returns:
nullif the passed string does not contain the search character.
-
getFromLastIncl
Get everything from the string from and including the passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
-
getFromLastExcl
Get everything from the string from and excluding the passed string.- Parameters:
sStr- The source string. May benull.sSearch- The string to search. May benull.- Returns:
nullif the passed string does not contain the search string. If the search string is empty, the input string is returned unmodified.
-
getFirstToken
Get the first token up to (and excluding) the separating character.- Parameters:
sStr- The string to search. May benull.cSearch- The search character.- Returns:
- The passed string if no such separator token was found.
-
getFirstToken
Get the first token up to (and excluding) the separating string.- Parameters:
sStr- The string to search. May benull.sSearch- The search string. May benull.- Returns:
- The passed string if no such separator token was found.
-
getLastToken
Get the last token from (and excluding) the separating character.- Parameters:
sStr- The string to search. May benull.cSearch- The search character.- Returns:
- The passed string if no such separator token was found.
-
getLastToken
Get the last token from (and excluding) the separating string.- Parameters:
sStr- The string to search. May benull.sSearch- The search string. May benull.- Returns:
- The passed string if no such separator token was found.
-
isEmpty(CharSequence)instead