Skip to content

Commit 9a40b7e

Browse files
mp911dechristophstrobl
authored andcommitted
Polishing.
Fix contract annotations, add missing Override annotations, make fields final where possible. See: #4874 Original Pull Request: #4977
1 parent e368a42 commit 9a40b7e

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.data.mongodb.core.query;
1717

18-
import static org.springframework.util.ObjectUtils.nullSafeHashCode;
18+
import static org.springframework.util.ObjectUtils.*;
1919

2020
import java.util.ArrayList;
2121
import java.util.Arrays;
@@ -34,6 +34,7 @@
3434
import org.bson.Document;
3535
import org.bson.types.Binary;
3636
import org.jspecify.annotations.Nullable;
37+
3738
import org.springframework.data.domain.Example;
3839
import org.springframework.data.geo.Circle;
3940
import org.springframework.data.geo.Point;
@@ -76,8 +77,8 @@ public class Criteria implements CriteriaDefinition {
7677
private static final Object NOT_SET = new Object();
7778

7879
private @Nullable String key;
79-
private List<Criteria> criteriaChain;
80-
private LinkedHashMap<String, Object> criteria = new LinkedHashMap<String, Object>();
80+
private final List<Criteria> criteriaChain;
81+
private final LinkedHashMap<String, @Nullable Object> criteria = new LinkedHashMap<String, Object>();
8182
private @Nullable Object isValue = NOT_SET;
8283

8384
public Criteria() {
@@ -120,7 +121,7 @@ public static Criteria byExample(Object example) {
120121

121122
/**
122123
* Static factory method to create a {@link Criteria} matching an example object. <br />
123-
* By default the {@link Example} uses typed matching restricting it to probe assignable types. For example, when
124+
* By default, the {@link Example} uses typed matching restricting it to probe assignable types. For example, when
124125
* sticking with the default type key ({@code _class}), the query has restrictions such as
125126
* <code>_class : &#123; $in : [com.acme.Person] &#125; </code>. <br />
126127
* To avoid the above-mentioned type restriction use an {@link UntypedExampleMatcher} with
@@ -224,7 +225,7 @@ public Criteria is(@Nullable Object value) {
224225
* Missing Fields: Equality Filter</a>
225226
* @since 3.3
226227
*/
227-
@Contract("_ -> this")
228+
@Contract("-> this")
228229
public Criteria isNull() {
229230
return is(null);
230231
}
@@ -241,7 +242,7 @@ public Criteria isNull() {
241242
* Fields: Type Check</a>
242243
* @since 3.3
243244
*/
244-
@Contract("_ -> this")
245+
@Contract("-> this")
245246
public Criteria isNullValue() {
246247

247248
criteria.put("$type", BsonType.NULL.getValue());
@@ -391,7 +392,7 @@ public Criteria nin(Collection<?> values) {
391392
* @return this.
392393
* @see <a href="https://docs.mongodb.com/manual/reference/operator/query/mod/">MongoDB Query operator: $mod</a>
393394
*/
394-
@Contract("_ -> this")
395+
@Contract("_, _ -> this")
395396
public Criteria mod(Number value, Number remainder) {
396397
List<Object> l = new ArrayList<>(2);
397398
l.add(value);
@@ -818,7 +819,7 @@ public BitwiseCriteriaOperators bits() {
818819
}
819820

820821
/**
821-
* Creates a criteria using the {@code $or} operator for all of the provided criteria.
822+
* Creates a criteria using the {@code $or} operator for all provided criteria.
822823
* <p>
823824
* Note that MongoDB doesn't support an {@code $nor} operator to be wrapped in a {@code $not} operator.
824825
*
@@ -933,6 +934,7 @@ public Criteria andOperator(Collection<Criteria> criteria) {
933934
* @return this
934935
* @since 5.0
935936
*/
937+
@Contract("_, _ -> this")
936938
public Criteria raw(String operator, Object value) {
937939
criteria.put(operator, value);
938940
return this;
@@ -957,6 +959,7 @@ private Criteria registerCriteriaChainElement(Criteria criteria) {
957959
return this.key;
958960
}
959961

962+
@Override
960963
public Document getCriteriaObject() {
961964

962965
if (this.criteriaChain.size() == 1) {

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Update.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,17 @@ public Update filterArray(String identifier, Object expression) {
443443
return this;
444444
}
445445

446+
@Override
446447
public Boolean isIsolated() {
447448
return isolated;
448449
}
449450

451+
@Override
450452
public Document getUpdateObject() {
451453
return new Document(modifierOps);
452454
}
453455

456+
@Override
454457
public List<ArrayFilter> getArrayFilters() {
455458
return Collections.unmodifiableList(this.arrayFilters);
456459
}
@@ -486,6 +489,7 @@ protected void addMultiFieldOperation(String operator, String key, @Nullable Obj
486489
* @param key the field name.
487490
* @return {@literal true} if given field is updated.
488491
*/
492+
@Override
489493
public boolean modifies(String key) {
490494
return this.keysToUpdate.contains(key);
491495
}
@@ -544,7 +548,7 @@ public String toString() {
544548
*/
545549
public static class Modifiers {
546550

547-
private Map<String, Modifier> modifiers;
551+
private final Map<String, Modifier> modifiers;
548552

549553
public Modifiers() {
550554
this.modifiers = new LinkedHashMap<>(1);
@@ -727,7 +731,7 @@ public Object getValue() {
727731
*/
728732
private static class Slice extends AbstractModifier {
729733

730-
private int count;
734+
private final int count;
731735

732736
Slice(int count) {
733737
this.count = count;

0 commit comments

Comments
 (0)