Skip to content
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

add: equals method to aggregation and aggregation ops #4693

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -104,6 +104,12 @@ protected String mongoOperator() {
return "$addFields";
}

@Override
public boolean equals(Object obj) {
AddFieldsOperation that = obj instanceof AddFieldsOperation ? (AddFieldsOperation) obj : null;
return that != null && this.getValueMap().equals(that.getValueMap());
}

/**
* @author Christoph Strobl
* @since 3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import org.bson.Document;
import org.bson.conversions.Bson;
Expand Down Expand Up @@ -785,4 +786,18 @@ public Document toDocument(String inputCollectionName, AggregationOperationConte
public String toString() {
return SerializationUtils.serializeToJsonSafely(toDocument("__collection__", DEFAULT_CONTEXT));
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Aggregation)) {
return false;
}
Aggregation that = (Aggregation) o;
return Objects.equals(pipeline, that.pipeline) && Objects.equals(options, that.options);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ default List<Document> toPipelineStages(AggregationOperationContext context) {
default String getOperator() {
return toDocument(Aggregation.DEFAULT_CONTEXT).keySet().iterator().next();
}

boolean equals(Object obj);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.springframework.data.mongodb.core.aggregation;

import java.time.Duration;
import java.util.Objects;
import java.util.Optional;

import org.bson.Document;
Expand Down Expand Up @@ -696,4 +697,20 @@ public enum DomainTypeMapping {
*/
NONE
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AggregationOptions that = (AggregationOptions) o;
return allowDiskUse == that.allowDiskUse && explain == that.explain && Objects.equals(cursor, that.cursor)
&& Objects.equals(collation, that.collation) && Objects.equals(comment, that.comment)
&& Objects.equals(hint, that.hint) && Objects.equals(maxTime, that.maxTime)
&& resultOptions == that.resultOptions && domainTypeMapping == that.domainTypeMapping
&& Objects.equals(readConcern, that.readConcern) && Objects.equals(readPreference, that.readPreference);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,16 @@ private static boolean isMerge(AggregationOperation operator) {
private static boolean isOut(AggregationOperation operator) {
return operator instanceof OutOperation || operator.getOperator().equals("$out");
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof AggregationPipeline)) {
return false;
}
AggregationPipeline that = (AggregationPipeline) o;
return pipeline.equals(that.pipeline);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,16 @@ public Document toDocument(AggregationOperationContext context) {
throw new IllegalStateException(
String.format("%s cannot be converted to org.bson.Document", ObjectUtils.nullSafeClassName(value)));
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BasicAggregationOperation that = (BasicAggregationOperation) o;
return ObjectUtils.nullSafeEquals(value, that.value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.springframework.data.mongodb.core.aggregation.BucketOperationSupport.OutputBuilder;
import org.springframework.util.Assert;

import java.util.Objects;

/**
* Encapsulates the aggregation framework {@code $bucketAuto}-operation. <br />
* Bucket stage is typically used with {@link Aggregation} and {@code $facet}. Categorizes incoming documents into a
Expand Down Expand Up @@ -157,6 +159,21 @@ public BucketAutoOperationOutputBuilder andOutput(String fieldName) {
return new BucketAutoOperationOutputBuilder(Fields.field(fieldName), this);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof BucketAutoOperation)) {
return false;
}
if (!super.equals(o)) {
return false;
}
BucketAutoOperation that = (BucketAutoOperation) o;
return buckets == that.buckets && Objects.equals(granularity, that.granularity);
}

/**
* {@link OutputBuilder} implementation for {@link BucketAutoOperation}.
*/
Expand Down
Loading