diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java index d25b98ab1a..833f1a176b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java @@ -15,7 +15,7 @@ */ package org.springframework.data.mongodb.core.query; -import static org.springframework.util.ObjectUtils.nullSafeHashCode; +import static org.springframework.util.ObjectUtils.*; import java.util.ArrayList; import java.util.Arrays; @@ -34,6 +34,7 @@ import org.bson.Document; import org.bson.types.Binary; import org.jspecify.annotations.Nullable; + import org.springframework.data.domain.Example; import org.springframework.data.geo.Circle; import org.springframework.data.geo.Point; @@ -76,8 +77,8 @@ public class Criteria implements CriteriaDefinition { private static final Object NOT_SET = new Object(); private @Nullable String key; - private List criteriaChain; - private LinkedHashMap criteria = new LinkedHashMap(); + private final List criteriaChain; + private final LinkedHashMap criteria = new LinkedHashMap(); private @Nullable Object isValue = NOT_SET; public Criteria() { @@ -120,7 +121,7 @@ public static Criteria byExample(Object example) { /** * Static factory method to create a {@link Criteria} matching an example object.
- * By default the {@link Example} uses typed matching restricting it to probe assignable types. For example, when + * By default, the {@link Example} uses typed matching restricting it to probe assignable types. For example, when * sticking with the default type key ({@code _class}), the query has restrictions such as * _class : { $in : [com.acme.Person] } .
* To avoid the above-mentioned type restriction use an {@link UntypedExampleMatcher} with @@ -224,7 +225,7 @@ public Criteria is(@Nullable Object value) { * Missing Fields: Equality Filter * @since 3.3 */ - @Contract("_ -> this") + @Contract("-> this") public Criteria isNull() { return is(null); } @@ -241,7 +242,7 @@ public Criteria isNull() { * Fields: Type Check * @since 3.3 */ - @Contract("_ -> this") + @Contract("-> this") public Criteria isNullValue() { criteria.put("$type", BsonType.NULL.getValue()); @@ -391,7 +392,7 @@ public Criteria nin(Collection values) { * @return this. * @see MongoDB Query operator: $mod */ - @Contract("_ -> this") + @Contract("_, _ -> this") public Criteria mod(Number value, Number remainder) { List l = new ArrayList<>(2); l.add(value); @@ -818,7 +819,7 @@ public BitwiseCriteriaOperators bits() { } /** - * Creates a criteria using the {@code $or} operator for all of the provided criteria. + * Creates a criteria using the {@code $or} operator for all provided criteria. *

* Note that MongoDB doesn't support an {@code $nor} operator to be wrapped in a {@code $not} operator. * @@ -933,6 +934,7 @@ public Criteria andOperator(Collection criteria) { * @return this * @since 5.0 */ + @Contract("_, _ -> this") public Criteria raw(String operator, Object value) { criteria.put(operator, value); return this; @@ -957,6 +959,7 @@ private Criteria registerCriteriaChainElement(Criteria criteria) { return this.key; } + @Override public Document getCriteriaObject() { if (this.criteriaChain.size() == 1) { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Update.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Update.java index cfb214a5a3..78a42661ff 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Update.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Update.java @@ -443,14 +443,17 @@ public Update filterArray(String identifier, Object expression) { return this; } + @Override public Boolean isIsolated() { return isolated; } + @Override public Document getUpdateObject() { return new Document(modifierOps); } + @Override public List getArrayFilters() { return Collections.unmodifiableList(this.arrayFilters); } @@ -486,6 +489,7 @@ protected void addMultiFieldOperation(String operator, String key, @Nullable Obj * @param key the field name. * @return {@literal true} if given field is updated. */ + @Override public boolean modifies(String key) { return this.keysToUpdate.contains(key); } @@ -544,7 +548,7 @@ public String toString() { */ public static class Modifiers { - private Map modifiers; + private final Map modifiers; public Modifiers() { this.modifiers = new LinkedHashMap<>(1); @@ -727,7 +731,7 @@ public Object getValue() { */ private static class Slice extends AbstractModifier { - private int count; + private final int count; Slice(int count) { this.count = count;