Browse Source

Polishing.

Update since tags. Add missing Override annotation.

See #4070
Original pull request: #4242
pull/4486/head
Mark Paluch 2 years ago
parent
commit
ec7cfa3b8e
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 7
      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

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

@ -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;
} }
@ -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);
} }
} }

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> {
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()) {

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

@ -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);
} }

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

@ -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 {

Loading…
Cancel
Save