Class MlStrings


  • public final class MlStrings
    extends java.lang.Object
    Another String utilities class. Class name is prefixed with Ml to avoid confusion with one of the myriad String utility classes out there.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int ID_LENGTH_LIMIT  
    • Method Summary

      Modifier and Type Method Description
      static java.lang.String doubleQuoteIfNotAlphaNumeric​(java.lang.String input)
      Surrounds with double quotes the given input if it contains any non-word characters.
      static java.lang.String getParentField​(java.lang.String fieldPath)
      Returns the path to the parent field if fieldPath is nested or fieldPath itself.
      static boolean hasValidLengthForId​(java.lang.String id)
      Checks if the given id has a valid length.
      static boolean isValidId​(java.lang.String id)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • doubleQuoteIfNotAlphaNumeric

        public static java.lang.String doubleQuoteIfNotAlphaNumeric​(java.lang.String input)
        Surrounds with double quotes the given input if it contains any non-word characters. Any double quotes contained in input will be escaped.
        Parameters:
        input - any non null string
        Returns:
        input when it does not contain non-word characters, or a new string that contains input surrounded by double quotes otherwise
      • isValidId

        public static boolean isValidId​(java.lang.String id)
      • hasValidLengthForId

        public static boolean hasValidLengthForId​(java.lang.String id)
        Checks if the given id has a valid length. We keep IDs in a length shorter or equal than ID_LENGTH_LIMIT in order to avoid unfriendly errors when storing docs with more than 512 bytes.
        Parameters:
        id - the id
        Returns:
        true if the id has a valid length
      • getParentField

        public static java.lang.String getParentField​(java.lang.String fieldPath)
        Returns the path to the parent field if fieldPath is nested or fieldPath itself.
        Parameters:
        fieldPath - a field path
        Returns:
        the path to the parent field if {code fieldPath} is nested or fieldPath itself