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