diff --git a/.changes/next-release/bugfix-AWSSDKforJavav2-ffd0ebe.json b/.changes/next-release/bugfix-AWSSDKforJavav2-ffd0ebe.json new file mode 100644 index 000000000000..6a232c98e62f --- /dev/null +++ b/.changes/next-release/bugfix-AWSSDKforJavav2-ffd0ebe.json @@ -0,0 +1,6 @@ +{ + "type": "bugfix", + "category": "AWS SDK for Java v2", + "contributor": "brettkail-wk", + "description": "Implement `ApiName.equals`/`.hashCode`" +} \ No newline at end of file diff --git a/core/sdk-core/src/main/java/software/amazon/awssdk/core/ApiName.java b/core/sdk-core/src/main/java/software/amazon/awssdk/core/ApiName.java index a574f0b306bd..889793473340 100644 --- a/core/sdk-core/src/main/java/software/amazon/awssdk/core/ApiName.java +++ b/core/sdk-core/src/main/java/software/amazon/awssdk/core/ApiName.java @@ -17,6 +17,7 @@ import static software.amazon.awssdk.utils.Validate.notNull; +import java.util.Objects; import software.amazon.awssdk.annotations.SdkPublicApi; /** @@ -42,6 +43,30 @@ public String version() { return version; } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + ApiName that = (ApiName) o; + + if (!Objects.equals(name, that.name)) { + return false; + } + return Objects.equals(version, that.version); + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (version != null ? version.hashCode() : 0); + return result; + } + public static Builder builder() { return new BuilderImpl(); } diff --git a/core/sdk-core/src/test/java/software/amazon/awssdk/core/ApiNameTest.java b/core/sdk-core/src/test/java/software/amazon/awssdk/core/ApiNameTest.java new file mode 100644 index 000000000000..1b5a2d3425a4 --- /dev/null +++ b/core/sdk-core/src/test/java/software/amazon/awssdk/core/ApiNameTest.java @@ -0,0 +1,29 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package software.amazon.awssdk.core; + +import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; + +public class ApiNameTest { + + @Test + public void equalsHashCode() { + EqualsVerifier.forClass(ApiName.class) + .withNonnullFields("name", "version") + .verify(); + } +} \ No newline at end of file