Skip to content

Commit 9a68ee4

Browse files
committed
Polishing.
Update since tags. Add missing Override annotation. See #4070 Original pull request: #4242
1 parent 7517527 commit 9a68ee4

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
2323
* A special field that points to a variable {@code $$} expression.
2424
*
2525
* @author Christoph Strobl
26-
* @since 4.1
26+
* @since 4.1.3
2727
*/
2828
public interface AggregationVariable extends Field {
2929

@@ -33,6 +33,7 @@ public interface AggregationVariable extends Field {
3333
* @return {@literal true} if the fields {@link #getName() name} does not match the defined {@link #getTarget()
3434
* target}.
3535
*/
36+
@Override
3637
default boolean isAliased() {
3738
return !ObjectUtils.nullSafeEquals(getName(), getTarget());
3839
}
@@ -42,6 +43,7 @@ default String getName() {
4243
return getTarget();
4344
}
4445

46+
@Override
4547
default boolean isInternal() {
4648
return false;
4749
}
@@ -50,7 +52,7 @@ default boolean isInternal() {
5052
* Create a new {@link AggregationVariable} for the given name.
5153
* <p>
5254
* Variables start with {@code $$}. If not, the given value gets prefixed with {@code $$}.
53-
*
55+
*
5456
* @param value must not be {@literal null}.
5557
* @return new instance of {@link AggregationVariable}.
5658
* @throws IllegalArgumentException if given value is {@literal null}.
@@ -127,4 +129,5 @@ private static String prefixVariable(String variable) {
127129
var trimmed = variable.stripLeading();
128130
return trimmed.startsWith(PREFIX) ? trimmed : (PREFIX + trimmed);
129131
}
132+
130133
}

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static Fields fields(String... names) {
6767

6868
Assert.notNull(names, "Field names must not be null");
6969

70-
List<Field> fields = new ArrayList<Field>();
70+
List<Field> fields = new ArrayList<>();
7171

7272
for (String name : names) {
7373
fields.add(field(name));
@@ -114,7 +114,7 @@ private Fields(List<Field> fields) {
114114

115115
private static List<Field> verify(List<Field> fields) {
116116

117-
Map<String, Field> reference = new HashMap<String, Field>();
117+
Map<String, Field> reference = new HashMap<>();
118118

119119
for (Field field : fields) {
120120

@@ -133,7 +133,7 @@ private static List<Field> verify(List<Field> fields) {
133133

134134
private Fields(Fields existing, Field tail) {
135135

136-
this.fields = new ArrayList<Field>(existing.fields.size() + 1);
136+
this.fields = new ArrayList<>(existing.fields.size() + 1);
137137
this.fields.addAll(existing.fields);
138138
this.fields.add(tail);
139139
}
@@ -253,10 +253,12 @@ private static String cleanUp(String source) {
253253
return dollarIndex == -1 ? source : source.substring(dollarIndex + 1);
254254
}
255255

256+
@Override
256257
public String getName() {
257258
return name;
258259
}
259260

261+
@Override
260262
public String getTarget() {
261263

262264
if (isLocalVar() || pointsToDBRefId()) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.List;
2222

2323
import org.bson.Document;
24-
2524
import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
2625
import org.springframework.expression.spel.ast.Projection;
2726
import org.springframework.util.Assert;
@@ -431,6 +430,7 @@ private interface ReplacementContributor extends AggregationExpression {
431430
* @param context will never be {@literal null}.
432431
* @return never {@literal null}.
433432
*/
433+
@Override
434434
Document toDocument(AggregationOperationContext context);
435435
}
436436

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@
2121
import org.mockito.Mockito;
2222

2323
/**
24+
* Unit tests for {@link AggregationVariable}.
25+
*
2426
* @author Christoph Strobl
2527
*/
2628
class AggregationVariableUnitTests {

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import static org.springframework.data.mongodb.core.aggregation.Fields.*;
2121
import static org.springframework.data.mongodb.test.util.Assertions.*;
2222

23-
import lombok.AllArgsConstructor;
24-
2523
import java.util.Arrays;
2624
import java.util.List;
2725

@@ -483,13 +481,19 @@ void rendersLocalVariables() {
483481
}
484482

485483
@org.springframework.data.mongodb.core.mapping.Document(collection = "person")
486-
@AllArgsConstructor
487484
public static class FooPerson {
488485

489486
final ObjectId id;
490487
final String name;
491488
@org.springframework.data.mongodb.core.mapping.Field("last_name") final String lastName;
492489
final Age age;
490+
491+
public FooPerson(ObjectId id, String name, String lastName, Age age) {
492+
this.id = id;
493+
this.name = name;
494+
this.lastName = lastName;
495+
this.age = age;
496+
}
493497
}
494498

495499
public static class Age {

0 commit comments

Comments
 (0)