14
14
import java .io .Serializable ;
15
15
import java .util .EnumMap ;
16
16
import java .util .Map ;
17
+ import java .util .Objects ;
17
18
import java .util .function .Function ;
18
19
19
20
/**
@@ -36,6 +37,7 @@ public interface UnaryOperator extends Serializable {
36
37
UNARY_OPERATORS .put (Operation .ABS , UnaryOperations ::abs );
37
38
UNARY_OPERATORS .put (Operation .LOWER , UnaryOperations ::lower );
38
39
UNARY_OPERATORS .put (Operation .UPPER , UnaryOperations ::upper );
40
+ UNARY_OPERATORS .put (Operation .HASH , UnaryOperations ::hash );
39
41
}
40
42
41
43
static TypedObject not (Evaluator evaluator , BulletRecord record ) {
@@ -61,20 +63,6 @@ static TypedObject trim(Evaluator evaluator, BulletRecord record) {
61
63
});
62
64
}
63
65
64
- static TypedObject lower (Evaluator evaluator , BulletRecord record ) {
65
- return checkNull (evaluator , record , value -> {
66
- String str = (String ) value .getValue ();
67
- return TypedObject .valueOf (str .toLowerCase ());
68
- });
69
- }
70
-
71
- static TypedObject upper (Evaluator evaluator , BulletRecord record ) {
72
- return checkNull (evaluator , record , value -> {
73
- String str = (String ) value .getValue ();
74
- return TypedObject .valueOf (str .toUpperCase ());
75
- });
76
- }
77
-
78
66
static TypedObject abs (Evaluator evaluator , BulletRecord record ) {
79
67
return checkNull (evaluator , record , value -> {
80
68
Number number = (Number ) value .getValue ();
@@ -91,6 +79,24 @@ static TypedObject abs(Evaluator evaluator, BulletRecord record) {
91
79
});
92
80
}
93
81
82
+ static TypedObject lower (Evaluator evaluator , BulletRecord record ) {
83
+ return checkNull (evaluator , record , value -> {
84
+ String str = (String ) value .getValue ();
85
+ return TypedObject .valueOf (str .toLowerCase ());
86
+ });
87
+ }
88
+
89
+ static TypedObject upper (Evaluator evaluator , BulletRecord record ) {
90
+ return checkNull (evaluator , record , value -> {
91
+ String str = (String ) value .getValue ();
92
+ return TypedObject .valueOf (str .toUpperCase ());
93
+ });
94
+ }
95
+
96
+ static TypedObject hash (Evaluator evaluator , BulletRecord record ) {
97
+ return TypedObject .valueOf (Objects .hashCode (evaluator .evaluate (record ).getValue ()));
98
+ }
99
+
94
100
private static TypedObject checkNull (Evaluator evaluator , BulletRecord record , Function <TypedObject , TypedObject > operator ) {
95
101
TypedObject value = evaluator .evaluate (record );
96
102
if (Utilities .isNull (value )) {
0 commit comments