Class StringUtil

java.lang.Object
org.frankframework.util.StringUtil

public class StringUtil extends Object
  • Field Details

    • OMIT_PASSWORD_FIELDS_STYLE

      public static final org.apache.commons.lang3.builder.ToStringStyle OMIT_PASSWORD_FIELDS_STYLE
    • DEFAULT_STRING_SPLIT_DELIMITER

      public static final String DEFAULT_STRING_SPLIT_DELIMITER
      See Also:
    • MATCH_OPTIONAL_WHITESPACE

      public static final String MATCH_OPTIONAL_WHITESPACE
      See Also:
  • Method Details

    • concatStrings

      public static String concatStrings(String part1, String separator, 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.

      Example:

               String a = "We";
               String b = "Frank";
               String separator = "Are";
               String res = StringUtil.concatStrings(a, separator, b);
               System.out.println(res); // prints "WeAreFrank"
           

      Parameters:
      part1 - First string
      separator - Specified separator
      part2 - Second string
      Returns:
      the concatenated string
    • concat

      public static String concat(String separator, String... parts)
    • hide

      public static String hide(String string)
      Returns:
      hidden string with all characters replaced with '*'
      See Also:
    • hide

      public static String hide(String string, int mode)
      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

      public static String hideAll(String message, 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

      public static String hideAll(String message, 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

      public static String hideAll(String inputString, String regex)
      See Also:
    • hideAll

      public static String hideAll(String inputString, String 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.
    • hideAll

      public static String hideAll(String inputString, 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

      public static int countRegex(String string, String regex)
      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

      public static String lcFirst(String input)
      Turns the first Char into lower case.
    • ucFirst

      public static String ucFirst(String input)
      Turns the first Char into upper case.
    • safeCollectionToString

      public static String safeCollectionToString(Collection<?> collection)
    • split

      @Nonnull public static List<String> split(@Nullable String input)
      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) List of strings. An empty list if the input was null.
    • splitToStream

      @Nonnull public static Stream<String> splitToStream(@Nullable String input)
      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 Stream of strings. An empty stream if the input was null.
    • split

      @Nonnull public static List<String> split(@Nullable String input, @Nonnull String delim)
      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) List of strings. An empty list if the input was null.
    • splitToStream

      @Nonnull public static Stream<String> splitToStream(@Nullable String input, @Nonnull String delim)
      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

      @Nonnull public static String reflectionToString(@Nullable Object object)
      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 the OMIT_PASSWORD_FIELDS_STYLE.
      See Also:
      • ToStringBuilder.reflectionToString(java.lang.Object)