15
15
*/
16
16
package org .springframework .data .mongodb .core .spel ;
17
17
18
+ import org .springframework .expression .spel .ExpressionState ;
19
+ import org .springframework .expression .spel .ast .MethodReference ;
20
+
18
21
import java .util .Collections ;
19
22
import java .util .HashMap ;
20
23
import java .util .Map ;
21
24
22
- import org .springframework .expression .spel .ExpressionState ;
23
- import org .springframework .expression .spel .ast .MethodReference ;
24
-
25
25
/**
26
26
* An {@link ExpressionNode} representing a method reference.
27
- *
27
+ *
28
28
* @author Oliver Gierke
29
29
* @author Thomas Darimont
30
+ * @author Sebastien Gerard
30
31
*/
31
32
public class MethodReferenceNode extends ExpressionNode {
32
33
33
34
private static final Map <String , String > FUNCTIONS ;
34
35
35
36
static {
36
-
37
37
Map <String , String > map = new HashMap <String , String >();
38
38
39
+ map .put ("and" , "$and" ); // Returns true only when all its expressions evaluate to true.
40
+ map .put ("or" , "$or" ); // Returns true when any of its expressions evaluates to true.
41
+ map .put ("not" , "$not" ); // Returns the boolean value that is the opposite of its argument expression.
42
+
43
+ map .put ("setEquals" , "$setEquals" ); // Returns true if the input sets have the same distinct elements.
44
+ map .put ("setIntersection" , "$setIntersection" ); // Returns a set with elements that appear in all of the input sets.
45
+ map .put ("setUnion" , "$setUnion" ); // Returns a set with elements that appear in any of the input sets.
46
+ map .put ("setDifference" , "$setDifference" ); // Returns a set with elements that appear in the 1st set but not in the
47
+ // 2nd.
48
+ map .put ("setIsSubset" , "$setIsSubset" ); // Returns true if all elements of the 1st set appear in the 2nd set.
49
+ map .put ("anyElementTrue" , "$anyElementTrue" ); // Returns whether any elements of a set evaluate to true.
50
+ map .put ("allElementsTrue" , "$allElementsTrue" ); // Returns whether no element of a set evaluates to false.
51
+
52
+ map .put ("cmp" , "$cmp" ); // Returns: 0 if the two values are equivalent, 1 if the first value is greater than the
53
+ // second, and -1 if the first value is less than the second.
54
+ map .put ("eq" , "$eq" ); // Returns true if the values are equivalent.
55
+ map .put ("gt" , "$gt" ); // Returns true if the first value is greater than the second.
56
+ map .put ("gte" , "$gte" ); // Returns true if the first value is greater than or equal to the second.
57
+ map .put ("lt" , "$lt" ); // Returns true if the first value is less than the second.
58
+ map .put ("lte" , "$lte" ); // Returns true if the first value is less than or equal to the second.
59
+ map .put ("ne" , "$ne" ); // Returns true if the values are not equivalent.
60
+
61
+ map .put ("abs" , "$abs" ); // Returns the absolute value of a number.;
62
+ map .put ("add" , "$add" ); // Adds numbers to return the sum, or adds numbers and a date to return a new date.
63
+ map .put ("ceil" , "$ceil" ); // Returns the smallest integer greater than or equal to the specified number.
64
+ map .put ("divide" , "$divide" ); // Returns the result of dividing the first number by the second.
65
+ map .put ("exp" , "$exp" ); // Raises e to the specified exponent.
66
+ map .put ("floor" , "$floor" ); // Returns the largest integer less than or equal to the specified number.
67
+ map .put ("ln" , "$ln" ); // Calculates the natural log of a number.
68
+ map .put ("log" , "$log" ); // Calculates the log of a number in the specified base.
69
+ map .put ("log10" , "$log10" ); // Calculates the log base 10 of a number.
70
+ map .put ("mod" , "$mod" ); // Returns the remainder of the first number divided by the second.
71
+ map .put ("multiply" , "$multiply" ); // Multiplies numbers to return the product.
72
+ map .put ("pow" , "$pow" ); // Raises a number to the specified exponent.
73
+ map .put ("sqrt" , "$sqrt" ); // Calculates the square root.
74
+ map .put ("subtract" , "$subtract" ); // Returns the result of subtracting the second value from the first. If the
75
+ // two values are numbers, return the difference. If the two values are dates, return the difference in
76
+ // milliseconds.
77
+ map .put ("trunc" , "$trunc" ); // Truncates a number to its integer.
78
+
39
79
map .put ("concat" , "$concat" ); // Concatenates two strings.
40
- map .put ("strcasecmp" , "$strcasecmp" ); // Compares two strings and returns an integer that reflects the comparison.
41
80
map .put ("substr" , "$substr" ); // Takes a string and returns portion of that string.
42
81
map .put ("toLower" , "$toLower" ); // Converts a string to lowercase.
43
82
map .put ("toUpper" , "$toUpper" ); // Converts a string to uppercase.
83
+ map .put ("strcasecmp" , "$strcasecmp" ); // Compares two strings and returns an integer that reflects the comparison.
84
+
85
+ map .put ("meta" , "$meta" ); // Access text search metadata.
86
+
87
+ map .put ("arrayElemAt" , "$arrayElemAt" ); // Returns the element at the specified array index.
88
+ map .put ("concatArrays" , "$concatArrays" ); // Concatenates arrays to return the concatenated array.
89
+ map .put ("filter" , "$filter" ); // Selects a subset of the array to return an array with only the elements that
90
+ // match the filter condition.
91
+ map .put ("isArray" , "$isArray" ); // Determines if the operand is an array. Returns a boolean.
92
+ map .put ("size" , "$size" ); // Returns the number of elements in the array.
93
+ map .put ("slice" , "$slice" ); // Returns a subset of an array.
94
+
95
+ map .put ("map" , "$map" ); // Applies a subexpression to each element of an array and returns the array of
96
+ // resulting values in order.
97
+ map .put ("let" , "$let" ); // Defines variables for use within the scope of a subexpression and returns the result
98
+ // of the subexpression.
99
+
100
+ map .put ("literal" , "$literal" ); // Return a value without parsing.
44
101
45
102
map .put ("dayOfYear" , "$dayOfYear" ); // Converts a date to a number between 1 and 366.
46
103
map .put ("dayOfMonth" , "$dayOfMonth" ); // Converts a date to a number between 1 and 31.
@@ -53,6 +110,13 @@ public class MethodReferenceNode extends ExpressionNode {
53
110
map .put ("second" , "$second" ); // Converts a date into a number between 0 and 59. May be 60 to account for leap
54
111
// seconds.
55
112
map .put ("millisecond" , "$millisecond" ); // Returns the millisecond portion of a date as an integer between 0 and
113
+ // 999.
114
+ map .put ("dateToString" , "$dateToString" ); // Returns the date as a formatted string.
115
+
116
+ map .put ("cond" , "$cond" ); // A ternary operator that evaluates one expression, and depending on the result,
117
+ // returns the value of one of the other two expressions.
118
+ map .put ("ifNull" , "$ifNull" ); // Returns either the non-null result of the first expression or the result of the
119
+ // second expression if the first expression results in a null result.
56
120
57
121
FUNCTIONS = Collections .unmodifiableMap (map );
58
122
}
@@ -63,11 +127,8 @@ public class MethodReferenceNode extends ExpressionNode {
63
127
64
128
/**
65
129
* Returns the name of the method.
66
- *
67
- * @return
68
130
*/
69
131
public String getMethodName () {
70
-
71
132
String name = getName ();
72
133
String methodName = name .substring (0 , name .indexOf ('(' ));
73
134
return FUNCTIONS .get (methodName );
0 commit comments