Class StringExpressions


  • public final class StringExpressions
    extends Object
    Defines helper methods for the string expressions
    Since:
    2.0
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static dev.morphia.aggregation.expressions.impls.Expression concat​(dev.morphia.aggregation.expressions.impls.Expression first, dev.morphia.aggregation.expressions.impls.Expression... additional)
      Concatenates any number of strings.
      static dev.morphia.aggregation.expressions.impls.IndexExpression indexOfBytes​(dev.morphia.aggregation.expressions.impls.Expression string, dev.morphia.aggregation.expressions.impls.Expression substring)
      Searches a string for an occurence of a substring and returns the UTF-8 byte index of the first occurence.
      static dev.morphia.aggregation.expressions.impls.IndexExpression indexOfCP​(dev.morphia.aggregation.expressions.impls.Expression string, dev.morphia.aggregation.expressions.impls.Expression substring)
      Searches a string for an occurence of a substring and returns the UTF-8 code point index of the first occurence.
      static dev.morphia.aggregation.expressions.impls.TrimExpression ltrim​(dev.morphia.aggregation.expressions.impls.Expression input)
      Removes whitespace or the specified characters from the beginning of a string.
      static dev.morphia.aggregation.expressions.impls.RegexExpression regexFind​(dev.morphia.aggregation.expressions.impls.Expression input)
      Applies a regular expression (regex) to a string and returns information on the first matched substring.
      static dev.morphia.aggregation.expressions.impls.RegexExpression regexFindAll​(dev.morphia.aggregation.expressions.impls.Expression input)
      Applies a regular expression (regex) to a string and returns information on the all matched substrings.
      static dev.morphia.aggregation.expressions.impls.RegexExpression regexMatch​(dev.morphia.aggregation.expressions.impls.Expression input)
      Applies a regular expression (regex) to a string and returns a boolean that indicates if a match is found or not.
      static dev.morphia.aggregation.expressions.impls.Expression replaceAll​(dev.morphia.aggregation.expressions.impls.Expression input, dev.morphia.aggregation.expressions.impls.Expression find, dev.morphia.aggregation.expressions.impls.Expression replacement)
      Replaces all instances of a search string in an input string with a replacement string.
      static dev.morphia.aggregation.expressions.impls.Expression replaceOne​(dev.morphia.aggregation.expressions.impls.Expression input, dev.morphia.aggregation.expressions.impls.Expression find, dev.morphia.aggregation.expressions.impls.Expression replacement)
      Replaces the first instance of a search string in an input string with a replacement string.
      static dev.morphia.aggregation.expressions.impls.TrimExpression rtrim​(dev.morphia.aggregation.expressions.impls.Expression input)
      Removes whitespace or the specified characters from the end of a string.
      static dev.morphia.aggregation.expressions.impls.Expression split​(dev.morphia.aggregation.expressions.impls.Expression input, dev.morphia.aggregation.expressions.impls.Expression delimiter)
      Splits a string into substrings based on a delimiter.
      static dev.morphia.aggregation.expressions.impls.Expression strcasecmp​(dev.morphia.aggregation.expressions.impls.Expression first, dev.morphia.aggregation.expressions.impls.Expression second)
      Performs case-insensitive string comparison and returns: 0 if two strings are equivalent, 1 if the first string is greater than the second, and -1 if the first string is less than the second.
      static dev.morphia.aggregation.expressions.impls.Expression strLenBytes​(dev.morphia.aggregation.expressions.impls.Expression input)
      Returns the number of UTF-8 encoded bytes in a string.
      static dev.morphia.aggregation.expressions.impls.Expression strLenCP​(dev.morphia.aggregation.expressions.impls.Expression input)
      Returns the number of UTF-8 code points in a string.
      static dev.morphia.aggregation.expressions.impls.Expression substr​(dev.morphia.aggregation.expressions.impls.Expression input, int start, int length)
      Deprecated.
      Deprecated since version 3.4: $substr is now an alias for substrBytes(Expression, int, int)
      static dev.morphia.aggregation.expressions.impls.Expression substrBytes​(dev.morphia.aggregation.expressions.impls.Expression input, int start, int length)
      Returns the substring of a string.
      static dev.morphia.aggregation.expressions.impls.Expression substrCP​(dev.morphia.aggregation.expressions.impls.Expression input, int start, int length)
      Returns the substring of a string.
      static dev.morphia.aggregation.expressions.impls.Expression toLower​(dev.morphia.aggregation.expressions.impls.Expression input)
      Converts a string to lowercase.
      static dev.morphia.aggregation.expressions.impls.Expression toString​(dev.morphia.aggregation.expressions.impls.Expression input)
      Converts value to a string.
      static dev.morphia.aggregation.expressions.impls.Expression toUpper​(dev.morphia.aggregation.expressions.impls.Expression input)
      Converts a string to uppercase.
      static dev.morphia.aggregation.expressions.impls.TrimExpression trim​(dev.morphia.aggregation.expressions.impls.Expression input)
      Removes whitespace or the specified characters from the beginning and end of a string.
    • Method Detail

      • concat

        public static dev.morphia.aggregation.expressions.impls.Expression concat​(dev.morphia.aggregation.expressions.impls.Expression first,
                                                                                  dev.morphia.aggregation.expressions.impls.Expression... additional)
        Concatenates any number of strings.
        Parameters:
        first - the first array expression
        additional - additional expressions
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $concat
      • indexOfBytes

        public static dev.morphia.aggregation.expressions.impls.IndexExpression indexOfBytes​(dev.morphia.aggregation.expressions.impls.Expression string,
                                                                                             dev.morphia.aggregation.expressions.impls.Expression substring)
        Searches a string for an occurence of a substring and returns the UTF-8 byte index of the first occurence. If the substring is not found, returns -1.
        Parameters:
        string - the string to search
        substring - the target string
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $indexOfBytes
      • indexOfCP

        public static dev.morphia.aggregation.expressions.impls.IndexExpression indexOfCP​(dev.morphia.aggregation.expressions.impls.Expression string,
                                                                                          dev.morphia.aggregation.expressions.impls.Expression substring)
        Searches a string for an occurence of a substring and returns the UTF-8 code point index of the first occurence. If the substring is not found, returns -1
        Parameters:
        string - the string to search
        substring - the target string
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $indexOfCP
      • ltrim

        public static dev.morphia.aggregation.expressions.impls.TrimExpression ltrim​(dev.morphia.aggregation.expressions.impls.Expression input)
        Removes whitespace or the specified characters from the beginning of a string.
        Parameters:
        input - The string to trim. The argument can be any valid expression that resolves to a string.
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $ltrim
      • regexFind

        public static dev.morphia.aggregation.expressions.impls.RegexExpression regexFind​(dev.morphia.aggregation.expressions.impls.Expression input)
        Applies a regular expression (regex) to a string and returns information on the first matched substring.
        Parameters:
        input - the string to evaluate
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $regexFind
      • regexFindAll

        public static dev.morphia.aggregation.expressions.impls.RegexExpression regexFindAll​(dev.morphia.aggregation.expressions.impls.Expression input)
        Applies a regular expression (regex) to a string and returns information on the all matched substrings.
        Parameters:
        input - the string to evaluate
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $regexFindAll
      • regexMatch

        public static dev.morphia.aggregation.expressions.impls.RegexExpression regexMatch​(dev.morphia.aggregation.expressions.impls.Expression input)
        Applies a regular expression (regex) to a string and returns a boolean that indicates if a match is found or not.
        Parameters:
        input - the string to process
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $regexMatch
      • replaceAll

        public static dev.morphia.aggregation.expressions.impls.Expression replaceAll​(dev.morphia.aggregation.expressions.impls.Expression input,
                                                                                      dev.morphia.aggregation.expressions.impls.Expression find,
                                                                                      dev.morphia.aggregation.expressions.impls.Expression replacement)
        Replaces all instances of a search string in an input string with a replacement string.
        Parameters:
        input - the input value/source
        find - the search expression
        replacement - the replacement value
        Returns:
        the new expression
        Since:
        2.1
        MongoDB documentation
        Aggregration Expression: $replaceAll
      • replaceOne

        public static dev.morphia.aggregation.expressions.impls.Expression replaceOne​(dev.morphia.aggregation.expressions.impls.Expression input,
                                                                                      dev.morphia.aggregation.expressions.impls.Expression find,
                                                                                      dev.morphia.aggregation.expressions.impls.Expression replacement)
        Replaces the first instance of a search string in an input string with a replacement string.
        Parameters:
        input - the input value/source
        find - the search expression
        replacement - the replacement value
        Returns:
        the new expression
        Since:
        2.1
        MongoDB documentation
        Aggregration Expression: $replaceOne
      • rtrim

        public static dev.morphia.aggregation.expressions.impls.TrimExpression rtrim​(dev.morphia.aggregation.expressions.impls.Expression input)
        Removes whitespace or the specified characters from the end of a string.
        Parameters:
        input - The string to trim. The argument can be any valid expression that resolves to a string.
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $rtrim
      • split

        public static dev.morphia.aggregation.expressions.impls.Expression split​(dev.morphia.aggregation.expressions.impls.Expression input,
                                                                                 dev.morphia.aggregation.expressions.impls.Expression delimiter)
        Splits a string into substrings based on a delimiter. Returns an array of substrings. If the delimiter is not found within the string, returns an array containing the original string.
        Parameters:
        input - The string to split. The argument can be any valid expression that resolves to a string.
        delimiter - The delimiter to use when splitting the string expression. delimiter can be any valid expression as long as it resolves to a string.
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $split
      • strLenBytes

        public static dev.morphia.aggregation.expressions.impls.Expression strLenBytes​(dev.morphia.aggregation.expressions.impls.Expression input)
        Returns the number of UTF-8 encoded bytes in a string.
        Parameters:
        input - the string to process
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $strLenBytes
      • strLenCP

        public static dev.morphia.aggregation.expressions.impls.Expression strLenCP​(dev.morphia.aggregation.expressions.impls.Expression input)
        Returns the number of UTF-8 code points in a string.
        Parameters:
        input - the string to process
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $strLenCP
      • strcasecmp

        public static dev.morphia.aggregation.expressions.impls.Expression strcasecmp​(dev.morphia.aggregation.expressions.impls.Expression first,
                                                                                      dev.morphia.aggregation.expressions.impls.Expression second)
        Performs case-insensitive string comparison and returns: 0 if two strings are equivalent, 1 if the first string is greater than the second, and -1 if the first string is less than the second.
        Parameters:
        first - the first string to compare
        second - the first string to second
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $strcasecmp
      • substr

        @Deprecated
        public static dev.morphia.aggregation.expressions.impls.Expression substr​(dev.morphia.aggregation.expressions.impls.Expression input,
                                                                                  int start,
                                                                                  int length)
        Deprecated.
        Deprecated since version 3.4: $substr is now an alias for substrBytes(Expression, int, int)
        Deprecated. Use $substrBytes or $substrCP.

        *note*: Included for completeness and discoverability.

        Parameters:
        input - the string to process
        start - the starting position
        length - the number of characters
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $substr
      • substrBytes

        public static dev.morphia.aggregation.expressions.impls.Expression substrBytes​(dev.morphia.aggregation.expressions.impls.Expression input,
                                                                                       int start,
                                                                                       int length)
        Returns the substring of a string. Starts with the character at the specified UTF-8 byte index (zero-based) in the string and continues for the specified number of bytes.
        Parameters:
        input - the string to process
        start - Indicates the starting point of the substring
        length - the byte count to include. Can not result in an ending index that is in the middle of a UTF-8 character.
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $substrBytes
      • substrCP

        public static dev.morphia.aggregation.expressions.impls.Expression substrCP​(dev.morphia.aggregation.expressions.impls.Expression input,
                                                                                    int start,
                                                                                    int length)
        Returns the substring of a string. Starts with the character at the specified UTF-8 code point (CP) index (zero-based) in the string and continues for the number of code points specified.
        Parameters:
        input - the string to process
        start - Indicates the starting point of the substring
        length - the code points to include.
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $substrCP
      • toLower

        public static dev.morphia.aggregation.expressions.impls.Expression toLower​(dev.morphia.aggregation.expressions.impls.Expression input)
        Converts a string to lowercase. Accepts a single argument expression.
        Parameters:
        input - the string to process
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $toLower
      • toString

        public static dev.morphia.aggregation.expressions.impls.Expression toString​(dev.morphia.aggregation.expressions.impls.Expression input)
        Converts value to a string.
        Parameters:
        input - the value to process
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $toString
      • toUpper

        public static dev.morphia.aggregation.expressions.impls.Expression toUpper​(dev.morphia.aggregation.expressions.impls.Expression input)
        Converts a string to uppercase. Accepts a single argument expression.
        Parameters:
        input - the string to process
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $toUpper
      • trim

        public static dev.morphia.aggregation.expressions.impls.TrimExpression trim​(dev.morphia.aggregation.expressions.impls.Expression input)
        Removes whitespace or the specified characters from the beginning and end of a string.
        Parameters:
        input - the string to process
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $trim