Browse Source

Polishing.

Update since tags. Add missing Override annotation.

See #4070
Original pull request: #4242
4.1.x
Mark Paluch 2 years ago
parent
commit
9a68ee4e7f
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 9
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationVariable.java
  2. 8
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Fields.java
  3. 2
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ReplaceRootOperation.java
  4. 4
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationVariableUnitTests.java
  5. 10
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/TypeBasedAggregationOperationContextUnitTests.java

9
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationVariable.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2022 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -23,7 +23,7 @@ import org.springframework.util.ObjectUtils; @@ -23,7 +23,7 @@ import org.springframework.util.ObjectUtils;
* A special field that points to a variable {@code $$} expression.
*
* @author Christoph Strobl
* @since 4.1
* @since 4.1.3
*/
public interface AggregationVariable extends Field {
@ -33,6 +33,7 @@ public interface AggregationVariable extends Field { @@ -33,6 +33,7 @@ public interface AggregationVariable extends Field {
* @return {@literal true} if the fields {@link #getName() name} does not match the defined {@link #getTarget()
* target}.
*/
@Override
default boolean isAliased() {
return !ObjectUtils.nullSafeEquals(getName(), getTarget());
}
@ -42,6 +43,7 @@ public interface AggregationVariable extends Field { @@ -42,6 +43,7 @@ public interface AggregationVariable extends Field {
return getTarget();
}
@Override
default boolean isInternal() {
return false;
}
@ -50,7 +52,7 @@ public interface AggregationVariable extends Field { @@ -50,7 +52,7 @@ public interface AggregationVariable extends Field {
* Create a new {@link AggregationVariable} for the given name.
* <p>
* Variables start with {@code $$}. If not, the given value gets prefixed with {@code $$}.
*
*
* @param value must not be {@literal null}.
* @return new instance of {@link AggregationVariable}.
* @throws IllegalArgumentException if given value is {@literal null}.
@ -127,4 +129,5 @@ public interface AggregationVariable extends Field { @@ -127,4 +129,5 @@ public interface AggregationVariable extends Field {
var trimmed = variable.stripLeading();
return trimmed.startsWith(PREFIX) ? trimmed : (PREFIX + trimmed);
}
}

8
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Fields.java

@ -67,7 +67,7 @@ public final class Fields implements Iterable<Field> { @@ -67,7 +67,7 @@ public final class Fields implements Iterable<Field> {
Assert.notNull(names, "Field names must not be null");
List<Field> fields = new ArrayList<Field>();
List<Field> fields = new ArrayList<>();
for (String name : names) {
fields.add(field(name));
@ -114,7 +114,7 @@ public final class Fields implements Iterable<Field> { @@ -114,7 +114,7 @@ public final class Fields implements Iterable<Field> {
private static List<Field> verify(List<Field> fields) {
Map<String, Field> reference = new HashMap<String, Field>();
Map<String, Field> reference = new HashMap<>();
for (Field field : fields) {
@ -133,7 +133,7 @@ public final class Fields implements Iterable<Field> { @@ -133,7 +133,7 @@ public final class Fields implements Iterable<Field> {
private Fields(Fields existing, Field tail) {
this.fields = new ArrayList<Field>(existing.fields.size() + 1);
this.fields = new ArrayList<>(existing.fields.size() + 1);
this.fields.addAll(existing.fields);
this.fields.add(tail);
}
@ -253,10 +253,12 @@ public final class Fields implements Iterable<Field> { @@ -253,10 +253,12 @@ public final class Fields implements Iterable<Field> {
return dollarIndex == -1 ? source : source.substring(dollarIndex + 1);
}
@Override
public String getName() {
return name;
}
@Override
public String getTarget() {
if (isLocalVar() || pointsToDBRefId()) {

2
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ReplaceRootOperation.java

@ -21,7 +21,6 @@ import java.util.Collections; @@ -21,7 +21,6 @@ import java.util.Collections;
import java.util.List;
import org.bson.Document;
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
import org.springframework.expression.spel.ast.Projection;
import org.springframework.util.Assert;
@ -431,6 +430,7 @@ public class ReplaceRootOperation implements FieldsExposingAggregationOperation @@ -431,6 +430,7 @@ public class ReplaceRootOperation implements FieldsExposingAggregationOperation
* @param context will never be {@literal null}.
* @return never {@literal null}.
*/
@Override
Document toDocument(AggregationOperationContext context);
}

4
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationVariableUnitTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2022 the original author or authors.
* Copyright 2022-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,6 +21,8 @@ import org.junit.jupiter.api.Test; @@ -21,6 +21,8 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
/**
* Unit tests for {@link AggregationVariable}.
*
* @author Christoph Strobl
*/
class AggregationVariableUnitTests {

10
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/TypeBasedAggregationOperationContextUnitTests.java

@ -20,8 +20,6 @@ import static org.springframework.data.mongodb.core.aggregation.Aggregation.*; @@ -20,8 +20,6 @@ import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
import static org.springframework.data.mongodb.core.aggregation.Fields.*;
import static org.springframework.data.mongodb.test.util.Assertions.*;
import lombok.AllArgsConstructor;
import java.util.Arrays;
import java.util.List;
@ -483,13 +481,19 @@ public class TypeBasedAggregationOperationContextUnitTests { @@ -483,13 +481,19 @@ public class TypeBasedAggregationOperationContextUnitTests {
}
@org.springframework.data.mongodb.core.mapping.Document(collection = "person")
@AllArgsConstructor
public static class FooPerson {
final ObjectId id;
final String name;
@org.springframework.data.mongodb.core.mapping.Field("last_name") final String lastName;
final Age age;
public FooPerson(ObjectId id, String name, String lastName, Age age) {
this.id = id;
this.name = name;
this.lastName = lastName;
this.age = age;
}
}
public static class Age {

Loading…
Cancel
Save