Skip to content

Commit 63e4b61

Browse files
committed
Update and add documentation (#1059)
* Fix, tests JAVA-4799
1 parent 8229b87 commit 63e4b61

15 files changed

+516
-138
lines changed

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

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,39 @@
2121
import static com.mongodb.client.model.expressions.Expressions.of;
2222

2323
/**
24-
* Expresses an array value. An array value is a finite, ordered collection of
25-
* elements of a certain type.
24+
* An array {@link Expression value} in the context of the MongoDB Query
25+
* Language (MQL). An array is a finite, ordered collection of elements of a
26+
* certain type. It is also known as a finite mathematical sequence.
2627
*
27-
* @param <T> the type of the elements in the array
28+
* @param <T> the type of the elements
2829
*/
2930
public interface ArrayExpression<T extends Expression> extends Expression {
3031

3132
/**
32-
* Returns an array consisting of those elements in this array that match
33-
* the given predicate condition. Evaluates each expression in this array
34-
* according to the cond function. If cond evaluates to logical true, then
35-
* the element is preserved; if cond evaluates to logical false, the element
36-
* is omitted.
33+
* An array consisting of only those elements in {@code this} array that
34+
* match the provided predicate.
3735
*
38-
* @param cond the function to apply to each element
39-
* @return the new array
36+
* @param predicate the predicate to apply to each element to determine if
37+
* it should be included.
38+
* @return the resulting array.
4039
*/
41-
ArrayExpression<T> filter(Function<? super T, ? extends BooleanExpression> cond);
40+
ArrayExpression<T> filter(Function<? super T, ? extends BooleanExpression> predicate);
4241

4342
/**
44-
* Returns an array consisting of the results of applying the given function
45-
* to the elements of this array.
43+
* An array consisting of the results of applying the provided function to
44+
* the elements of {@code this} array.
4645
*
47-
* @param in the function to apply to each element
48-
* @return the new array
49-
* @param <R> the type contained in the resulting array
46+
* @param in the function to apply to each element.
47+
* @return the resulting array.
48+
* @param <R> the type of the elements of the resulting array.
5049
*/
5150
<R extends Expression> ArrayExpression<R> map(Function<? super T, ? extends R> in);
5251

52+
/**
53+
* The size of {@code this} array.
54+
*
55+
* @return the size.
56+
*/
5357
IntegerExpression size();
5458

5559
BooleanExpression any(Function<? super T, BooleanExpression> predicate);
@@ -113,7 +117,25 @@ default ArrayExpression<T> slice(final int start, final int length) {
113117

114118
ArrayExpression<T> distinct();
115119

120+
/**
121+
* The result of passing {@code this} value to the provided function.
122+
* Equivalent to {@code f.apply(this)}, and allows lambdas and static,
123+
* user-defined functions to use the chaining syntax.
124+
*
125+
* @see Expression#passTo
126+
* @param f the function to apply.
127+
* @return the resulting value.
128+
* @param <R> the type of the resulting value.
129+
*/
116130
<R extends Expression> R passArrayTo(Function<? super ArrayExpression<T>, ? extends R> f);
117131

118-
<R extends Expression> R switchArrayOn(Function<Branches<ArrayExpression<T>>, ? extends BranchesTerminal<ArrayExpression<T>, ? extends R>> on);
132+
/**
133+
* The result of applying the provided switch mapping to {@code this} value.
134+
*
135+
* @see Expression#switchOn
136+
* @param mapping the switch mapping.
137+
* @return the resulting value.
138+
* @param <R> the type of the resulting value.
139+
*/
140+
<R extends Expression> R switchArrayOn(Function<Branches<ArrayExpression<T>>, ? extends BranchesTerminal<ArrayExpression<T>, ? extends R>> mapping);
119141
}

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
import java.util.function.Function;
2020

2121
/**
22-
* A logical boolean value, either true or false.
22+
* A boolean {@linkplain Expression value} in the context of the
23+
* MongoDB Query Language (MQL).
2324
*/
2425
public interface BooleanExpression extends Expression {
2526

@@ -45,20 +46,37 @@ public interface BooleanExpression extends Expression {
4546
* @return the resulting value.
4647
*/
4748
BooleanExpression and(BooleanExpression other);
48-
// TODO-END check the evaluation semantics of and/or
4949

5050
/**
51-
* The {@code left} branch when {@code this} is true,
52-
* and the {@code right} branch otherwise.
51+
* The {@code ifTrue} value when {@code this} is true,
52+
* and the {@code ifFalse} value otherwise.
5353
*
54-
* @param left the left branch.
55-
* @param right the right branch.
54+
* @param ifTrue the ifTrue value.
55+
* @param ifFalse the ifFalse value.
5656
* @return the resulting value.
5757
* @param <T> The type of the resulting expression.
5858
*/
59-
<T extends Expression> T cond(T left, T right);
59+
<T extends Expression> T cond(T ifTrue, T ifFalse);
6060

61+
/**
62+
* The result of passing {@code this} value to the provided function.
63+
* Equivalent to {@code f.apply(this)}, and allows lambdas and static,
64+
* user-defined functions to use the chaining syntax.
65+
*
66+
* @see Expression#passTo
67+
* @param f the function to apply.
68+
* @return the resulting value.
69+
* @param <R> the type of the resulting value.
70+
*/
6171
<R extends Expression> R passBooleanTo(Function<? super BooleanExpression, ? extends R> f);
6272

63-
<R extends Expression> R switchBooleanOn(Function<Branches<BooleanExpression>, ? extends BranchesTerminal<BooleanExpression, ? extends R>> on);
73+
/**
74+
* The result of applying the provided switch mapping to {@code this} value.
75+
*
76+
* @see Expression#switchOn
77+
* @param mapping the switch mapping.
78+
* @return the resulting value.
79+
* @param <R> the type of the resulting value.
80+
*/
81+
<R extends Expression> R switchBooleanOn(Function<Branches<BooleanExpression>, ? extends BranchesTerminal<BooleanExpression, ? extends R>> mapping);
6482
}

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
import java.util.function.Function;
2020

2121
/**
22-
* An instantaneous date and time. Tracks a UTC datetime, the number of
23-
* milliseconds since the Unix epoch. Does not track the timezone.
22+
* A UTC date-time {@linkplain Expression value} in the context
23+
* of the MongoDB Query Language (MQL). Tracks the number of
24+
* milliseconds since the Unix epoch, and does not track the timezone.
25+
*
26+
* @mongodb.driver.manual reference/operator/aggregation/dateToString/ Format Specifiers, UTC Offset, and Olson Timezone Identifier
2427
*/
2528
public interface DateExpression extends Expression {
2629

@@ -123,11 +126,30 @@ public interface DateExpression extends Expression {
123126
* provided {@code timezone}, and formatted according to the {@code format}.
124127
*
125128
* @param timezone the UTC Offset or Olson Timezone Identifier.
126-
* @param format the format specifier. TODO-END what standard is this?
129+
* @param format the format specifier.
127130
* @return the resulting value.
128131
*/
129132
StringExpression asString(StringExpression timezone, StringExpression format);
130133

134+
/**
135+
* The result of passing {@code this} value to the provided function.
136+
* Equivalent to {@code f.apply(this)}, and allows lambdas and static,
137+
* user-defined functions to use the chaining syntax.
138+
*
139+
* @see Expression#passTo
140+
* @param f the function to apply.
141+
* @return the resulting value.
142+
* @param <R> the type of the resulting value.
143+
*/
131144
<R extends Expression> R passDateTo(Function<? super DateExpression, ? extends R> f);
132-
<R extends Expression> R switchDateOn(Function<Branches<DateExpression>, ? extends BranchesTerminal<DateExpression, ? extends R>> on);
145+
146+
/**
147+
* The result of applying the provided switch mapping to {@code this} value.
148+
*
149+
* @see Expression#switchOn
150+
* @param mapping the switch mapping.
151+
* @return the resulting value.
152+
* @param <R> the type of the resulting value.
153+
*/
154+
<R extends Expression> R switchDateOn(Function<Branches<DateExpression>, ? extends BranchesTerminal<DateExpression, ? extends R>> mapping);
133155
}

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,25 @@ default <T extends Expression> MapExpression<T> getMap(final String fieldName, f
102102

103103
MapExpression<Expression> asMap();
104104

105+
/**
106+
* The result of passing {@code this} value to the provided function.
107+
* Equivalent to {@code f.apply(this)}, and allows lambdas and static,
108+
* user-defined functions to use the chaining syntax.
109+
*
110+
* @see Expression#passTo
111+
* @param f the function to apply.
112+
* @return the resulting value.
113+
* @param <R> the type of the resulting value.
114+
*/
105115
<R extends Expression> R passDocumentTo(Function<? super DocumentExpression, ? extends R> f);
106-
<R extends Expression> R switchDocumentOn(Function<Branches<DocumentExpression>, ? extends BranchesTerminal<DocumentExpression, ? extends R>> on);
116+
117+
/**
118+
* The result of applying the provided switch mapping to {@code this} value.
119+
*
120+
* @see Expression#switchOn
121+
* @param mapping the switch mapping.
122+
* @return the resulting value.
123+
* @param <R> the type of the resulting value.
124+
*/
125+
<R extends Expression> R switchDocumentOn(Function<Branches<DocumentExpression>, ? extends BranchesTerminal<DocumentExpression, ? extends R>> mapping);
107126
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818

1919
import static com.mongodb.client.model.expressions.Expressions.of;
2020

21+
/**
22+
* A map entry {@linkplain Expression value} in the context
23+
* of the MongoDB Query Language (MQL). An entry has a
24+
* {@linkplain StringExpression string} key and some
25+
* {@linkplain Expression value}. Entries are used with
26+
* {@linkplain MapExpression maps}.
27+
*
28+
* Entries are {@linkplain Expression#isDocumentOr document-like} and
29+
* {@linkplain Expression#isMapOr map-like}, unless the method returning the
30+
* entry specifies otherwise.
31+
*
32+
* @param <T> The type of the value
33+
*/
2134
public interface EntryExpression<T extends Expression> extends Expression {
2235
StringExpression getKey();
2336

0 commit comments

Comments
 (0)