Class StringUtils

java.lang.Object
com.apple.foundationdb.util.StringUtils

public class StringUtils extends Object
Utility methods for operating with Strings.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    containsIgnoreCase(String source, String searchStr)
    Returns whether some substring of source contains searchStr, ignoring case.
    static boolean
    Whether the string is a non-empty string containing only numeric characters.
    static boolean
    isNumeric(String s, int beginIndex)
    Whether the substring beginning at beginIndex is non-empty and contains only numeric characters.
    static boolean
    isNumeric(String s, int beginIndex, int endIndex)
    Whether the substring from beginIndex to endIndex is non-empty and contains only numeric characters.
    static String
    repeat(char c, int n)
    Construct a String with n occurrences of a character c.
    static String
    replaceEach(String source, Map<String,String> replaceMap)
    Replace all occurrences of the keys of the replaceMap in the source string with their corresponding value in the map.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • isNumeric

      public static boolean isNumeric(@Nonnull String s)
      Whether the string is a non-empty string containing only numeric characters.
      Parameters:
      s - string to test for numeric characters
      Returns:
      whether s contains only numeric characters
    • isNumeric

      public static boolean isNumeric(@Nonnull String s, int beginIndex)
      Whether the substring beginning at beginIndex is non-empty and contains only numeric characters. This should be equivalent to calling isNumeric(s.substring(beginIndex)).
      Parameters:
      s - string to test for numeric characters
      beginIndex - index to begin testing for numeric characters
      Returns:
      whether the substring of s beginning at beginIndex is non-empty and contains only numeric characters
    • isNumeric

      public static boolean isNumeric(@Nonnull String s, int beginIndex, int endIndex)
      Whether the substring from beginIndex to endIndex is non-empty and contains only numeric characters. This should be equivalent to calling isNumeric(s.substring(beginIndex, endIndex)).
      Parameters:
      s - string to test for numeric characters
      beginIndex - index to begin testing for numeric characters
      endIndex - index to end testing for numeric characters
      Returns:
      whether the substring of s beginning at beginIndex and ending at endIndex is non-empty and contains only numeric characters
    • repeat

      public static String repeat(char c, int n)
      Construct a String with n occurrences of a character c. If n is 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 character
      n - the number of times to repeat c
      Returns:
      a string with n occurrences of the string c
      See Also:
    • replaceEach

      @Nonnull public static String replaceEach(@Nonnull String source, @Nonnull Map<String,String> replaceMap)
      Replace all occurrences of the keys of the replaceMap in the source string with their corresponding value in the map. Elements from the replaceMap are processed in order in the source string, 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 on
      replaceMap - mapping used to transform the source string
      Returns:
      a string composed by replacing all occurrences of the replaceMap keys in source with their values
    • containsIgnoreCase

      public static boolean containsIgnoreCase(@Nonnull String source, @Nonnull String searchStr)
      Returns whether some substring of source contains searchStr, ignoring case. This uses the same criteria as String.equalsIgnoreCase(String) to determine if characters are equal ignoring case.
      Parameters:
      source - the source string
      searchStr - the string to search through
      Returns:
      whether some substring of source is equal to searchStr ignoring case