* The {@code name} serves as an alias for the actual backing document field denoted by {@code target}. If no target
* is set explicitly, the name will be used as target.
- *
+ *
* @param name must not be {@literal null} or empty
* @param target
*/
- public AggregationField(String name, String target) {
+ public AggregationField(String name, @Nullable String target) {
raw = name;
- String nameToSet = cleanUp(name);
- String targetToSet = cleanUp(target);
+ String nameToSet = name != null ? cleanUp(name) : null;
+ String targetToSet = target != null ? cleanUp(target) : null;
Assert.hasText(nameToSet, "AggregationField name must not be null or empty!");
@@ -241,11 +243,7 @@ public final class Fields implements Iterable
* We recommend to use the static factory method {@link Aggregation#group(Fields)} instead of creating instances of this
* class directly.
- *
+ *
* @author Sebastian Herold
* @author Thomas Darimont
* @author Oliver Gierke
* @author Gustavo de Geus
* @author Christoph Strobl
+ * @author Mark Paluch
* @since 1.3
* @see MongoDB Aggregation Framework: $group
*/
@@ -52,7 +52,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Creates a new {@link GroupOperation} including the given {@link Fields}.
- *
+ *
* @param fields must not be {@literal null}.
*/
public GroupOperation(Fields fields) {
@@ -63,7 +63,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Creates a new {@link GroupOperation} from the given {@link GroupOperation}.
- *
+ *
* @param groupOperation must not be {@literal null}.
*/
protected GroupOperation(GroupOperation groupOperation) {
@@ -72,7 +72,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Creates a new {@link GroupOperation} from the given {@link GroupOperation} and the given {@link Operation}s.
- *
+ *
* @param groupOperation
* @param nextOperations
*/
@@ -89,7 +89,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Creates a new {@link GroupOperation} from the current one adding the given {@link Operation}.
- *
+ *
* @param operation must not be {@literal null}.
* @return
*/
@@ -99,7 +99,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Builder for {@link GroupOperation}s on a field.
- *
+ *
* @author Thomas Darimont
*/
public static final class GroupOperationBuilder {
@@ -109,7 +109,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Creates a new {@link GroupOperationBuilder} from the given {@link GroupOperation} and {@link Operation}.
- *
+ *
* @param groupOperation
* @param operation
*/
@@ -124,7 +124,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Allows to specify an alias for the new-operation operation.
- *
+ *
* @param alias
* @return
*/
@@ -138,7 +138,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
*
* Count expressions are emulated via {@code $sum: 1}.
*
- *
+ *
* @return
*/
public GroupOperationBuilder count() {
@@ -147,7 +147,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Generates an {@link GroupOperationBuilder} for a {@code $sum}-expression for the given field-reference.
- *
+ *
* @param reference
* @return
*/
@@ -155,13 +155,13 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
return sum(reference, null);
}
- private GroupOperationBuilder sum(String reference, Object value) {
+ private GroupOperationBuilder sum(@Nullable String reference, @Nullable Object value) {
return newBuilder(GroupOps.SUM, reference, value);
}
/**
* Generates an {@link GroupOperationBuilder} for an {@code $add_to_set}-expression for the given field-reference.
- *
+ *
* @param reference
* @return
*/
@@ -171,7 +171,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Generates an {@link GroupOperationBuilder} for an {@code $add_to_set}-expression for the given value.
- *
+ *
* @param value
* @return
*/
@@ -179,13 +179,13 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
return addToSet(null, value);
}
- private GroupOperationBuilder addToSet(String reference, Object value) {
+ private GroupOperationBuilder addToSet(@Nullable String reference, @Nullable Object value) {
return newBuilder(GroupOps.ADD_TO_SET, reference, value);
}
/**
* Generates an {@link GroupOperationBuilder} for an {@code $last}-expression for the given field-reference.
- *
+ *
* @param reference
* @return
*/
@@ -196,7 +196,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Generates an {@link GroupOperationBuilder} for an {@code $last}-expression for the given
* {@link AggregationExpression}.
- *
+ *
* @param expr
* @return
*/
@@ -206,7 +206,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Generates an {@link GroupOperationBuilder} for a {@code $first}-expression for the given field-reference.
- *
+ *
* @param reference
* @return
*/
@@ -217,7 +217,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Generates an {@link GroupOperationBuilder} for a {@code $first}-expression for the given
* {@link AggregationExpression}.
- *
+ *
* @param expr
* @return
*/
@@ -227,7 +227,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Generates an {@link GroupOperationBuilder} for an {@code $avg}-expression for the given field-reference.
- *
+ *
* @param reference
* @return
*/
@@ -238,7 +238,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Generates an {@link GroupOperationBuilder} for an {@code $avg}-expression for the given
* {@link AggregationExpression}.
- *
+ *
* @param expr
* @return
*/
@@ -248,7 +248,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Generates an {@link GroupOperationBuilder} for an {@code $push}-expression for the given field-reference.
- *
+ *
* @param reference
* @return
*/
@@ -258,7 +258,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Generates an {@link GroupOperationBuilder} for an {@code $push}-expression for the given value.
- *
+ *
* @param value
* @return
*/
@@ -266,13 +266,13 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
return push(null, value);
}
- private GroupOperationBuilder push(String reference, Object value) {
+ private GroupOperationBuilder push(@Nullable String reference, @Nullable Object value) {
return newBuilder(GroupOps.PUSH, reference, value);
}
/**
* Generates an {@link GroupOperationBuilder} for an {@code $min}-expression that for the given field-reference.
- *
+ *
* @param reference
* @return
*/
@@ -283,7 +283,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Generates an {@link GroupOperationBuilder} for an {@code $min}-expression that for the given
* {@link AggregationExpression}.
- *
+ *
* @param expr
* @return
*/
@@ -293,7 +293,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Generates an {@link GroupOperationBuilder} for an {@code $max}-expression that for the given field-reference.
- *
+ *
* @param reference
* @return
*/
@@ -304,7 +304,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
/**
* Generates an {@link GroupOperationBuilder} for an {@code $max}-expression that for the given
* {@link AggregationExpression}.
- *
+ *
* @param expr
* @return
*/
@@ -325,7 +325,8 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
}
/**
- * Generates an {@link GroupOperationBuilder} for an {@code $stdDevSamp}-expression that for the given {@link AggregationExpression}.
+ * Generates an {@link GroupOperationBuilder} for an {@code $stdDevSamp}-expression that for the given
+ * {@link AggregationExpression}.
*
* @param expr must not be {@literal null}.
* @return never {@literal null}.
@@ -347,7 +348,8 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
}
/**
- * Generates an {@link GroupOperationBuilder} for an {@code $stdDevPop}-expression that for the given {@link AggregationExpression}.
+ * Generates an {@link GroupOperationBuilder} for an {@code $stdDevPop}-expression that for the given
+ * {@link AggregationExpression}.
*
* @param expr must not be {@literal null}.
* @return never {@literal null}.
@@ -357,11 +359,11 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
return newBuilder(GroupOps.STD_DEV_POP, null, expr);
}
- private GroupOperationBuilder newBuilder(Keyword keyword, String reference, Object value) {
+ private GroupOperationBuilder newBuilder(Keyword keyword, @Nullable String reference, @Nullable Object value) {
return new GroupOperationBuilder(this, new Operation(keyword, null, reference, value));
}
- /*
+ /*
* (non-Javadoc)
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperationContext#getFields()
*/
@@ -421,7 +423,8 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
private static enum GroupOps implements Keyword {
- SUM("$sum"), LAST("$last"), FIRST("$first"), PUSH("$push"), AVG("$avg"), MIN("$min"), MAX("$max"), ADD_TO_SET("$addToSet"), STD_DEV_POP("$stdDevPop"), STD_DEV_SAMP("$stdDevSamp");
+ SUM("$sum"), LAST("$last"), FIRST("$first"), PUSH("$push"), AVG("$avg"), MIN("$min"), MAX("$max"), ADD_TO_SET(
+ "$addToSet"), STD_DEV_POP("$stdDevPop"), STD_DEV_SAMP("$stdDevSamp");
private String mongoOperator;
@@ -429,7 +432,6 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
this.mongoOperator = mongoOperator;
}
-
@Override
public String toString() {
return mongoOperator;
@@ -439,11 +441,11 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
static class Operation implements AggregationOperation {
private final Keyword op;
- private final String key;
- private final String reference;
- private final Object value;
+ private final @Nullable String key;
+ private final @Nullable String reference;
+ private final @Nullable Object value;
- public Operation(Keyword op, String key, String reference, Object value) {
+ public Operation(Keyword op, @Nullable String key, @Nullable String reference, @Nullable Object value) {
this.op = op;
this.key = key;
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperation.java
index f5d512131..2d868313f 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperation.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperation.java
@@ -22,13 +22,13 @@ import java.util.Collections;
import java.util.List;
import org.bson.Document;
-import org.springframework.data.mongodb.core.aggregation.VariableOperators.Let.ExpressionVariable;
import org.springframework.data.mongodb.core.aggregation.ConditionalOperators.Cond;
import org.springframework.data.mongodb.core.aggregation.ConditionalOperators.IfNull;
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
import org.springframework.data.mongodb.core.aggregation.Fields.AggregationField;
import org.springframework.data.mongodb.core.aggregation.ProjectionOperation.ProjectionOperationBuilder.FieldProjection;
import org.springframework.data.mongodb.core.aggregation.VariableOperators.Let.ExpressionVariable;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -39,14 +39,15 @@ import org.springframework.util.Assert;
*
* We recommend to use the static factory method {@link Aggregation#project(Fields)} instead of creating instances of
* this class directly.
- *
+ *
* @author Tobias Trelle
* @author Thomas Darimont
* @author Oliver Gierke
* @author Christoph Strobl
* @author Mark Paluch
* @since 1.3
- * @see MongoDB Aggregation Framework: $project
+ * @see MongoDB Aggregation Framework:
+ * $project
*/
public class ProjectionOperation implements FieldsExposingAggregationOperation {
@@ -65,7 +66,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
/**
* Creates a new {@link ProjectionOperation} including the given {@link Fields}.
- *
+ *
* @param fields must not be {@literal null}.
*/
public ProjectionOperation(Fields fields) {
@@ -75,7 +76,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
/**
* Copy constructor to allow building up {@link ProjectionOperation} instances from already existing
* {@link Projection}s.
- *
+ *
* @param current must not be {@literal null}.
* @param projections must not be {@literal null}.
*/
@@ -91,18 +92,18 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
/**
* Creates a new {@link ProjectionOperation} with the current {@link Projection}s and the given one.
- *
+ *
* @param projection must not be {@literal null}.
* @return
*/
private ProjectionOperation and(Projection projection) {
- return new ProjectionOperation(this.projections, Arrays.asList(projection));
+ return new ProjectionOperation(this.projections, Collections.singletonList(projection));
}
/**
* Creates a new {@link ProjectionOperation} with the current {@link Projection}s replacing the last current one with
* the given one.
- *
+ *
* @param projection must not be {@literal null}.
* @return
*/
@@ -110,12 +111,12 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
List