Skip to content

Polishing. #4977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -76,8 +77,8 @@ public class Criteria implements CriteriaDefinition {
private static final Object NOT_SET = new Object();

private @Nullable String key;
private List<Criteria> criteriaChain;
private LinkedHashMap<String, Object> criteria = new LinkedHashMap<String, Object>();
private final List<Criteria> criteriaChain;
private final LinkedHashMap<String, @Nullable Object> criteria = new LinkedHashMap<String, Object>();
private @Nullable Object isValue = NOT_SET;

public Criteria() {
Expand Down Expand Up @@ -120,7 +121,7 @@ public static Criteria byExample(Object example) {

/**
* Static factory method to create a {@link Criteria} matching an example object. <br />
* 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
* <code>_class : &#123; $in : [com.acme.Person] &#125; </code>. <br />
* To avoid the above-mentioned type restriction use an {@link UntypedExampleMatcher} with
Expand Down Expand Up @@ -224,7 +225,7 @@ public Criteria is(@Nullable Object value) {
* Missing Fields: Equality Filter</a>
* @since 3.3
*/
@Contract("_ -> this")
@Contract("-> this")
public Criteria isNull() {
return is(null);
}
Expand All @@ -241,7 +242,7 @@ public Criteria isNull() {
* Fields: Type Check</a>
* @since 3.3
*/
@Contract("_ -> this")
@Contract("-> this")
public Criteria isNullValue() {

criteria.put("$type", BsonType.NULL.getValue());
Expand Down Expand Up @@ -391,7 +392,7 @@ public Criteria nin(Collection<?> values) {
* @return this.
* @see <a href="https://docs.mongodb.com/manual/reference/operator/query/mod/">MongoDB Query operator: $mod</a>
*/
@Contract("_ -> this")
@Contract("_, _ -> this")
public Criteria mod(Number value, Number remainder) {
List<Object> l = new ArrayList<>(2);
l.add(value);
Expand Down Expand Up @@ -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.
* <p>
* Note that MongoDB doesn't support an {@code $nor} operator to be wrapped in a {@code $not} operator.
*
Expand Down Expand Up @@ -933,6 +934,7 @@ public Criteria andOperator(Collection<Criteria> criteria) {
* @return this
* @since 5.0
*/
@Contract("_, _ -> this")
public Criteria raw(String operator, Object value) {
criteria.put(operator, value);
return this;
Expand All @@ -957,6 +959,7 @@ private Criteria registerCriteriaChainElement(Criteria criteria) {
return this.key;
}

@Override
public Document getCriteriaObject() {

if (this.criteriaChain.size() == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArrayFilter> getArrayFilters() {
return Collections.unmodifiableList(this.arrayFilters);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -544,7 +548,7 @@ public String toString() {
*/
public static class Modifiers {

private Map<String, Modifier> modifiers;
private final Map<String, Modifier> modifiers;

public Modifiers() {
this.modifiers = new LinkedHashMap<>(1);
Expand Down Expand Up @@ -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;
Expand Down