From 1408d5106500a30a60a0ca100cbb3ffd1b0c326d Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 23 Mar 2015 09:23:12 +0100 Subject: [PATCH] DATAMONGO-979 - Polishing. Minor JavaDoc and code style polishes. Original pull request: #272. --- .../aggregation/AggregationExpression.java | 10 +++++--- .../AggregationFunctionExpressions.java | 25 +++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationExpression.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationExpression.java index 3944bcfdf..c25ae17ba 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationExpression.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationExpression.java @@ -18,14 +18,18 @@ package org.springframework.data.mongodb.core.aggregation; import com.mongodb.DBObject; /** - * An {@link AggregationExpression} can be used with field expressions in aggregation pipeline stages like {@code project} and - * {@code group}. + * An {@link AggregationExpression} can be used with field expressions in aggregation pipeline stages like + * {@code project} and {@code group}. * * @author Thomas Darimont + * @author Oliver Gierke */ -public interface AggregationExpression { +interface AggregationExpression { /** + * Turns the {@link AggregationExpression} into a {@link DBObject} within the given + * {@link AggregationOperationContext}. + * * @param context * @return */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationFunctionExpressions.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationFunctionExpressions.java index 51cfc241b..8f3525c03 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationFunctionExpressions.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationFunctionExpressions.java @@ -27,6 +27,7 @@ import com.mongodb.DBObject; * An enum of supported {@link AggregationExpression}s in aggregation pipeline stages. * * @author Thomas Darimont + * @author Oliver Gierke * @since 1.10 */ public enum AggregationFunctionExpressions { @@ -34,22 +35,22 @@ public enum AggregationFunctionExpressions { SIZE; /** - * Returns an {@link AggregationExpression} build from the current {@link Enum} name and the given {@code params}. + * Returns an {@link AggregationExpression} build from the current {@link Enum} name and the given parameters. * - * @param params must not be {@literal null} + * @param parameters must not be {@literal null} * @return */ - public AggregationExpression of(Object... params) { + public AggregationExpression of(Object... parameters) { - Assert.notNull(params, "Params must not be null!"); - - return new FunctionExpression(name().toLowerCase(), params); + Assert.notNull(parameters, "Parameters must not be null!"); + return new FunctionExpression(name().toLowerCase(), parameters); } /** * An {@link AggregationExpression} representing a function call. * * @author Thomas Darimont + * @author Oliver Gierke * @since 1.10 */ static class FunctionExpression implements AggregationExpression { @@ -57,6 +58,12 @@ public enum AggregationFunctionExpressions { private final String name; private final Object[] values; + /** + * Creates a new {@link FunctionExpression} for the given name and values. + * + * @param name must not be {@literal null} or empty. + * @param values must not be {@literal null}. + */ public FunctionExpression(String name, Object[] values) { Assert.hasText(name, "Name must not be null!"); @@ -66,13 +73,15 @@ public enum AggregationFunctionExpressions { this.values = values; } - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.springframework.data.mongodb.core.aggregation.Expression#toDbObject(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext) */ @Override public DBObject toDbObject(AggregationOperationContext context) { List args = new ArrayList(values.length); + for (int i = 0; i < values.length; i++) { args.add(unpack(values[i], context)); } @@ -80,7 +89,7 @@ public enum AggregationFunctionExpressions { return new BasicDBObject("$" + name, args); } - private Object unpack(Object value, AggregationOperationContext context) { + private static Object unpack(Object value, AggregationOperationContext context) { if (value instanceof AggregationExpression) { return ((AggregationExpression) value).toDbObject(context);