Package org.frankframework.util
Class StringUtil
java.lang.Object
org.frankframework.util.StringUtil
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringConcatenate strings withseparator, skipping any arguments that may be null or"".static StringconcatStrings(String part1, String separator, String part2) Concatenates two strings, if specified, uses the separator in between two strings.static intcountRegex(String string, String regex) Counts the number of characters that the specified regexes will affect in the specified string.static Stringstatic StringHides the string based on the mode given.static Stringstatic StringHides the input string according to the given regex and mode.static StringhideAll(String message, Collection<Pattern> collection) Hide all characters matching the given Regular Expression.static StringhideAll(String message, Collection<Pattern> collection, int mode) Hide all characters matching the given Regular Expression.static StringHides the input string according to the given regex and mode.static StringTurns the first Char into lower case.static StringreflectionToString(Object object) toStrings and concatenates all fields of the given object, except fields containing the word 'password' or 'secret'.static StringsafeCollectionToString(Collection<?> collection) Splits a string into a list of substrings using default delimiter ",".Splits a string into an array of substrings using specified delimiters.splitToStream(String input) Splits a string into a stream of substrings using default delimiter ",".splitToStream(String input, String delim) Splits a string into a stream of substrings using specified delimiters.static StringTurns the first Char into upper case.
-
Field Details
-
OMIT_PASSWORD_FIELDS_STYLE
public static final org.apache.commons.lang3.builder.ToStringStyle OMIT_PASSWORD_FIELDS_STYLE -
DEFAULT_STRING_SPLIT_DELIMITER
- See Also:
-
MATCH_OPTIONAL_WHITESPACE
- See Also:
-
-
Method Details
-
concatStrings
@Nullable public static String concatStrings(@Nullable String part1, @Nonnull String separator, @Nullable String part2) Concatenates two strings, if specified, uses the separator in between two strings. Does not use any separators if both or one of the strings are empty.Examples:
String a = "We"; String b = "Frank"; String separator = "Are"; String res1 = StringUtil.concatStrings(a, separator, b); System.out.println(res1); // prints "WeAreFrank" String c = null; String d = "Frank"; String res2 = StringUtil.concatStrings(c, separator, d); System.out.println(res2); // prints "Frank" String e = "We"; String f = ""; String re3 = StringUtil.concatStrings(c, separator, d); System.out.println(re3); // prints "We"- Parameters:
part1- First string, may be nullseparator- Specified separator, may not be nullpart2- Second string, may be NULL- Returns:
- the concatenated string, or NULL of both
part1andpart2were null.
-
concat
Concatenate strings withseparator, skipping any arguments that may be null or"". If all given parts to be concatenated are empty / null, then return null.- Parameters:
separator- Separator to put between partsparts- All parts to concatenate. May contain null values.- Returns:
- Concatenation of all parts with separator, or null.
-
hide
- Returns:
- hidden string with all characters replaced with '*'
- See Also:
-
hide
Hides the string based on the mode given. Mode 1 hides starting from the second character of the string until, excluding, the last character.Example:
String a = "test"; String res = StringUtil.hide(a, 1); System.out.println(res) // prints "t**t" -
hideAll
@Nullable public static String hideAll(@Nullable String message, @Nullable Collection<Pattern> collection) Hide all characters matching the given Regular Expression. If the set of expressions is null or empty it will return the raw message.- See Also:
-
hideAll
@Nullable public static String hideAll(@Nullable String message, @Nullable Collection<Pattern> collection, int mode) Hide all characters matching the given Regular Expression. If the set of expressions is null or empty it will return the raw message- See Also:
-
hideAll
- See Also:
-
hideAll
Hides the input string according to the given regex and mode. If mode is set to 1, then the first half of the string gets hidden. Else, all of it. -
hideAll
@Nonnull public static String hideAll(@Nonnull String inputString, @Nonnull Pattern regex, int mode) Hides the input string according to the given regex and mode. If mode is set to 1, then the first half of the string gets hidden. Else, all of it. -
countRegex
Counts the number of characters that the specified regexes will affect in the specified string.String s = "12ab34"; String regex = "\\d"; int regexCount = StringUtil.countRegex(s, regex); // regexCount gives out 4 -
lcFirst
Turns the first Char into lower case. -
ucFirst
Turns the first Char into upper case. -
safeCollectionToString
-
split
Splits a string into a list of substrings using default delimiter ",". Spaces before or after separators, and any leading trailing spaces, are trimmed from the result.- Parameters:
input- the string to split, can be null.- Returns:
- a (modifiable)
Listof strings. An empty list if the input was null.
-
splitToStream
Splits a string into a stream of substrings using default delimiter ",". Spaces before or after separators, and any leading trailing spaces, are trimmed from the result.- Parameters:
input- the string to split, can be null.- Returns:
- a
Streamof strings. An empty stream if the input was null.
-
split
Splits a string into an array of substrings using specified delimiters. Spaces before or after separators, and any leading trailing spaces, are trimmed from the result.- Parameters:
input- the string to split, can be null.delim- the delimiters to split the string by- Returns:
- a (modifiable)
Listof strings. An empty list if the input was null.
-
splitToStream
Splits a string into a stream of substrings using specified delimiters. Spaces before or after separators, and any leading trailing spaces, are trimmed from the result.- Parameters:
input- the string to split, can be null.delim- the delimiters to split the string by. Each character in the string is a potential delimiter, so if you want to split strings by for instance a space,,or;then pass" ,;".- Returns:
- a Stream of strings. An empty stream if the input was null.
-
reflectionToString
toStrings and concatenates all fields of the given object, except fields containing the word 'password' or 'secret'. 'fail-safe' method, returns toString if it is unable to use reflection. Uses theOMIT_PASSWORD_FIELDS_STYLE.- See Also:
-