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

      @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 null
      separator - Specified separator, may not be null
      part2 - Second string, may be NULL
      Returns:
      the concatenated string, or NULL of both part1 and part2 were null.
    • concat

      @Nullable public static String concat(@Nonnull String separator, String... parts)
      Concatenate strings with separator, 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 parts
      parts - All parts to concatenate. May contain null values.
      Returns:
      Concatenation of all parts with separator, or null.
    • hide

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

      @Nullable public static String hide(@Nullable 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

      @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

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

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

      @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

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

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

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

      @Nonnull public static String safeCollectionToString(@Nullable 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)