Skip to content

Commit 5066958

Browse files
Implement ApiName.equals/.hashCode (#5302)
Co-authored-by: Anirudh <[email protected]>
1 parent 501e37c commit 5066958

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "brettkail-wk",
5+
"description": "Implement `ApiName.equals`/`.hashCode`"
6+
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/ApiName.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static software.amazon.awssdk.utils.Validate.notNull;
1919

20+
import java.util.Objects;
2021
import software.amazon.awssdk.annotations.SdkPublicApi;
2122

2223
/**
@@ -42,6 +43,30 @@ public String version() {
4243
return version;
4344
}
4445

46+
@Override
47+
public boolean equals(Object o) {
48+
if (this == o) {
49+
return true;
50+
}
51+
if (o == null || getClass() != o.getClass()) {
52+
return false;
53+
}
54+
55+
ApiName that = (ApiName) o;
56+
57+
if (!Objects.equals(name, that.name)) {
58+
return false;
59+
}
60+
return Objects.equals(version, that.version);
61+
}
62+
63+
@Override
64+
public int hashCode() {
65+
int result = name != null ? name.hashCode() : 0;
66+
result = 31 * result + (version != null ? version.hashCode() : 0);
67+
return result;
68+
}
69+
4570
public static Builder builder() {
4671
return new BuilderImpl();
4772
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.core;
17+
18+
import nl.jqno.equalsverifier.EqualsVerifier;
19+
import org.junit.jupiter.api.Test;
20+
21+
public class ApiNameTest {
22+
23+
@Test
24+
public void equalsHashCode() {
25+
EqualsVerifier.forClass(ApiName.class)
26+
.withNonnullFields("name", "version")
27+
.verify();
28+
}
29+
}

0 commit comments

Comments
 (0)