Class StringExpressions

  • java.lang.Object
    • dev.morphia.aggregation.experimental.expressions.StringExpressions

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

      • indexOfBytes

        public static IndexExpression indexOfBytes​(Expression string,
                                                   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 IndexExpression indexOfCP​(Expression string,
                                                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 TrimExpression ltrim​(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 RegexExpression regexFind​(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 RegexExpression regexFindAll​(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 RegexExpression regexMatch​(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
      • rtrim

        public static TrimExpression rtrim​(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 Expression split​(Expression input,
                                       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
      • strcasecmp

        public static Expression strcasecmp​(Expression first,
                                            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 Expression substr​(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 Expression substrBytes​(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 Expression substrCP​(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
      • trim

        public static TrimExpression trim​(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