@@ -58,6 +58,22 @@ public static BooleanExpression of(final boolean of) {
58
58
return new MqlExpression <>((codecRegistry ) -> new AstPlaceholder (new BsonBoolean (of )));
59
59
}
60
60
61
+ /**
62
+ * Returns an array expression containing the same boolean values as the
63
+ * provided array of booleans.
64
+ *
65
+ * @param array the array of booleans
66
+ * @return the boolean array expression
67
+ */
68
+ public static ArrayExpression <BooleanExpression > ofBooleanArray (final boolean ... array ) {
69
+ Assertions .notNull ("array" , array );
70
+ List <BsonValue > list = new ArrayList <>();
71
+ for (boolean b : array ) {
72
+ list .add (new BsonBoolean (b ));
73
+ }
74
+ return new MqlExpression <>((cr ) -> new AstPlaceholder (new BsonArray (list )));
75
+ }
76
+
61
77
/**
62
78
* Returns an expression having the same integer value as the provided
63
79
* int primitive.
@@ -68,21 +84,72 @@ public static BooleanExpression of(final boolean of) {
68
84
public static IntegerExpression of (final int of ) {
69
85
return new MqlExpression <>((codecRegistry ) -> new AstPlaceholder (new BsonInt32 (of )));
70
86
}
87
+
88
+ public static ArrayExpression <IntegerExpression > ofIntegerArray (final int ... array ) {
89
+ Assertions .notNull ("array" , array );
90
+ List <BsonValue > list = new ArrayList <>();
91
+ for (int i : array ) {
92
+ list .add (new BsonInt32 (i ));
93
+ }
94
+ return new MqlExpression <>((cr ) -> new AstPlaceholder (new BsonArray (list )));
95
+ }
96
+
71
97
public static IntegerExpression of (final long of ) {
72
98
return new MqlExpression <>((codecRegistry ) -> new AstPlaceholder (new BsonInt64 (of )));
73
99
}
100
+
101
+ public static ArrayExpression <IntegerExpression > ofIntegerArray (final long ... array ) {
102
+ Assertions .notNull ("array" , array );
103
+ List <BsonValue > list = new ArrayList <>();
104
+ for (long i : array ) {
105
+ list .add (new BsonInt64 (i ));
106
+ }
107
+ return new MqlExpression <>((cr ) -> new AstPlaceholder (new BsonArray (list )));
108
+ }
109
+
74
110
public static NumberExpression of (final double of ) {
75
111
return new MqlExpression <>((codecRegistry ) -> new AstPlaceholder (new BsonDouble (of )));
76
112
}
113
+
114
+ public static ArrayExpression <NumberExpression > ofNumberArray (final double ... array ) {
115
+ Assertions .notNull ("array" , array );
116
+ List <BsonValue > list = new ArrayList <>();
117
+ for (double n : array ) {
118
+ list .add (new BsonDouble (n ));
119
+ }
120
+ return new MqlExpression <>((cr ) -> new AstPlaceholder (new BsonArray (list )));
121
+ }
122
+
77
123
public static NumberExpression of (final Decimal128 of ) {
78
124
Assertions .notNull ("Decimal128" , of );
79
125
return new MqlExpression <>((codecRegistry ) -> new AstPlaceholder (new BsonDecimal128 (of )));
80
126
}
127
+
128
+ public static ArrayExpression <NumberExpression > ofNumberArray (final Decimal128 ... array ) {
129
+ Assertions .notNull ("array" , array );
130
+ List <BsonValue > result = new ArrayList <>();
131
+ for (Decimal128 e : array ) {
132
+ Assertions .notNull ("elements of array" , e );
133
+ result .add (new BsonDecimal128 (e ));
134
+ }
135
+ return new MqlExpression <>((cr ) -> new AstPlaceholder (new BsonArray (result )));
136
+ }
137
+
81
138
public static DateExpression of (final Instant of ) {
82
139
Assertions .notNull ("Instant" , of );
83
140
return new MqlExpression <>((codecRegistry ) -> new AstPlaceholder (new BsonDateTime (of .toEpochMilli ())));
84
141
}
85
142
143
+ public static ArrayExpression <DateExpression > ofDateArray (final Instant ... array ) {
144
+ Assertions .notNull ("array" , array );
145
+ List <BsonValue > result = new ArrayList <>();
146
+ for (Instant e : array ) {
147
+ Assertions .notNull ("elements of array" , e );
148
+ result .add (new BsonDateTime (e .toEpochMilli ()));
149
+ }
150
+ return new MqlExpression <>((cr ) -> new AstPlaceholder (new BsonArray (result )));
151
+ }
152
+
86
153
/**
87
154
* Returns an expression having the same string value as the provided
88
155
* string.
@@ -95,27 +162,28 @@ public static StringExpression of(final String of) {
95
162
return new MqlExpression <>((codecRegistry ) -> new AstPlaceholder (new BsonString (of )));
96
163
}
97
164
98
- /**
99
- * Returns an array expression containing the same boolean values as the
100
- * provided array of booleans.
101
- *
102
- * @param array the array of booleans
103
- * @return the boolean array expression
104
- */
105
- public static ArrayExpression <BooleanExpression > ofBooleanArray (final boolean ... array ) {
165
+
166
+ public static ArrayExpression <StringExpression > ofStringArray (final String ... array ) {
167
+ Assertions .notNull ("array" , array );
106
168
List <BsonValue > result = new ArrayList <>();
107
- for (boolean b : array ) {
108
- result .add (new BsonBoolean (b ));
169
+ for (String e : array ) {
170
+ Assertions .notNull ("elements of array" , e );
171
+ result .add (new BsonString (e ));
109
172
}
110
173
return new MqlExpression <>((cr ) -> new AstPlaceholder (new BsonArray (result )));
111
174
}
112
175
113
-
114
- public static ArrayExpression <IntegerExpression > ofIntegerArray (final int ... ofIntegerArray ) {
115
- List <BsonValue > array = Arrays .stream (ofIntegerArray )
116
- .mapToObj (BsonInt32 ::new )
117
- .collect (Collectors .toList ());
118
- return new MqlExpression <>((cr ) -> new AstPlaceholder (new BsonArray (array )));
176
+ @ SafeVarargs // nothing is stored in the array
177
+ public static <T extends Expression > ArrayExpression <T > ofArray (final T ... array ) {
178
+ Assertions .notNull ("array" , array );
179
+ return new MqlExpression <>((cr ) -> {
180
+ List <BsonValue > list = new ArrayList <>();
181
+ for (T v : array ) {
182
+ Assertions .notNull ("elements of array" , v );
183
+ list .add (((MqlExpression <?>) v ).toBsonValue (cr ));
184
+ }
185
+ return new AstPlaceholder (new BsonArray (list ));
186
+ });
119
187
}
120
188
121
189
public static DocumentExpression ofDocument (final Bson document ) {
@@ -133,6 +201,7 @@ public static <R extends Expression> R ofNull() {
133
201
}
134
202
135
203
static NumberExpression numberToExpression (final Number number ) {
204
+ Assertions .notNull ("number" , number );
136
205
if (number instanceof Integer ) {
137
206
return of ((int ) number );
138
207
} else if (number instanceof Long ) {
0 commit comments