Skip to content

Commit b80bfcd

Browse files
committed
4.4 annotations (#1070)
JAVA-4799
1 parent 5680102 commit b80bfcd

File tree

7 files changed

+48
-25
lines changed

7 files changed

+48
-25
lines changed

driver-core/src/main/com/mongodb/client/model/expressions/ArrayExpression.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ default T elementAt(final int i) {
247247
* the array is not empty.
248248
* If the array is empty then the behaviour of the API is not defined.
249249
*
250+
* @mongodb.server.release 4.4
250251
* @return the resulting value.
251252
*/
252253
@MqlUnchecked(PRESENT)
@@ -259,6 +260,7 @@ default T elementAt(final int i) {
259260
* the array is not empty.
260261
* If the array is empty then the behaviour of the API is not defined.
261262
*
263+
* @mongodb.server.release 4.4
262264
* @return the resulting value.
263265
*/
264266
T last();

driver-core/src/main/com/mongodb/client/model/expressions/Branches.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public <R extends Expression> BranchesIntermediary<T, R> isBoolean(final Functio
127127
* {@linkplain Expression#isBooleanOr(BooleanExpression) being a boolean}
128128
* produces a value specified by the {@code mapping}.
129129
*
130+
* @mongodb.server.release 4.4
130131
* @param mapping the mapping.
131132
* @return the appended sequence of checks.
132133
* @param <R> the type of the produced value.
@@ -140,6 +141,7 @@ public <R extends Expression> BranchesIntermediary<T, R> isNumber(final Function
140141
* {@linkplain Expression#isIntegerOr(IntegerExpression) being an integer}
141142
* produces a value specified by the {@code mapping}.
142143
*
144+
* @mongodb.server.release 4.4
143145
* @param mapping the mapping.
144146
* @return the appended sequence of checks.
145147
* @param <R> the type of the produced value.

driver-core/src/main/com/mongodb/client/model/expressions/BranchesIntermediary.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public BranchesIntermediary<T, R> isBoolean(final Function<? super BooleanExpres
116116
* {@linkplain Expression#isBooleanOr(BooleanExpression) being a boolean}
117117
* produces a value specified by the {@code mapping}.
118118
*
119+
* @mongodb.server.release 4.4
119120
* @param mapping the mapping.
120121
* @return the appended sequence of checks.
121122
*/
@@ -128,6 +129,7 @@ public BranchesIntermediary<T, R> isNumber(final Function<? super NumberExpressi
128129
* {@linkplain Expression#isIntegerOr(IntegerExpression) being an integer}
129130
* produces a value specified by the {@code mapping}.
130131
*
132+
* @mongodb.server.release 4.4
131133
* @param mapping the mapping.
132134
* @return the appended sequence of checks.
133135
*/

driver-core/src/main/com/mongodb/client/model/expressions/Expression.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public interface Expression {
165165
* {@code this} is a number, or the {@code other} number value if
166166
* {@code this} is null, or is missing, or is of any other non-number type.
167167
*
168+
* @mongodb.server.release 4.4
168169
* @param other the other value.
169170
* @return the resulting value.
170171
*/

driver-core/src/test/functional/com/mongodb/client/model/expressions/ArrayExpressionsFunctionalTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,9 @@ public void elementAtTest() {
338338
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/
339339
assertExpression(
340340
Arrays.asList(1, 2, 3).get(0),
341-
// 0.0 is a valid integer value
342-
array123.elementAt(of(0.0).isIntegerOr(of(-1))),
341+
array123.elementAt(of(0)),
343342
// MQL:
344-
"{'$arrayElemAt': [[1, 2, 3], {'$switch': {'branches': [{'case': "
345-
+ "{'$isNumber': [0.0]}, 'then': {'$cond': "
346-
+ "[{'$eq': [{'$round': 0.0}, 0.0]}, 0.0, -1]}}], 'default': -1}}]} ");
343+
"{'$arrayElemAt': [[1, 2, 3], 0]}");
347344
// negatives
348345
assertExpression(
349346
Arrays.asList(1, 2, 3).get(3 - 1),
@@ -365,10 +362,17 @@ public void elementAtTest() {
365362
assertThrows(MongoCommandException.class, () -> assertExpression(
366363
MISSING,
367364
array123.elementAt(of(Long.MAX_VALUE))));
365+
366+
// 0.0 is a valid integer value
367+
assumeTrue(serverVersionAtLeast(4, 4)); // isNumber
368+
assertExpression(
369+
Arrays.asList(1, 2, 3).get(0),
370+
array123.elementAt(of(0.0).isIntegerOr(of(-1))));
368371
}
369372

370373
@Test
371374
public void firstTest() {
375+
assumeTrue(serverVersionAtLeast(4, 4));
372376
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/
373377
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/first-array-element/
374378
assertExpression(
@@ -386,6 +390,7 @@ public void firstTest() {
386390

387391
@Test
388392
public void lastTest() {
393+
assumeTrue(serverVersionAtLeast(4, 4));
389394
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/last-array-element/
390395
assertExpression(
391396
new LinkedList<>(Arrays.asList(1, 2, 3)).getLast(),

driver-core/src/test/functional/com/mongodb/client/model/expressions/ControlExpressionsFunctionalTest.java

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public void passToTest() {
7171

7272
@Test
7373
public void switchTest() {
74+
assumeTrue(serverVersionAtLeast(4, 4)); // isNumber
7475
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/
7576
assertExpression("a", of(0).switchOn(on -> on.is(v -> v.eq(of(0)), v -> of("a"))));
7677
assertExpression("a", of(0).switchOn(on -> on.isNumber(v -> of("a"))));
@@ -185,13 +186,6 @@ public void switchTestInitial() {
185186
assertExpression("A",
186187
of(true).switchOn(on -> on.isBoolean(v -> of("A"))),
187188
"{'$switch': {'branches': [{'case': {'$eq': [{'$type': [true]}, 'bool']}, 'then': 'A'}]}}");
188-
assertExpression("A",
189-
of(1).switchOn(on -> on.isNumber(v -> of("A"))),
190-
"{'$switch': {'branches': [{'case': {'$isNumber': [1]}, 'then': 'A'}]}}");
191-
assertExpression("A",
192-
of(1).switchOn(on -> on.isInteger(v -> of("A"))),
193-
"{'$switch': {'branches': [{'case': {'$switch': {'branches': [{'case': {'$isNumber': [1]},"
194-
+ "'then': {'$eq': [{'$round': 1}, 1]}}], 'default': false}}, 'then': 'A'}]}}");
195189
assertExpression("A",
196190
of("x").switchOn(on -> on.isString(v -> of("A"))),
197191
"{'$switch': {'branches': [{'case': {'$eq': [{'$type': ['x']}, 'string']}, 'then': 'A'}]}}");
@@ -215,6 +209,35 @@ public void switchTestInitial() {
215209
"{'$switch': {'branches': [{'case': {'$eq': [null, null]}, 'then': 'A'}]}}");
216210
}
217211

212+
@Test
213+
public void switchTestInitialVersion44() {
214+
assumeTrue(serverVersionAtLeast(4, 4));
215+
assertExpression("A",
216+
of(1).switchOn(on -> on.isNumber(v -> of("A"))),
217+
"{'$switch': {'branches': [{'case': {'$isNumber': [1]}, 'then': 'A'}]}}");
218+
assertExpression("A",
219+
of(1).switchOn(on -> on.isInteger(v -> of("A"))),
220+
"{'$switch': {'branches': [{'case': {'$switch': {'branches': [{'case': {'$isNumber': [1]},"
221+
+ "'then': {'$eq': [{'$round': 1}, 1]}}], 'default': false}}, 'then': 'A'}]}}");
222+
}
223+
@Test
224+
public void switchTestPartialVersion44() {
225+
assumeTrue(serverVersionAtLeast(4, 4));
226+
assertExpression("A",
227+
of(1).switchOn(on -> on.isNull(v -> of("X")).isNumber(v -> of("A"))),
228+
"{'$switch': {'branches': [{'case': {'$eq': [1, null]}, 'then': 'X'}, "
229+
+ "{'case': {'$isNumber': [1]}, 'then': 'A'}]}}");
230+
assertExpression("A",
231+
of(1).switchOn(on -> on.isNull(v -> of("X")).isInteger(v -> of("A"))),
232+
"{'$switch': {'branches': [{'case': {'$eq': [1, null]}, 'then': 'X'}, {'case': "
233+
+ "{'$switch': {'branches': [{'case': {'$isNumber': [1]}, "
234+
+ "'then': {'$eq': [{'$round': 1}, 1]}}], 'default': false}}, 'then': 'A'}]}}");
235+
assertExpression("A",
236+
ofNull().switchOn(on -> on.isNumber(v -> of("X")).isNull(v -> of("A"))),
237+
"{'$switch': {'branches': [{'case': {'$isNumber': [null]}, 'then': 'X'}, "
238+
+ "{'case': {'$eq': [null, null]}, 'then': 'A'}]}}");
239+
}
240+
218241
@Test
219242
public void switchTestPartial() {
220243
assertExpression("A",
@@ -243,15 +266,6 @@ public void switchTestPartial() {
243266
of(true).switchOn(on -> on.isNull(v -> of("X")).isBoolean(v -> of("A"))),
244267
"{'$switch': {'branches': [{'case': {'$eq': [true, null]}, 'then': 'X'}, "
245268
+ "{'case': {'$eq': [{'$type': [true]}, 'bool']}, 'then': 'A'}]}}");
246-
assertExpression("A",
247-
of(1).switchOn(on -> on.isNull(v -> of("X")).isNumber(v -> of("A"))),
248-
"{'$switch': {'branches': [{'case': {'$eq': [1, null]}, 'then': 'X'}, "
249-
+ "{'case': {'$isNumber': [1]}, 'then': 'A'}]}}");
250-
assertExpression("A",
251-
of(1).switchOn(on -> on.isNull(v -> of("X")).isInteger(v -> of("A"))),
252-
"{'$switch': {'branches': [{'case': {'$eq': [1, null]}, 'then': 'X'}, {'case': "
253-
+ "{'$switch': {'branches': [{'case': {'$isNumber': [1]}, "
254-
+ "'then': {'$eq': [{'$round': 1}, 1]}}], 'default': false}}, 'then': 'A'}]}}");
255269
assertExpression("A",
256270
of("x").switchOn(on -> on.isNull(v -> of("X")).isString(v -> of("A"))),
257271
"{'$switch': {'branches': [{'case': {'$eq': ['x', null]}, 'then': 'X'}, "
@@ -274,9 +288,5 @@ public void switchTestPartial() {
274288
ofMap(Document.parse("{}")).switchOn(on -> on.isNull(v -> of("X")).isMap(v -> of("A"))),
275289
"{'$switch': {'branches': [{'case': {'$eq': [{'$literal': {}}, null]}, 'then': 'X'}, "
276290
+ "{'case': {'$eq': [{'$type': [{'$literal': {}}]}, 'object']}, 'then': 'A'}]}}");
277-
assertExpression("A",
278-
ofNull().switchOn(on -> on.isNumber(v -> of("X")).isNull(v -> of("A"))),
279-
"{'$switch': {'branches': [{'case': {'$isNumber': [null]}, 'then': 'X'}, "
280-
+ "{'case': {'$eq': [null, null]}, 'then': 'A'}]}}");
281291
}
282292
}

driver-core/src/test/functional/com/mongodb/client/model/expressions/TypeExpressionsFunctionalTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public void isBooleanOrTest() {
5656

5757
@Test
5858
public void isNumberOrTest() {
59+
assumeTrue(serverVersionAtLeast(4, 4));
5960
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/
6061
assertExpression(1, of(1).isNumberOr(of(99)), "{'$cond': [{'$isNumber': [1]}, 1, 99]}");
6162
// other numeric values:

0 commit comments

Comments
 (0)