|
20 | 20 |
|
21 | 21 | import static com.mongodb.client.model.expressions.Expressions.of;
|
22 | 22 | import static com.mongodb.client.model.expressions.MqlUnchecked.Unchecked.PRESENT;
|
23 |
| -import static com.mongodb.client.model.expressions.MqlUnchecked.Unchecked.NON_EMPTY; |
24 | 23 |
|
25 | 24 | /**
|
26 | 25 | * An array {@link Expression value} in the context of the MongoDB Query
|
@@ -58,67 +57,267 @@ public interface ArrayExpression<T extends Expression> extends Expression {
|
58 | 57 | */
|
59 | 58 | IntegerExpression size();
|
60 | 59 |
|
| 60 | + /** |
| 61 | + * True if any value in {@code this} array satisfies the predicate. |
| 62 | + * |
| 63 | + * @param predicate the predicate. |
| 64 | + * @return the resulting value. |
| 65 | + */ |
61 | 66 | BooleanExpression any(Function<? super T, BooleanExpression> predicate);
|
62 | 67 |
|
| 68 | + /** |
| 69 | + * True if all values in {@code this} array satisfy the predicate. |
| 70 | + * |
| 71 | + * @param predicate the predicate. |
| 72 | + * @return the resulting value. |
| 73 | + */ |
63 | 74 | BooleanExpression all(Function<? super T, BooleanExpression> predicate);
|
64 | 75 |
|
| 76 | + /** |
| 77 | + * The sum of adding together all the values of {@code this} array, |
| 78 | + * via the provided {@code mapper}. Returns 0 if the array is empty. |
| 79 | + * |
| 80 | + * <p>The mapper may be used to transform the values of {@code this} array |
| 81 | + * into {@linkplain NumberExpression numbers}. If no transformation is |
| 82 | + * necessary, then the identify function {@code array.sum(v -> v)} should |
| 83 | + * be used. |
| 84 | + * |
| 85 | + * @param mapper the mapper function. |
| 86 | + * @return the resulting value. |
| 87 | + */ |
65 | 88 | NumberExpression sum(Function<? super T, ? extends NumberExpression> mapper);
|
66 | 89 |
|
| 90 | + /** |
| 91 | + * The product of multiplying together all the values of {@code this} array, |
| 92 | + * via the provided {@code mapper}. Returns 1 if the array is empty. |
| 93 | + * |
| 94 | + * <p>The mapper may be used to transform the values of {@code this} array |
| 95 | + * into {@linkplain NumberExpression numbers}. If no transformation is |
| 96 | + * necessary, then the identify function {@code array.multiply(v -> v)} |
| 97 | + * should be used. |
| 98 | + * |
| 99 | + * @param mapper the mapper function. |
| 100 | + * @return the resulting value. |
| 101 | + */ |
67 | 102 | NumberExpression multiply(Function<? super T, ? extends NumberExpression> mapper);
|
68 | 103 |
|
| 104 | + /** |
| 105 | + * The {@linkplain #gt(Expression) largest} value all the values of |
| 106 | + * {@code this} array, or the {@code other} value if this array is empty. |
| 107 | + * |
| 108 | + * @param other the other value. |
| 109 | + * @return the resulting value. |
| 110 | + */ |
69 | 111 | T max(T other);
|
70 | 112 |
|
| 113 | + /** |
| 114 | + * The {@linkplain #lt(Expression) smallest} value all the values of |
| 115 | + * {@code this} array, or the {@code other} value if this array is empty. |
| 116 | + * |
| 117 | + * @param other the other value. |
| 118 | + * @return the resulting value. |
| 119 | + */ |
71 | 120 | T min(T other);
|
72 | 121 |
|
| 122 | + /** |
| 123 | + * The {@linkplain #gt(Expression) largest} {@code n} elements of |
| 124 | + * {@code this} array, or all elements if the array contains fewer than |
| 125 | + * {@code n} elements. |
| 126 | + * |
| 127 | + * @param n the number of elements. |
| 128 | + * @return the resulting value. |
| 129 | + */ |
73 | 130 | ArrayExpression<T> maxN(IntegerExpression n);
|
| 131 | + |
| 132 | + /** |
| 133 | + * The {@linkplain #lt(Expression) smallest} {@code n} elements of |
| 134 | + * {@code this} array, or all elements if the array contains fewer than |
| 135 | + * {@code n} elements. |
| 136 | + * |
| 137 | + * @param n the number of elements. |
| 138 | + * @return the resulting value. |
| 139 | + */ |
74 | 140 | ArrayExpression<T> minN(IntegerExpression n);
|
75 | 141 |
|
| 142 | + /** |
| 143 | + * The string-concatenation of all the values of {@code this} array, |
| 144 | + * via the provided {@code mapper}. Returns the empty string if the array |
| 145 | + * is empty. |
| 146 | + * |
| 147 | + * <p>The mapper may be used to transform the values of {@code this} array |
| 148 | + * into {@linkplain StringExpression strings}. If no transformation is |
| 149 | + * necessary, then the identify function {@code array.join(v -> v)} should |
| 150 | + * be used. |
| 151 | + * |
| 152 | + * @param mapper the mapper function. |
| 153 | + * @return the resulting value. |
| 154 | + */ |
76 | 155 | StringExpression join(Function<? super T, StringExpression> mapper);
|
77 | 156 |
|
| 157 | + /** |
| 158 | + * The array-concatenation of all the array values of {@code this} array, |
| 159 | + * via the provided {@code mapper}. Returns the empty array if the array |
| 160 | + * is empty. |
| 161 | + * |
| 162 | + * <p>The mapper may be used to transform the values of {@code this} array |
| 163 | + * into {@linkplain ArrayExpression arrays}. If no transformation is |
| 164 | + * necessary, then the identify function {@code array.concat(v -> v)} should |
| 165 | + * be used. |
| 166 | + * |
| 167 | + * @param mapper the mapper function. |
| 168 | + * @return the resulting value. |
| 169 | + * @param <R> the type of the elements of the array. |
| 170 | + */ |
78 | 171 | <R extends Expression> ArrayExpression<R> concat(Function<? super T, ? extends ArrayExpression<? extends R>> mapper);
|
79 | 172 |
|
| 173 | + /** |
| 174 | + * The set union of all the array values of {@code this} array, |
| 175 | + * via the provided {@code mapper}. Returns the empty array if the array |
| 176 | + * is empty. |
| 177 | + * |
| 178 | + * <p>The mapper may be used to transform the values of {@code this} array |
| 179 | + * into {@linkplain ArrayExpression arrays}. If no transformation is |
| 180 | + * necessary, then the identify function {@code array.union(v -> v)} should |
| 181 | + * be used. |
| 182 | + * |
| 183 | + * @param mapper the mapper function. |
| 184 | + * @return the resulting value. |
| 185 | + * @param <R> the type of the elements of the array. |
| 186 | + */ |
80 | 187 | <R extends Expression> ArrayExpression<R> union(Function<? super T, ? extends ArrayExpression<? extends R>> mapper);
|
81 | 188 |
|
| 189 | + /** |
| 190 | + * The {@linkplain MapExpression map} value corresponding to the |
| 191 | + * {@linkplain EntryExpression entry} values of {@code this} array, |
| 192 | + * via the provided {@code mapper}. Returns the empty array if the array |
| 193 | + * is empty. |
| 194 | + * |
| 195 | + * <p>The mapper may be used to transform the values of {@code this} array |
| 196 | + * into {@linkplain EntryExpression entries}. If no transformation is |
| 197 | + * necessary, then the identify function {@code array.union(v -> v)} should |
| 198 | + * be used. |
| 199 | + * |
| 200 | + * @see MapExpression#entrySet() |
| 201 | + * @param mapper the mapper function. |
| 202 | + * @return the resulting value. |
| 203 | + * @param <R> the type of the resulting map's values. |
| 204 | + */ |
82 | 205 | <R extends Expression> MapExpression<R> asMap(Function<? super T, ? extends EntryExpression<? extends R>> mapper);
|
83 | 206 |
|
84 | 207 | /**
|
85 |
| - * user asserts that i is in bounds for the array |
| 208 | + * Returns the element at the provided index {@code i} for |
| 209 | + * {@code this} array. |
86 | 210 | *
|
87 |
| - * @param i |
88 |
| - * @return |
| 211 | + * <p>Warning: The use of this method is an assertion that |
| 212 | + * the index {@code i} is in bounds for the array. |
| 213 | + * If the index is out of bounds for this array, then |
| 214 | + * the behaviour of the API is not defined. |
| 215 | + * |
| 216 | + * @param i the index. |
| 217 | + * @return the resulting value. |
89 | 218 | */
|
90 | 219 | @MqlUnchecked(PRESENT)
|
91 | 220 | T elementAt(IntegerExpression i);
|
92 | 221 |
|
| 222 | + /** |
| 223 | + * Returns the element at the provided index {@code i} for |
| 224 | + * {@code this} array. |
| 225 | + * |
| 226 | + * <p>Warning: The use of this method is an assertion that |
| 227 | + * the index {@code i} is in bounds for the array. |
| 228 | + * If the index is out of bounds for this array, then |
| 229 | + * the behaviour of the API is not defined. |
| 230 | + * |
| 231 | + * @param i the index. |
| 232 | + * @return the resulting value. |
| 233 | + */ |
| 234 | + @MqlUnchecked(PRESENT) |
93 | 235 | default T elementAt(final int i) {
|
94 | 236 | return this.elementAt(of(i));
|
95 | 237 | }
|
96 | 238 |
|
97 | 239 | /**
|
98 |
| - * user asserts that array is not empty |
99 |
| - * @return |
| 240 | + * Returns the first element of {@code this} array. |
| 241 | + * |
| 242 | + * <p>Warning: The use of this method is an assertion that |
| 243 | + * the array is not empty. |
| 244 | + * If the array is empty then the behaviour of the API is not defined. |
| 245 | + * |
| 246 | + * @return the resulting value. |
100 | 247 | */
|
101 |
| - @MqlUnchecked(NON_EMPTY) |
| 248 | + @MqlUnchecked(PRESENT) |
102 | 249 | T first();
|
103 | 250 |
|
104 | 251 | /**
|
105 |
| - * user asserts that array is not empty |
106 |
| - * @return |
| 252 | + * Returns the last element of {@code this} array. |
| 253 | + * |
| 254 | + * <p>Warning: The use of this method is an assertion that |
| 255 | + * the array is not empty. |
| 256 | + * If the array is empty then the behaviour of the API is not defined. |
| 257 | + * |
| 258 | + * @return the resulting value. |
107 | 259 | */
|
108 | 260 | T last();
|
109 | 261 |
|
110 |
| - BooleanExpression contains(T contains); |
| 262 | + /** |
| 263 | + * True if {@code this} array contains a value that is |
| 264 | + * {@linkplain #eq equal} to the provided {@code value}. |
| 265 | + * |
| 266 | + * @param value the value. |
| 267 | + * @return the resulting value. |
| 268 | + */ |
| 269 | + BooleanExpression contains(T value); |
111 | 270 |
|
112 |
| - ArrayExpression<T> concat(ArrayExpression<? extends T> array); |
| 271 | + /** |
| 272 | + * The result of concatenating {@code this} array first with |
| 273 | + * the {@code other} array ensuing. |
| 274 | + * |
| 275 | + * @param other the other array. |
| 276 | + * @return the resulting array. |
| 277 | + */ |
| 278 | + ArrayExpression<T> concat(ArrayExpression<? extends T> other); |
113 | 279 |
|
| 280 | + /** |
| 281 | + * The subarray of {@code this} array, from the {@code start} index |
| 282 | + * inclusive, and continuing for the specified {@code length}, up to |
| 283 | + * the end of the array. |
| 284 | + * |
| 285 | + * @param start start index |
| 286 | + * @param length length |
| 287 | + * @return the resulting value |
| 288 | + */ |
114 | 289 | ArrayExpression<T> slice(IntegerExpression start, IntegerExpression length);
|
115 | 290 |
|
| 291 | + /** |
| 292 | + * The subarray of {@code this} array, from the {@code start} index |
| 293 | + * inclusive, and continuing for the specified {@code length}, or |
| 294 | + * to the end of the array. |
| 295 | + * |
| 296 | + * @param start start index |
| 297 | + * @param length length |
| 298 | + * @return the resulting value |
| 299 | + */ |
116 | 300 | default ArrayExpression<T> slice(final int start, final int length) {
|
117 | 301 | return this.slice(of(start), of(length));
|
118 | 302 | }
|
119 | 303 |
|
120 |
| - ArrayExpression<T> union(ArrayExpression<? extends T> set); |
| 304 | + /** |
| 305 | + * The set-union of {@code this} array and the {@code other} array ensuing, |
| 306 | + * containing only the distinct values of both. |
| 307 | + * No guarantee is made regarding order. |
| 308 | + * |
| 309 | + * @param other the other array. |
| 310 | + * @return the resulting array. |
| 311 | + */ |
| 312 | + ArrayExpression<T> union(ArrayExpression<? extends T> other); |
| 313 | + |
121 | 314 |
|
| 315 | + /** |
| 316 | + * An array containing only the distinct values of {@code this} array. |
| 317 | + * No guarantee is made regarding order. |
| 318 | + * |
| 319 | + * @return the resulting value |
| 320 | + */ |
122 | 321 | ArrayExpression<T> distinct();
|
123 | 322 |
|
124 | 323 | /**
|
|
0 commit comments