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 Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Expression
concat(Expression first, Expression... additional)
Concatenates any number of strings.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.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.static TrimExpression
ltrim(Expression input)
Removes whitespace or the specified characters from the beginning of a string.static RegexExpression
regexFind(Expression input)
Applies a regular expression (regex) to a string and returns information on the first matched substring.static RegexExpression
regexFindAll(Expression input)
Applies a regular expression (regex) to a string and returns information on the all matched substrings.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.static Expression
replaceAll(Expression input, Expression find, Expression replacement)
Replaces all instances of a search string in an input string with a replacement string.static Expression
replaceOne(Expression input, Expression find, Expression replacement)
Replaces the first instance of a search string in an input string with a replacement string.static TrimExpression
rtrim(Expression input)
Removes whitespace or the specified characters from the end of a string.static Expression
split(Expression input, Expression delimiter)
Splits a string into substrings based on a delimiter.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.static Expression
strLenBytes(Expression input)
Returns the number of UTF-8 encoded bytes in a string.static Expression
strLenCP(Expression input)
Returns the number of UTF-8 code points in a string.static Expression
substr(Expression input, int start, int length)
Deprecated.Deprecated since version 3.4: $substr is now an alias forsubstrBytes(Expression, int, int)
static Expression
substrBytes(Expression input, int start, int length)
Returns the substring of a string.static Expression
substrCP(Expression input, int start, int length)
Returns the substring of a string.static Expression
toLower(Expression input)
Converts a string to lowercase.static Expression
toString(Expression input)
Converts value to a string.static Expression
toUpper(Expression input)
Converts a string to uppercase.static TrimExpression
trim(Expression input)
Removes whitespace or the specified characters from the beginning and end of a string.
-
-
-
Method Detail
-
concat
public static Expression concat(Expression first, Expression... additional)
Concatenates any number of strings.- Parameters:
first
- the first array expressionadditional
- additional expressions- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $concat
-
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 searchsubstring
- 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 searchsubstring
- 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
-
replaceAll
public static Expression replaceAll(Expression input, Expression find, Expression replacement)
Replaces all instances of a search string in an input string with a replacement string.- Parameters:
input
- the input value/sourcefind
- the search expressionreplacement
- the replacement value- Returns:
- the new expression
- Since:
- 2.1
- MongoDB documentation
- Aggregration Expression: $replaceAll
-
replaceOne
public static Expression replaceOne(Expression input, Expression find, Expression replacement)
Replaces the first instance of a search string in an input string with a replacement string.- Parameters:
input
- the input value/sourcefind
- the search expressionreplacement
- the replacement value- Returns:
- the new expression
- Since:
- 2.1
- MongoDB documentation
- Aggregration Expression: $replaceOne
-
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
-
strLenBytes
public static Expression strLenBytes(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 Expression strLenCP(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 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 comparesecond
- 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 forsubstrBytes(Expression, int, int)
Deprecated. Use $substrBytes or $substrCP.*note*: Included for completeness and discoverability.
- Parameters:
input
- the string to processstart
- the starting positionlength
- 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 processstart
- Indicates the starting point of the substringlength
- 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 processstart
- Indicates the starting point of the substringlength
- the code points to include.- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $substrCP
-
toLower
public static Expression toLower(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 Expression toString(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 Expression toUpper(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 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
-
-