DATAMONGO-2053 - Polishing.
Tweak Javadoc. Surpress generics warnings. Remove nullable annotation from ObjectOperatorFactory.value as it cannot be null. Extend tests. Reformat. Original pull request: #601.
This commit is contained in:
@@ -93,7 +93,7 @@ abstract class AbstractAggregationExpression implements AggregationExpression {
|
||||
return targetDocument;
|
||||
}
|
||||
|
||||
if(value instanceof SystemVariable) {
|
||||
if (value instanceof SystemVariable) {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,10 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Abstraction for
|
||||
* Gateway for
|
||||
* <a href="https://docs.mongodb.com/manual/meta/aggregation-quick-reference/#object-expression-operators">object
|
||||
* expression operators</a>.
|
||||
*
|
||||
@@ -57,7 +56,7 @@ public class ObjectOperators {
|
||||
*/
|
||||
public static class ObjectOperatorFactory {
|
||||
|
||||
@Nullable private final Object value;
|
||||
private final Object value;
|
||||
|
||||
/**
|
||||
* Creates new {@link ObjectOperatorFactory} for given {@literal value}.
|
||||
@@ -67,6 +66,7 @@ public class ObjectOperators {
|
||||
public ObjectOperatorFactory(Object value) {
|
||||
|
||||
Assert.notNull(value, "Value must not be null!");
|
||||
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class ObjectOperators {
|
||||
|
||||
/**
|
||||
* Creates new {@link MergeObjects aggregation expression} that takes the associated value and combines it with the
|
||||
* given values into a single document. <br />
|
||||
* given values (documents or mapped objects) into a single document. <br />
|
||||
* <strong>NOTE:</strong> Requires MongoDB 4.0 or later.
|
||||
*
|
||||
* @return new instance of {@link MergeObjects}.
|
||||
@@ -186,7 +186,7 @@ public class ObjectOperators {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new {@link MergeObjects aggregation expression} by adding the given values.
|
||||
* Creates new {@link MergeObjects aggregation expression} by adding the given values (documents or mapped objects).
|
||||
*
|
||||
* @param values must not be {@literal null}.
|
||||
* @return new instance of {@link MergeObjects}.
|
||||
@@ -204,11 +204,12 @@ public class ObjectOperators {
|
||||
return super.toDocument(potentiallyExtractSingleValue(value), context);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object potentiallyExtractSingleValue(Object value) {
|
||||
|
||||
if (value instanceof Collection) {
|
||||
|
||||
Collection<Object> collection = ((Collection) value);
|
||||
Collection<Object> collection = ((Collection<Object>) value);
|
||||
if (collection.size() == 1) {
|
||||
return collection.iterator().next();
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.data.mongodb.core.aggregation.ObjectOperators.MergeOb
|
||||
* Unit tests for {@link ObjectOperators}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @currentRead Royal Assassin - Robin Hobb
|
||||
*/
|
||||
public class ObjectOperatorsUnitTests {
|
||||
@@ -67,8 +68,9 @@ public class ObjectOperatorsUnitTests {
|
||||
public void mergeMixed() {
|
||||
|
||||
assertThat(
|
||||
ObjectOperators.valueOf("kettricken").mergeWithValuesOf(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT))
|
||||
.isEqualTo(Document.parse("{ $mergeObjects: [ \"$kettricken\", " + EXPRESSION_STRING + " ] } "));
|
||||
ObjectOperators.valueOf("kettricken").mergeWithValuesOf(EXPRESSION).mergeWithValuesOf("verity")
|
||||
.toDocument(Aggregation.DEFAULT_CONTEXT)).isEqualTo(
|
||||
Document.parse("{ $mergeObjects: [ \"$kettricken\", " + EXPRESSION_STRING + ", \"$verity\" ] } "));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2053
|
||||
|
||||
Reference in New Issue
Block a user