DATAMONGO-979 - Polishing.
Minor JavaDoc and code style polishes. Original pull request: #272.
This commit is contained in:
@@ -18,14 +18,18 @@ package org.springframework.data.mongodb.core.aggregation;
|
|||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link AggregationExpression} can be used with field expressions in aggregation pipeline stages like {@code project} and
|
* An {@link AggregationExpression} can be used with field expressions in aggregation pipeline stages like
|
||||||
* {@code group}.
|
* {@code project} and {@code group}.
|
||||||
*
|
*
|
||||||
* @author Thomas Darimont
|
* @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
|
* @param context
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import com.mongodb.DBObject;
|
|||||||
* An enum of supported {@link AggregationExpression}s in aggregation pipeline stages.
|
* An enum of supported {@link AggregationExpression}s in aggregation pipeline stages.
|
||||||
*
|
*
|
||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
|
* @author Oliver Gierke
|
||||||
* @since 1.10
|
* @since 1.10
|
||||||
*/
|
*/
|
||||||
public enum AggregationFunctionExpressions {
|
public enum AggregationFunctionExpressions {
|
||||||
@@ -34,22 +35,22 @@ public enum AggregationFunctionExpressions {
|
|||||||
SIZE;
|
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
|
* @return
|
||||||
*/
|
*/
|
||||||
public AggregationExpression of(Object... params) {
|
public AggregationExpression of(Object... parameters) {
|
||||||
|
|
||||||
Assert.notNull(params, "Params must not be null!");
|
Assert.notNull(parameters, "Parameters must not be null!");
|
||||||
|
return new FunctionExpression(name().toLowerCase(), parameters);
|
||||||
return new FunctionExpression(name().toLowerCase(), params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link AggregationExpression} representing a function call.
|
* An {@link AggregationExpression} representing a function call.
|
||||||
*
|
*
|
||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
|
* @author Oliver Gierke
|
||||||
* @since 1.10
|
* @since 1.10
|
||||||
*/
|
*/
|
||||||
static class FunctionExpression implements AggregationExpression {
|
static class FunctionExpression implements AggregationExpression {
|
||||||
@@ -57,6 +58,12 @@ public enum AggregationFunctionExpressions {
|
|||||||
private final String name;
|
private final String name;
|
||||||
private final Object[] values;
|
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) {
|
public FunctionExpression(String name, Object[] values) {
|
||||||
|
|
||||||
Assert.hasText(name, "Name must not be null!");
|
Assert.hasText(name, "Name must not be null!");
|
||||||
@@ -66,13 +73,15 @@ public enum AggregationFunctionExpressions {
|
|||||||
this.values = values;
|
this.values = values;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
* @see org.springframework.data.mongodb.core.aggregation.Expression#toDbObject(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)
|
* @see org.springframework.data.mongodb.core.aggregation.Expression#toDbObject(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public DBObject toDbObject(AggregationOperationContext context) {
|
public DBObject toDbObject(AggregationOperationContext context) {
|
||||||
|
|
||||||
List<Object> args = new ArrayList<Object>(values.length);
|
List<Object> args = new ArrayList<Object>(values.length);
|
||||||
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
for (int i = 0; i < values.length; i++) {
|
||||||
args.add(unpack(values[i], context));
|
args.add(unpack(values[i], context));
|
||||||
}
|
}
|
||||||
@@ -80,7 +89,7 @@ public enum AggregationFunctionExpressions {
|
|||||||
return new BasicDBObject("$" + name, args);
|
return new BasicDBObject("$" + name, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object unpack(Object value, AggregationOperationContext context) {
|
private static Object unpack(Object value, AggregationOperationContext context) {
|
||||||
|
|
||||||
if (value instanceof AggregationExpression) {
|
if (value instanceof AggregationExpression) {
|
||||||
return ((AggregationExpression) value).toDbObject(context);
|
return ((AggregationExpression) value).toDbObject(context);
|
||||||
|
|||||||
Reference in New Issue
Block a user