From a981eb7311ec0807f848eb54ff48c8e8c9e56642 Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Wed, 2 Oct 2024 10:05:19 +1300 Subject: [PATCH] Generate hashCode and equals (#1201) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Generate hashCode and equals , wip Signed-off-by: miguel-vila * add changelog entry Signed-off-by: miguel-vila * remove change Signed-off-by: miguel-vila * take into account primitives Signed-off-by: miguel-vila * refactor and format Signed-off-by: miguel-vila * use Object.equals Co-authored-by: Thomas Farr Signed-off-by: Miguel Vilá * use `&&` chain Signed-off-by: miguel-vila * adjust last line Signed-off-by: miguel-vila * use fqn Signed-off-by: miguel-vila * use fqn for Objects.hashCode, take into account parent Signed-off-by: miguel-vila * remove unused var definition Signed-off-by: miguel-vila * codegen equals/hashCode for request shapes Signed-off-by: miguel-vila * add hashCode/equals to TaggedUnion Signed-off-by: miguel-vila * use import Signed-off-by: miguel-vila * fix equals for request shapes Signed-off-by: miguel-vila * codegen latest from main Signed-off-by: miguel-vila --------- Signed-off-by: miguel-vila Signed-off-by: Miguel Vilá Co-authored-by: Thomas Farr Signed-off-by: Thomas Farr (cherry picked from commit 18a84604c74c945c2a08e1228b89b04d64d0db5e) --- CHANGELOG.md | 1 + .../client/opensearch/_types/ErrorCause.java | 26 +++++++++++++++ .../opensearch/_types/ShardFailure.java | 22 +++++++++++++ .../opensearch/_types/ShardStatistics.java | 22 +++++++++++++ .../opensearch/_types/WriteResponseBase.java | 28 ++++++++++++++++ .../client/opensearch/ml/Action.java | 26 +++++++++++++++ .../client/opensearch/ml/ClientConfig.java | 26 +++++++++++++++ .../opensearch/ml/CreateConnectorRequest.java | 28 ++++++++++++++++ .../ml/CreateConnectorResponse.java | 14 ++++++++ .../client/opensearch/ml/Credential.java | 20 ++++++++++++ .../opensearch/ml/DeleteAgentRequest.java | 14 ++++++++ .../opensearch/ml/DeleteAgentResponse.java | 14 ++++++++ .../opensearch/ml/DeleteConnectorRequest.java | 14 ++++++++ .../ml/DeleteConnectorResponse.java | 14 ++++++++ .../ml/DeleteModelGroupRequest.java | 14 ++++++++ .../ml/DeleteModelGroupResponse.java | 14 ++++++++ .../opensearch/ml/DeleteModelRequest.java | 14 ++++++++ .../opensearch/ml/DeleteModelResponse.java | 14 ++++++++ .../opensearch/ml/DeleteTaskRequest.java | 14 ++++++++ .../opensearch/ml/DeleteTaskResponse.java | 14 ++++++++ .../opensearch/ml/DeployModelRequest.java | 14 ++++++++ .../opensearch/ml/DeployModelResponse.java | 18 +++++++++++ .../opensearch/ml/GetModelGroupRequest.java | 14 ++++++++ .../opensearch/ml/GetModelGroupResponse.java | 24 ++++++++++++++ .../client/opensearch/ml/GetTaskRequest.java | 14 ++++++++ .../client/opensearch/ml/GetTaskResponse.java | 32 +++++++++++++++++++ .../client/opensearch/ml/Headers.java | 15 +++++++++ .../opensearch/client/opensearch/ml/LLM.java | 15 +++++++++ .../client/opensearch/ml/Memory.java | 14 ++++++++ .../opensearch/ml/RegisterAgentsRequest.java | 28 ++++++++++++++++ .../opensearch/ml/RegisterAgentsResponse.java | 14 ++++++++ .../ml/RegisterModelGroupRequest.java | 22 +++++++++++++ .../ml/RegisterModelGroupResponse.java | 15 +++++++++ .../opensearch/ml/RegisterModelRequest.java | 22 +++++++++++++ .../opensearch/ml/RegisterModelResponse.java | 15 +++++++++ .../client/opensearch/ml/ToolItems.java | 20 ++++++++++++ .../opensearch/ml/UndeployModelNode.java | 14 ++++++++ .../opensearch/ml/UndeployModelRequest.java | 14 ++++++++ .../opensearch/ml/UndeployModelResponse.java | 14 ++++++++ .../client/codegen/model/Field.java | 8 +++++ .../client/codegen/model/ObjectShape.java | 4 +++ .../client/codegen/model/RequestShape.java | 4 +++ .../opensearch/client/codegen/model/Type.java | 12 +++++++ .../client/codegen/model/Types.java | 1 + .../codegen/templates/ObjectShape.mustache | 6 +++- .../templates/ObjectShape/Equals.mustache | 27 ++++++++++++++++ .../templates/ObjectShape/HashCode.mustache | 22 +++++++++++++ .../ObjectShape/TaggedUnionEquals.mustache | 6 ++++ .../ObjectShape/TaggedUnionHashCode.mustache | 6 ++++ .../codegen/templates/RequestShape.mustache | 6 +++- .../templates/TaggedUnionShape.mustache | 5 +++ 51 files changed, 796 insertions(+), 2 deletions(-) create mode 100644 java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Equals.mustache create mode 100644 java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/HashCode.mustache create mode 100644 java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/TaggedUnionEquals.mustache create mode 100644 java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/TaggedUnionHashCode.mustache diff --git a/CHANGELOG.md b/CHANGELOG.md index 57d3fd71b5..4687e56ca3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [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.1 diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/ErrorCause.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/ErrorCause.java index c029456c39..de1cad3599 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/ErrorCause.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/ErrorCause.java @@ -40,6 +40,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -404,4 +405,29 @@ protected static void setupErrorCauseDeserializer(ObjectDeserializer> 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() + && Objects.equals(this.id, other.id) + && Objects.equals(this.index, other.index) + && this.primaryTerm() == other.primaryTerm() + && Objects.equals(this.result, other.result) + && this.seqNo() == other.seqNo() + && Objects.equals(this.shards, other.shards) + && this.version() == other.version(); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Action.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Action.java index e9912634cc..68e20bc646 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Action.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Action.java @@ -13,6 +13,7 @@ package org.opensearch.client.opensearch.ml; import jakarta.json.stream.JsonGenerator; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -286,4 +287,29 @@ protected static void setupActionDeserializer(ObjectDeserializer op.add(Builder::requestBody, JsonpDeserializer.stringDeserializer(), "request_body"); op.add(Builder::url, JsonpDeserializer.stringDeserializer(), "url"); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.actionType); + result = 31 * result + Objects.hashCode(this.headers); + result = 31 * result + Objects.hashCode(this.method); + result = 31 * result + Objects.hashCode(this.postProcessFunction); + result = 31 * result + Objects.hashCode(this.preProcessFunction); + result = 31 * result + Objects.hashCode(this.requestBody); + result = 31 * result + Objects.hashCode(this.url); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + Action other = (Action) o; + return Objects.equals(this.actionType, other.actionType) + && Objects.equals(this.headers, other.headers) + && Objects.equals(this.method, other.method) + && Objects.equals(this.postProcessFunction, other.postProcessFunction) + && Objects.equals(this.preProcessFunction, other.preProcessFunction) + && Objects.equals(this.requestBody, other.requestBody) + && Objects.equals(this.url, other.url); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/ClientConfig.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/ClientConfig.java index e3907e7f59..0a3fa1a853 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/ClientConfig.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/ClientConfig.java @@ -13,6 +13,7 @@ package org.opensearch.client.opensearch.ml; import jakarta.json.stream.JsonGenerator; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -279,4 +280,29 @@ protected static void setupClientConfigDeserializer(ObjectDeserializer op) { op.add(Builder::connectorId, JsonpDeserializer.stringDeserializer(), "connector_id"); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.connectorId); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + CreateConnectorResponse other = (CreateConnectorResponse) o; + return Objects.equals(this.connectorId, other.connectorId); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Credential.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Credential.java index 8e32830e5e..1e465e9f59 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Credential.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Credential.java @@ -15,6 +15,7 @@ import jakarta.json.stream.JsonGenerator; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -214,4 +215,23 @@ protected static void setupCredentialDeserializer(ObjectDeserializer op) { WriteResponseBase.setupWriteResponseBaseDeserializer(op); } + + public int hashCode() { + int result = super.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (!super.equals(o)) { + return false; + } + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + return true; + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteConnectorRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteConnectorRequest.java index 30e0f7d202..b108f9b63e 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteConnectorRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteConnectorRequest.java @@ -12,6 +12,7 @@ package org.opensearch.client.opensearch.ml; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import org.opensearch.client.opensearch._types.ErrorResponse; @@ -98,4 +99,17 @@ public DeleteConnectorRequest build() { false, DeleteConnectorResponse._DESERIALIZER ); + + public int hashCode() { + int result = 17; + result = 31 * result + this.connectorId.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + DeleteConnectorRequest other = (DeleteConnectorRequest) o; + return Objects.equals(this.connectorId, other.connectorId); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteConnectorResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteConnectorResponse.java index 1ba0900cc8..9119d195e6 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteConnectorResponse.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteConnectorResponse.java @@ -73,4 +73,18 @@ public DeleteConnectorResponse build() { protected static void setupDeleteConnectorResponseDeserializer(ObjectDeserializer op) { WriteResponseBase.setupWriteResponseBaseDeserializer(op); } + + public int hashCode() { + int result = super.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (!super.equals(o)) { + return false; + } + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + return true; + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupRequest.java index 181a605275..7575637baf 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupRequest.java @@ -12,6 +12,7 @@ package org.opensearch.client.opensearch.ml; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import org.opensearch.client.opensearch._types.ErrorResponse; @@ -98,4 +99,17 @@ public DeleteModelGroupRequest build() { false, DeleteModelGroupResponse._DESERIALIZER ); + + public int hashCode() { + int result = 17; + result = 31 * result + this.modelGroupId.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + DeleteModelGroupRequest other = (DeleteModelGroupRequest) o; + return Objects.equals(this.modelGroupId, other.modelGroupId); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupResponse.java index 742257bf99..5315f6739b 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupResponse.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupResponse.java @@ -73,4 +73,18 @@ public DeleteModelGroupResponse build() { protected static void setupDeleteModelGroupResponseDeserializer(ObjectDeserializer op) { WriteResponseBase.setupWriteResponseBaseDeserializer(op); } + + public int hashCode() { + int result = super.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (!super.equals(o)) { + return false; + } + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + return true; + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelRequest.java index f9be99c118..f14d9eb0cd 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelRequest.java @@ -12,6 +12,7 @@ package org.opensearch.client.opensearch.ml; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import org.opensearch.client.opensearch._types.ErrorResponse; @@ -98,4 +99,17 @@ public DeleteModelRequest build() { false, DeleteModelResponse._DESERIALIZER ); + + public int hashCode() { + int result = 17; + result = 31 * result + this.modelId.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + DeleteModelRequest other = (DeleteModelRequest) o; + return Objects.equals(this.modelId, other.modelId); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelResponse.java index 1395e93e08..feb2c322d6 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelResponse.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelResponse.java @@ -73,4 +73,18 @@ public DeleteModelResponse build() { protected static void setupDeleteModelResponseDeserializer(ObjectDeserializer op) { WriteResponseBase.setupWriteResponseBaseDeserializer(op); } + + public int hashCode() { + int result = super.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (!super.equals(o)) { + return false; + } + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + return true; + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskRequest.java index a378f83fde..9620b90898 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskRequest.java @@ -12,6 +12,7 @@ package org.opensearch.client.opensearch.ml; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import org.opensearch.client.opensearch._types.ErrorResponse; @@ -98,4 +99,17 @@ public DeleteTaskRequest build() { false, DeleteTaskResponse._DESERIALIZER ); + + public int hashCode() { + int result = 17; + result = 31 * result + this.taskId.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + DeleteTaskRequest other = (DeleteTaskRequest) o; + return Objects.equals(this.taskId, other.taskId); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskResponse.java index 93e33ffd2c..ee52e15754 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskResponse.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskResponse.java @@ -73,4 +73,18 @@ public DeleteTaskResponse build() { protected static void setupDeleteTaskResponseDeserializer(ObjectDeserializer op) { WriteResponseBase.setupWriteResponseBaseDeserializer(op); } + + public int hashCode() { + int result = super.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (!super.equals(o)) { + return false; + } + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + return true; + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelRequest.java index 2230cb1d82..dc823dd744 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelRequest.java @@ -12,6 +12,7 @@ package org.opensearch.client.opensearch.ml; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import org.opensearch.client.opensearch._types.ErrorResponse; @@ -99,4 +100,17 @@ public DeployModelRequest build() { false, DeployModelResponse._DESERIALIZER ); + + public int hashCode() { + int result = 17; + result = 31 * result + this.modelId.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + DeployModelRequest other = (DeployModelRequest) o; + return Objects.equals(this.modelId, other.modelId); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelResponse.java index 23b01f8025..2d436560f4 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelResponse.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelResponse.java @@ -13,6 +13,7 @@ package org.opensearch.client.opensearch.ml; import jakarta.json.stream.JsonGenerator; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -158,4 +159,21 @@ protected static void setupDeployModelResponseDeserializer(ObjectDeserializer op) { op.add(Builder::modelId, JsonpDeserializer.stringDeserializer(), "model_id"); op.add(Builder::parameters, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "parameters"); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.modelId); + result = 31 * result + Objects.hashCode(this.parameters); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + LLM other = (LLM) o; + return Objects.equals(this.modelId, other.modelId) && Objects.equals(this.parameters, other.parameters); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Memory.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Memory.java index dfc0a9083c..3ae6dcaf1e 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Memory.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Memory.java @@ -13,6 +13,7 @@ package org.opensearch.client.opensearch.ml; import jakarta.json.stream.JsonGenerator; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -111,4 +112,17 @@ public Memory build() { protected static void setupMemoryDeserializer(ObjectDeserializer op) { op.add(Builder::type, JsonpDeserializer.stringDeserializer(), "type"); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.type); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + Memory other = (Memory) o; + return Objects.equals(this.type, other.type); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsRequest.java index 155e0de881..1924edac77 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsRequest.java @@ -15,6 +15,7 @@ import jakarta.json.stream.JsonGenerator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -386,4 +387,31 @@ protected static void setupRegisterAgentsRequestDeserializer(ObjectDeserializer< true, RegisterAgentsResponse._DESERIALIZER ); + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.appType); + result = 31 * result + Objects.hashCode(this.description); + result = 31 * result + Objects.hashCode(this.llm); + result = 31 * result + Objects.hashCode(this.memory); + result = 31 * result + this.name.hashCode(); + result = 31 * result + Objects.hashCode(this.parameters); + result = 31 * result + Objects.hashCode(this.tools); + result = 31 * result + this.type.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + RegisterAgentsRequest other = (RegisterAgentsRequest) o; + return Objects.equals(this.appType, other.appType) + && Objects.equals(this.description, other.description) + && Objects.equals(this.llm, other.llm) + && Objects.equals(this.memory, other.memory) + && Objects.equals(this.name, other.name) + && Objects.equals(this.parameters, other.parameters) + && Objects.equals(this.tools, other.tools) + && Objects.equals(this.type, other.type); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsResponse.java index e69ff9e0de..199ae5fde6 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsResponse.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsResponse.java @@ -13,6 +13,7 @@ package org.opensearch.client.opensearch.ml; import jakarta.json.stream.JsonGenerator; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -111,4 +112,17 @@ public RegisterAgentsResponse build() { protected static void setupRegisterAgentsResponseDeserializer(ObjectDeserializer op) { op.add(Builder::agentId, JsonpDeserializer.stringDeserializer(), "agent_id"); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.agentId); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + RegisterAgentsResponse other = (RegisterAgentsResponse) o; + return Objects.equals(this.agentId, other.agentId); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupRequest.java index 2cf102fca7..b9f1b069fd 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupRequest.java @@ -14,6 +14,7 @@ import jakarta.json.stream.JsonGenerator; import java.util.List; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -294,4 +295,25 @@ protected static void setupRegisterModelGroupRequestDeserializer(ObjectDeseriali true, RegisterModelGroupResponse._DESERIALIZER ); + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.accessMode); + result = 31 * result + Boolean.hashCode(this.addAllBackendRoles); + result = 31 * result + Objects.hashCode(this.backendRoles); + result = 31 * result + Objects.hashCode(this.description); + result = 31 * result + this.name.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + RegisterModelGroupRequest other = (RegisterModelGroupRequest) o; + return Objects.equals(this.accessMode, other.accessMode) + && this.addAllBackendRoles() == other.addAllBackendRoles() + && Objects.equals(this.backendRoles, other.backendRoles) + && Objects.equals(this.description, other.description) + && Objects.equals(this.name, other.name); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupResponse.java index 240993a8c8..6ee1aab4cf 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupResponse.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupResponse.java @@ -13,6 +13,7 @@ package org.opensearch.client.opensearch.ml; import jakarta.json.stream.JsonGenerator; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import org.opensearch.client.json.JsonpDeserializable; @@ -143,4 +144,18 @@ protected static void setupRegisterModelGroupResponseDeserializer(ObjectDeserial op.add(Builder::modelGroupId, JsonpDeserializer.stringDeserializer(), "model_group_id"); op.add(Builder::status, JsonpDeserializer.stringDeserializer(), "status"); } + + public int hashCode() { + int result = 17; + result = 31 * result + this.modelGroupId.hashCode(); + result = 31 * result + this.status.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + RegisterModelGroupResponse other = (RegisterModelGroupResponse) o; + return Objects.equals(this.modelGroupId, other.modelGroupId) && Objects.equals(this.status, other.status); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelRequest.java index 98fb7909fd..9536644078 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelRequest.java @@ -13,6 +13,7 @@ package org.opensearch.client.opensearch.ml; import jakarta.json.stream.JsonGenerator; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -262,4 +263,25 @@ protected static void setupRegisterModelRequestDeserializer(ObjectDeserializer op) { op.add(Builder::stats, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "stats"); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.stats); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + UndeployModelNode other = (UndeployModelNode) o; + return Objects.equals(this.stats, other.stats); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelRequest.java index 4ae83cb5b5..0b9f760371 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelRequest.java @@ -12,6 +12,7 @@ package org.opensearch.client.opensearch.ml; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import org.opensearch.client.opensearch._types.ErrorResponse; @@ -99,4 +100,17 @@ public UndeployModelRequest build() { false, UndeployModelResponse._DESERIALIZER ); + + public int hashCode() { + int result = 17; + result = 31 * result + this.modelId.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + UndeployModelRequest other = (UndeployModelRequest) o; + return Objects.equals(this.modelId, other.modelId); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelResponse.java index 83128a460a..74cd159526 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelResponse.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelResponse.java @@ -15,6 +15,7 @@ import jakarta.json.stream.JsonGenerator; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -140,4 +141,17 @@ protected static void setupUndeployModelResponseDeserializer(ObjectDeserializer< builder.nodes.put(name, UndeployModelNode._DESERIALIZER.deserialize(parser, mapper)); }); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.nodes); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (this.getClass() != o.getClass()) return false; + UndeployModelResponse other = (UndeployModelResponse) o; + return Objects.equals(this.nodes, other.nodes); + } } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Field.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Field.java index e4d1734572..03025401cb 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Field.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Field.java @@ -84,4 +84,12 @@ public String getDescription() { public Deprecation getDeprecation() { return deprecation; } + + public boolean isUnboxedPrimitive() { + return type.isUnboxedPrimitive(); + } + + public Type getBoxedType() { + return type.getBoxed(); + } } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/ObjectShape.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/ObjectShape.java index 75b82438f1..32ba374de0 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/ObjectShape.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/ObjectShape.java @@ -55,6 +55,10 @@ public boolean hasFieldsToSerialize() { return !bodyFields.isEmpty() || additionalPropertiesField != null; } + public boolean hasFields() { + return !bodyFields.isEmpty() || additionalPropertiesField != null; + } + public Collection getImplementsTypes() { return hasFieldsToSerialize() && !extendsOtherShape() ? List.of(Types.Client.Json.PlainJsonSerializable) : null; } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java index 18facfd53e..d76a67d2fe 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java @@ -151,6 +151,10 @@ public boolean hasAnyRequiredFields() { return fields.values().stream().anyMatch(Field::isRequired); } + public boolean hasFields() { + return !fields.isEmpty(); + } + public Type getJsonEndpointType() { return Types.Client.Transport.JsonEndpoint(getType(), getResponseType(), Types.Client.OpenSearch._Types.ErrorResponse); } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Type.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Type.java index 2e4391b787..d9123a7eaa 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Type.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Type.java @@ -157,6 +157,18 @@ public boolean isPrimitive() { return PRIMITIVES.contains(name); } + public boolean isUnboxedPrimitive() { + return isPrimitive() + && !name.equals("String") + && !name.equals("Boolean") + && !name.equals("Character") + && !name.equals("Integer") + && !name.equals("Long") + && !name.equals("Float") + && !name.equals("Double") + && !name.equals("Number"); + } + public boolean isNumber() { return "Number".equals(name); } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Types.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Types.java index 8d522a11f1..d5f4e9a750 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Types.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Types.java @@ -72,6 +72,7 @@ public static final class Lang { public static final class Util { public static final String PACKAGE = Java.PACKAGE + ".util"; + public static final Type Objects = Type.builder().withPackage(PACKAGE).withName("Objects").build(); public static final Type HashMap = Type.builder().withPackage(PACKAGE).withName("HashMap").build(); public static Type Map(Type keyType, Type valueType) { diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape.mustache index 627af1db03..0cd936e3b4 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape.mustache @@ -19,4 +19,8 @@ // --------------------------------------------------------------------------------------------- {{>ObjectShape/Deserialize}} -} \ No newline at end of file + + {{>ObjectShape/HashCode}} + + {{>ObjectShape/Equals}} +} diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Equals.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Equals.mustache new file mode 100644 index 0000000000..6e45e22d72 --- /dev/null +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Equals.mustache @@ -0,0 +1,27 @@ + public boolean equals(Object o) { + {{#extendsOtherShape}} + if(!super.equals(o)) { + return false; + } + {{/extendsOtherShape}} + if(this == o) return true; + if(this.getClass() != o.getClass()) return false; + {{^hasFields}} + return true; + {{/hasFields}} + {{#hasFields}} + {{className}} other = ({{className}})o; + return + {{#fields}} + {{#isUnboxedPrimitive}} + this.{{name}}() == other.{{name}}() + {{/isUnboxedPrimitive}} + {{^isUnboxedPrimitive}} + {{TYPES.Java.Util.Objects}}.equals(this.{{name}}, other.{{name}}) + {{/isUnboxedPrimitive}} + {{^-last}} + && + {{/-last}} + {{/fields}}; + {{/hasFields}} + } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/HashCode.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/HashCode.mustache new file mode 100644 index 0000000000..5418321cc6 --- /dev/null +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/HashCode.mustache @@ -0,0 +1,22 @@ + public int hashCode() { + {{#extendsOtherShape}} + int result = super.hashCode(); + {{/extendsOtherShape}} + {{^extendsOtherShape}} + int result = 17; + {{/extendsOtherShape}} + {{#fields}} + {{#isUnboxedPrimitive}} + result = 31 * result + {{getBoxedType}}.hashCode(this.{{name}}); + {{/isUnboxedPrimitive}} + {{^isUnboxedPrimitive}} + {{#isRequired}} + result = 31 * result + this.{{name}}.hashCode(); + {{/isRequired}} + {{^isRequired}} + result = 31 * result + {{TYPES.Java.Util.Objects}}.hashCode(this.{{name}}); + {{/isRequired}} + {{/isUnboxedPrimitive}} + {{/fields}} + return result; + } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/TaggedUnionEquals.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/TaggedUnionEquals.mustache new file mode 100644 index 0000000000..7a368dc538 --- /dev/null +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/TaggedUnionEquals.mustache @@ -0,0 +1,6 @@ + public boolean equals(Object o) { + if(this == o) return true; + if(this.getClass() != o.getClass()) return false; + {{className}} other = ({{className}})o; + return this._kind().equals(other._kind()) && this._get().equals(other._get()); + } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/TaggedUnionHashCode.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/TaggedUnionHashCode.mustache new file mode 100644 index 0000000000..8cd7137529 --- /dev/null +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/TaggedUnionHashCode.mustache @@ -0,0 +1,6 @@ + public int hashCode() { + int result = 17; + result = 31 * result + _kind.hashCode(); + result = 31 * result + _value.hashCode(); + return result; + } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/RequestShape.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/RequestShape.mustache index 73c0960fea..f73f6dd4a2 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/RequestShape.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/RequestShape.mustache @@ -96,4 +96,8 @@ {{hasRequestBody}}, {{responseType}}._DESERIALIZER ); -} \ No newline at end of file + + {{>ObjectShape/HashCode}} + + {{>ObjectShape/Equals}} +} diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache index 236daf9abb..c59a635d39 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache @@ -111,4 +111,9 @@ } public static final {{TYPES.Client.Json.JsonpDeserializer}}<{{className}}> _DESERIALIZER = {{TYPES.Client.Json.JsonpDeserializer}}.lazy({{className}}::build{{className}}Deserializer); + + {{>ObjectShape/TaggedUnionHashCode}} + + {{>ObjectShape/TaggedUnionEquals}} + }