Polishing.
Update since tags. Add missing Override annotation. See #4070 Original pull request: #4242
This commit is contained in:
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -23,7 +23,7 @@ import org.springframework.util.ObjectUtils;
|
|||||||
* A special field that points to a variable {@code $$} expression.
|
* A special field that points to a variable {@code $$} expression.
|
||||||
*
|
*
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @since 4.1
|
* @since 4.1.3
|
||||||
*/
|
*/
|
||||||
public interface AggregationVariable extends Field {
|
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()
|
* @return {@literal true} if the fields {@link #getName() name} does not match the defined {@link #getTarget()
|
||||||
* target}.
|
* target}.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
default boolean isAliased() {
|
default boolean isAliased() {
|
||||||
return !ObjectUtils.nullSafeEquals(getName(), getTarget());
|
return !ObjectUtils.nullSafeEquals(getName(), getTarget());
|
||||||
}
|
}
|
||||||
@@ -42,6 +43,7 @@ public interface AggregationVariable extends Field {
|
|||||||
return getTarget();
|
return getTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
default boolean isInternal() {
|
default boolean isInternal() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -50,7 +52,7 @@ public interface AggregationVariable extends Field {
|
|||||||
* Create a new {@link AggregationVariable} for the given name.
|
* Create a new {@link AggregationVariable} for the given name.
|
||||||
* <p>
|
* <p>
|
||||||
* Variables start with {@code $$}. If not, the given value gets prefixed with {@code $$}.
|
* Variables start with {@code $$}. If not, the given value gets prefixed with {@code $$}.
|
||||||
*
|
*
|
||||||
* @param value must not be {@literal null}.
|
* @param value must not be {@literal null}.
|
||||||
* @return new instance of {@link AggregationVariable}.
|
* @return new instance of {@link AggregationVariable}.
|
||||||
* @throws IllegalArgumentException if given value is {@literal null}.
|
* @throws IllegalArgumentException if given value is {@literal null}.
|
||||||
@@ -127,4 +129,5 @@ public interface AggregationVariable extends Field {
|
|||||||
var trimmed = variable.stripLeading();
|
var trimmed = variable.stripLeading();
|
||||||
return trimmed.startsWith(PREFIX) ? trimmed : (PREFIX + trimmed);
|
return trimmed.startsWith(PREFIX) ? trimmed : (PREFIX + trimmed);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public final class Fields implements Iterable<Field> {
|
|||||||
|
|
||||||
Assert.notNull(names, "Field names must not be null");
|
Assert.notNull(names, "Field names must not be null");
|
||||||
|
|
||||||
List<Field> fields = new ArrayList<Field>();
|
List<Field> fields = new ArrayList<>();
|
||||||
|
|
||||||
for (String name : names) {
|
for (String name : names) {
|
||||||
fields.add(field(name));
|
fields.add(field(name));
|
||||||
@@ -114,7 +114,7 @@ public final class Fields implements Iterable<Field> {
|
|||||||
|
|
||||||
private static List<Field> verify(List<Field> fields) {
|
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) {
|
for (Field field : fields) {
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ public final class Fields implements Iterable<Field> {
|
|||||||
|
|
||||||
private Fields(Fields existing, Field tail) {
|
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.addAll(existing.fields);
|
||||||
this.fields.add(tail);
|
this.fields.add(tail);
|
||||||
}
|
}
|
||||||
@@ -253,10 +253,12 @@ public final class Fields implements Iterable<Field> {
|
|||||||
return dollarIndex == -1 ? source : source.substring(dollarIndex + 1);
|
return dollarIndex == -1 ? source : source.substring(dollarIndex + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getTarget() {
|
public String getTarget() {
|
||||||
|
|
||||||
if (isLocalVar() || pointsToDBRefId()) {
|
if (isLocalVar() || pointsToDBRefId()) {
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
|
||||||
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
|
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
|
||||||
import org.springframework.expression.spel.ast.Projection;
|
import org.springframework.expression.spel.ast.Projection;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
@@ -431,6 +430,7 @@ public class ReplaceRootOperation implements FieldsExposingAggregationOperation
|
|||||||
* @param context will never be {@literal null}.
|
* @param context will never be {@literal null}.
|
||||||
* @return never {@literal null}.
|
* @return never {@literal null}.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
Document toDocument(AggregationOperationContext context);
|
Document toDocument(AggregationOperationContext context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,6 +21,8 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Unit tests for {@link AggregationVariable}.
|
||||||
|
*
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
*/
|
*/
|
||||||
class AggregationVariableUnitTests {
|
class AggregationVariableUnitTests {
|
||||||
|
|||||||
@@ -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.core.aggregation.Fields.*;
|
||||||
import static org.springframework.data.mongodb.test.util.Assertions.*;
|
import static org.springframework.data.mongodb.test.util.Assertions.*;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -483,13 +481,19 @@ public class TypeBasedAggregationOperationContextUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@org.springframework.data.mongodb.core.mapping.Document(collection = "person")
|
@org.springframework.data.mongodb.core.mapping.Document(collection = "person")
|
||||||
@AllArgsConstructor
|
|
||||||
public static class FooPerson {
|
public static class FooPerson {
|
||||||
|
|
||||||
final ObjectId id;
|
final ObjectId id;
|
||||||
final String name;
|
final String name;
|
||||||
@org.springframework.data.mongodb.core.mapping.Field("last_name") final String lastName;
|
@org.springframework.data.mongodb.core.mapping.Field("last_name") final String lastName;
|
||||||
final Age age;
|
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 {
|
public static class Age {
|
||||||
|
|||||||
Reference in New Issue
Block a user