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

Generate hashCode and equals #1201

Merged
Merged
Show file tree
Hide file tree
Changes from 13 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
## [Unreleased 2.x]

### Added
- Add `hashCode` and `equals` implementations ([#312](https://github.com/opensearch-project/opensearch-java/pull/312)).

### Dependencies
- Bumps `org.junit:junit-bom` from 5.10.3 to 5.11.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,17 @@ protected static <BuilderT extends AbstractBuilder<BuilderT>> void setupAcknowle
) {
op.add(AbstractBuilder::acknowledged, JsonpDeserializer.booleanDeserializer(), "acknowledged");
}

public int hashCode() {
int result = 17;
result = 31 * result + Boolean.hashCode(this.acknowledged);
return result;
}

public boolean equals(Object o) {
if (this == o) return true;
if (this.getClass() != o.getClass()) return false;
AcknowledgedResponseBase other = (AcknowledgedResponseBase) o;
return this.acknowledged() == other.acknowledged();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,27 @@ protected static <BuilderT extends AbstractBuilder<BuilderT>> void setupBaseNode
op.add(AbstractBuilder::roles, JsonpDeserializer.arrayDeserializer(NodeRole._DESERIALIZER), "roles");
op.add(AbstractBuilder::transportAddress, JsonpDeserializer.stringDeserializer(), "transport_address");
}

public int hashCode() {
int result = 17;
result = 31 * result + java.util.Objects.hashCode(this.attributes);
result = 31 * result + java.util.Objects.hashCode(this.host);
result = 31 * result + java.util.Objects.hashCode(this.ip);
result = 31 * result + this.name.hashCode();
result = 31 * result + java.util.Objects.hashCode(this.roles);
result = 31 * result + java.util.Objects.hashCode(this.transportAddress);
return result;
}

public boolean equals(Object o) {
if (this == o) return true;
if (this.getClass() != o.getClass()) return false;
BaseNode other = (BaseNode) o;
return java.util.Objects.equals(this.attributes, other.attributes)
&& java.util.Objects.equals(this.host, other.host)
&& java.util.Objects.equals(this.ip, other.ip)
&& java.util.Objects.equals(this.name, other.name)
&& java.util.Objects.equals(this.roles, other.roles)
&& java.util.Objects.equals(this.transportAddress, other.transportAddress);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,29 @@ protected static void setupBulkByScrollFailureDeserializer(ObjectDeserializer<Bu
op.add(Builder::shard, JsonpDeserializer.integerDeserializer(), "shard");
op.add(Builder::status, JsonpDeserializer.integerDeserializer(), "status");
}

public int hashCode() {
int result = 17;
result = 31 * result + java.util.Objects.hashCode(this.cause);
result = 31 * result + java.util.Objects.hashCode(this.id);
result = 31 * result + java.util.Objects.hashCode(this.index);
result = 31 * result + java.util.Objects.hashCode(this.node);
result = 31 * result + java.util.Objects.hashCode(this.reason);
result = 31 * result + Integer.hashCode(this.shard);
result = 31 * result + Integer.hashCode(this.status);
return result;
}

public boolean equals(Object o) {
if (this == o) return true;
if (this.getClass() != o.getClass()) return false;
BulkByScrollFailure other = (BulkByScrollFailure) o;
return java.util.Objects.equals(this.cause, other.cause)
&& java.util.Objects.equals(this.id, other.id)
&& java.util.Objects.equals(this.index, other.index)
&& java.util.Objects.equals(this.node, other.node)
&& java.util.Objects.equals(this.reason, other.reason)
&& this.shard() == other.shard()
&& this.status() == other.status();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -614,4 +614,47 @@ protected static void setupBulkByScrollTaskStatusDeserializer(ObjectDeserializer
op.add(Builder::updated, JsonpDeserializer.longDeserializer(), "updated");
op.add(Builder::versionConflicts, JsonpDeserializer.longDeserializer(), "version_conflicts");
}

public int hashCode() {
int result = 17;
result = 31 * result + Integer.hashCode(this.batches);
result = 31 * result + java.util.Objects.hashCode(this.canceled);
result = 31 * result + Long.hashCode(this.created);
result = 31 * result + Long.hashCode(this.deleted);
result = 31 * result + Long.hashCode(this.noops);
result = 31 * result + Float.hashCode(this.requestsPerSecond);
result = 31 * result + this.retries.hashCode();
result = 31 * result + Integer.hashCode(this.sliceId);
result = 31 * result + java.util.Objects.hashCode(this.slices);
result = 31 * result + java.util.Objects.hashCode(this.throttled);
result = 31 * result + Long.hashCode(this.throttledMillis);
result = 31 * result + java.util.Objects.hashCode(this.throttledUntil);
result = 31 * result + Long.hashCode(this.throttledUntilMillis);
result = 31 * result + Long.hashCode(this.total);
result = 31 * result + Long.hashCode(this.updated);
result = 31 * result + Long.hashCode(this.versionConflicts);
return result;
}

public boolean equals(Object o) {
if (this == o) return true;
if (this.getClass() != o.getClass()) return false;
BulkByScrollTaskStatus other = (BulkByScrollTaskStatus) o;
return this.batches() == other.batches()
&& java.util.Objects.equals(this.canceled, other.canceled)
&& this.created() == other.created()
&& this.deleted() == other.deleted()
&& this.noops() == other.noops()
&& this.requestsPerSecond() == other.requestsPerSecond()
&& java.util.Objects.equals(this.retries, other.retries)
&& this.sliceId() == other.sliceId()
&& java.util.Objects.equals(this.slices, other.slices)
&& java.util.Objects.equals(this.throttled, other.throttled)
&& this.throttledMillis() == other.throttledMillis()
&& java.util.Objects.equals(this.throttledUntil, other.throttledUntil)
&& this.throttledUntilMillis() == other.throttledUntilMillis()
&& this.total() == other.total()
&& this.updated() == other.updated()
&& this.versionConflicts() == other.versionConflicts();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,19 @@ private static JsonpDeserializer<BulkByScrollTaskStatusOrException> buildBulkByS
public static final JsonpDeserializer<BulkByScrollTaskStatusOrException> _DESERIALIZER = JsonpDeserializer.lazy(
BulkByScrollTaskStatusOrException::buildBulkByScrollTaskStatusOrExceptionDeserializer
);

public int hashCode() {
int result = 17;
result = 31 * result + _kind.hashCode();
result = 31 * result + _value.hashCode();
return result;
}

public boolean equals(Object o) {
if (this == o) return true;
if (this.getClass() != o.getClass()) return false;
BulkByScrollTaskStatusOrException other = (BulkByScrollTaskStatusOrException) o;
return this._kind().equals(other._kind()) && this._get().equals(other._get());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,29 @@ protected static void setupErrorCauseDeserializer(ObjectDeserializer<ErrorCause.
builder.metadata.put(name, JsonData._DESERIALIZER.deserialize(parser, mapper));
});
}

public int hashCode() {
int result = 17;
result = 31 * result + java.util.Objects.hashCode(this.causedBy);
result = 31 * result + java.util.Objects.hashCode(this.reason);
result = 31 * result + java.util.Objects.hashCode(this.rootCause);
result = 31 * result + java.util.Objects.hashCode(this.stackTrace);
result = 31 * result + java.util.Objects.hashCode(this.suppressed);
result = 31 * result + this.type.hashCode();
result = 31 * result + java.util.Objects.hashCode(this.metadata);
return result;
}

public boolean equals(Object o) {
if (this == o) return true;
if (this.getClass() != o.getClass()) return false;
ErrorCause other = (ErrorCause) o;
return java.util.Objects.equals(this.causedBy, other.causedBy)
&& java.util.Objects.equals(this.reason, other.reason)
&& java.util.Objects.equals(this.rootCause, other.rootCause)
&& java.util.Objects.equals(this.stackTrace, other.stackTrace)
&& java.util.Objects.equals(this.suppressed, other.suppressed)
&& java.util.Objects.equals(this.type, other.type)
&& java.util.Objects.equals(this.metadata, other.metadata);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,23 @@ protected static void setupNodeStatisticsDeserializer(ObjectDeserializer<NodeSta
op.add(Builder::successful, JsonpDeserializer.integerDeserializer(), "successful");
op.add(Builder::total, JsonpDeserializer.integerDeserializer(), "total");
}

public int hashCode() {
int result = 17;
result = 31 * result + Integer.hashCode(this.failed);
result = 31 * result + java.util.Objects.hashCode(this.failures);
result = 31 * result + Integer.hashCode(this.successful);
result = 31 * result + Integer.hashCode(this.total);
return result;
}

public boolean equals(Object o) {
if (this == o) return true;
if (this.getClass() != o.getClass()) return false;
NodeStatistics other = (NodeStatistics) o;
return this.failed() == other.failed()
&& java.util.Objects.equals(this.failures, other.failures)
&& this.successful() == other.successful()
&& this.total() == other.total();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,35 @@ protected static void setupOpenSearchVersionInfoDeserializer(ObjectDeserializer<
op.add(Builder::minimumWireCompatibilityVersion, JsonpDeserializer.stringDeserializer(), "minimum_wire_compatibility_version");
op.add(Builder::number, JsonpDeserializer.stringDeserializer(), "number");
}

public int hashCode() {
int result = 17;
result = 31 * result + this.buildDate.hashCode();
result = 31 * result + java.util.Objects.hashCode(this.buildFlavor);
result = 31 * result + this.buildHash.hashCode();
result = 31 * result + Boolean.hashCode(this.buildSnapshot);
result = 31 * result + this.buildType.hashCode();
result = 31 * result + this.distribution.hashCode();
result = 31 * result + this.luceneVersion.hashCode();
result = 31 * result + this.minimumIndexCompatibilityVersion.hashCode();
result = 31 * result + this.minimumWireCompatibilityVersion.hashCode();
result = 31 * result + this.number.hashCode();
return result;
}

public boolean equals(Object o) {
if (this == o) return true;
if (this.getClass() != o.getClass()) return false;
OpenSearchVersionInfo other = (OpenSearchVersionInfo) o;
return java.util.Objects.equals(this.buildDate, other.buildDate)
&& java.util.Objects.equals(this.buildFlavor, other.buildFlavor)
&& java.util.Objects.equals(this.buildHash, other.buildHash)
&& this.buildSnapshot() == other.buildSnapshot()
&& java.util.Objects.equals(this.buildType, other.buildType)
&& java.util.Objects.equals(this.distribution, other.distribution)
&& java.util.Objects.equals(this.luceneVersion, other.luceneVersion)
&& java.util.Objects.equals(this.minimumIndexCompatibilityVersion, other.minimumIndexCompatibilityVersion)
&& java.util.Objects.equals(this.minimumWireCompatibilityVersion, other.minimumWireCompatibilityVersion)
&& java.util.Objects.equals(this.number, other.number);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,18 @@ protected static void setupRetriesDeserializer(ObjectDeserializer<Retries.Builde
op.add(Builder::bulk, JsonpDeserializer.longDeserializer(), "bulk");
op.add(Builder::search, JsonpDeserializer.longDeserializer(), "search");
}

public int hashCode() {
int result = 17;
result = 31 * result + Long.hashCode(this.bulk);
result = 31 * result + Long.hashCode(this.search);
return result;
}

public boolean equals(Object o) {
if (this == o) return true;
if (this.getClass() != o.getClass()) return false;
Retries other = (Retries) o;
return this.bulk() == other.bulk() && this.search() == other.search();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,25 @@ protected static void setupShardFailureDeserializer(ObjectDeserializer<ShardFail
op.add(Builder::shard, JsonpDeserializer.integerDeserializer(), "shard");
op.add(Builder::status, JsonpDeserializer.stringDeserializer(), "status");
}

public int hashCode() {
int result = 17;
result = 31 * result + java.util.Objects.hashCode(this.index);
result = 31 * result + java.util.Objects.hashCode(this.node);
result = 31 * result + this.reason.hashCode();
result = 31 * result + Integer.hashCode(this.shard);
result = 31 * result + java.util.Objects.hashCode(this.status);
return result;
}

public boolean equals(Object o) {
if (this == o) return true;
if (this.getClass() != o.getClass()) return false;
ShardFailure other = (ShardFailure) o;
return java.util.Objects.equals(this.index, other.index)
&& java.util.Objects.equals(this.node, other.node)
&& java.util.Objects.equals(this.reason, other.reason)
&& this.shard() == other.shard()
&& java.util.Objects.equals(this.status, other.status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,25 @@ protected static void setupShardStatisticsDeserializer(ObjectDeserializer<ShardS
op.add(Builder::successful, JsonpDeserializer.integerDeserializer(), "successful");
op.add(Builder::total, JsonpDeserializer.integerDeserializer(), "total");
}

public int hashCode() {
int result = 17;
result = 31 * result + Integer.hashCode(this.failed);
result = 31 * result + java.util.Objects.hashCode(this.failures);
result = 31 * result + Integer.hashCode(this.skipped);
result = 31 * result + Integer.hashCode(this.successful);
result = 31 * result + Integer.hashCode(this.total);
return result;
}

public boolean equals(Object o) {
if (this == o) return true;
if (this.getClass() != o.getClass()) return false;
ShardStatistics other = (ShardStatistics) o;
return this.failed() == other.failed()
&& java.util.Objects.equals(this.failures, other.failures)
&& this.skipped() == other.skipped()
&& this.successful() == other.successful()
&& this.total() == other.total();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,23 @@ protected static void setupTaskFailureDeserializer(ObjectDeserializer<TaskFailur
op.add(Builder::status, JsonpDeserializer.stringDeserializer(), "status");
op.add(Builder::taskId, JsonpDeserializer.integerDeserializer(), "task_id");
}

public int hashCode() {
int result = 17;
result = 31 * result + this.nodeId.hashCode();
result = 31 * result + this.reason.hashCode();
result = 31 * result + this.status.hashCode();
result = 31 * result + Integer.hashCode(this.taskId);
return result;
}

public boolean equals(Object o) {
if (this == o) return true;
if (this.getClass() != o.getClass()) return false;
TaskFailure other = (TaskFailure) o;
return java.util.Objects.equals(this.nodeId, other.nodeId)
&& java.util.Objects.equals(this.reason, other.reason)
&& java.util.Objects.equals(this.status, other.status)
&& this.taskId() == other.taskId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,31 @@ protected static <BuilderT extends AbstractBuilder<BuilderT>> void setupWriteRes
op.add(AbstractBuilder::shards, ShardStatistics._DESERIALIZER, "_shards");
op.add(AbstractBuilder::version, JsonpDeserializer.longDeserializer(), "_version");
}

public int hashCode() {
int result = 17;
result = 31 * result + Boolean.hashCode(this.forcedRefresh);
result = 31 * result + this.id.hashCode();
result = 31 * result + this.index.hashCode();
result = 31 * result + Long.hashCode(this.primaryTerm);
result = 31 * result + this.result.hashCode();
result = 31 * result + Long.hashCode(this.seqNo);
result = 31 * result + this.shards.hashCode();
result = 31 * result + Long.hashCode(this.version);
return result;
}

public boolean equals(Object o) {
if (this == o) return true;
if (this.getClass() != o.getClass()) return false;
WriteResponseBase other = (WriteResponseBase) o;
return this.forcedRefresh() == other.forcedRefresh()
&& java.util.Objects.equals(this.id, other.id)
&& java.util.Objects.equals(this.index, other.index)
&& this.primaryTerm() == other.primaryTerm()
&& java.util.Objects.equals(this.result, other.result)
&& this.seqNo() == other.seqNo()
&& java.util.Objects.equals(this.shards, other.shards)
&& this.version() == other.version();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,15 @@ public InfoRequest() {}
false,
InfoResponse._DESERIALIZER
);

public int hashCode() {
int result = 17;
return result;
}

public boolean equals(Object o) {
if (this == o) return true;
if (this.getClass() != o.getClass()) return false;
return true;
}
}
Loading
Loading