Package com.apple.foundationdb.util
Class StringUtils
java.lang.Object
com.apple.foundationdb.util.StringUtils
Utility methods for operating with
Strings.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsIgnoreCase(String source, String searchStr) Returns whether some substring ofsourcecontainssearchStr, ignoring case.static booleanWhether the string is a non-empty string containing only numeric characters.static booleanWhether the substring beginning atbeginIndexis non-empty and contains only numeric characters.static booleanWhether the substring frombeginIndextoendIndexis non-empty and contains only numeric characters.static Stringrepeat(char c, int n) static StringreplaceEach(String source, Map<String, String> replaceMap) Replace all occurrences of the keys of thereplaceMapin thesourcestring with their corresponding value in the map.
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
isNumeric
Whether the string is a non-empty string containing only numeric characters.- Parameters:
s- string to test for numeric characters- Returns:
- whether
scontains only numeric characters
-
isNumeric
Whether the substring beginning atbeginIndexis non-empty and contains only numeric characters. This should be equivalent to callingisNumeric(s.substring(beginIndex)).- Parameters:
s- string to test for numeric charactersbeginIndex- index to begin testing for numeric characters- Returns:
- whether the substring of
sbeginning atbeginIndexis non-empty and contains only numeric characters
-
isNumeric
Whether the substring frombeginIndextoendIndexis non-empty and contains only numeric characters. This should be equivalent to callingisNumeric(s.substring(beginIndex, endIndex)).- Parameters:
s- string to test for numeric charactersbeginIndex- index to begin testing for numeric charactersendIndex- index to end testing for numeric characters- Returns:
- whether the substring of
sbeginning atbeginIndexand ending atendIndexis non-empty and contains only numeric characters
-
repeat
Construct aStringwithnoccurrences of a characterc. Ifnis less than or equal to zero, the empty string will be returned. Note that if the character is in the high surrogate or low surrogate range (characters necessary to represent Unicode codepoints above U+FFFF in UTF-16), then the returned string will not be valid UTF-16.- Parameters:
c- a charactern- the number of times to repeatc- Returns:
- a string with
noccurrences of the stringc - See Also:
-
replaceEach
@Nonnull public static String replaceEach(@Nonnull String source, @Nonnull Map<String, String> replaceMap) Replace all occurrences of the keys of thereplaceMapin thesourcestring with their corresponding value in the map. Elements from thereplaceMapare processed in order in thesourcestring, so if two keys overlap, the one with the lower index will be processed. For example:replaceEach("abc", Map.of("ab", "x", "bc", "y")) = "xc"; replaceEach("abb", Map.of("ab", "x", "bb", "y")) = "xb"; replaceEach("abbb", Map.of("ab", "x", "bb", "y")) = "xy";If one replacement key is a prefix of another key, then the longer key will be preferred when the longer string is present. (If the other choice was taken, it would never process the longer key, as any time the longer key is found, the shorter key would also be found.) For example:
replaceEach("abc", Map.of("ab", "x", "abc", "y")) = "y"; replaceEach("ababc", Map.of("ab", "x", "abc", "y")) = "xy"; replaceEach("abcab", Map.of("ab", "x", "abc", "y")) = "yx";- Parameters:
source- string to perform the find and replace onreplaceMap- mapping used to transform thesourcestring- Returns:
- a string composed by replacing all occurrences of the
replaceMapkeys insourcewith their values
-
containsIgnoreCase
Returns whether some substring ofsourcecontainssearchStr, ignoring case. This uses the same criteria asString.equalsIgnoreCase(String)to determine if characters are equal ignoring case.- Parameters:
source- the source stringsearchStr- the string to search through- Returns:
- whether some substring of
sourceis equal tosearchStrignoring case
-