From 1e766d1f3dcd3ec296091ac5089f7c37c7a069e2 Mon Sep 17 00:00:00 2001 From: Michael Dowling Date: Sat, 9 Nov 2019 12:53:13 -0800 Subject: [PATCH] Update equals to include typed bag parent --- .../amazon/smithy/codegen/core/Symbol.java | 6 +++--- .../smithy/codegen/core/SymbolDependency.java | 3 ++- .../smithy/codegen/core/SymbolReference.java | 3 ++- .../smithy/codegen/core/TypedPropertiesBag.java | 17 +++++++++++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/Symbol.java b/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/Symbol.java index aeb2de15891..f3eb058ccb9 100644 --- a/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/Symbol.java +++ b/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/Symbol.java @@ -222,12 +222,12 @@ public String toString() { public boolean equals(Object o) { if (this == o) { return true; - } - if (!(o instanceof Symbol)) { + } else if (!(o instanceof Symbol)) { return false; } Symbol symbol = (Symbol) o; - return Objects.equals(namespace, symbol.namespace) + return super.equals(o) + && Objects.equals(namespace, symbol.namespace) && Objects.equals(namespaceDelimiter, symbol.namespaceDelimiter) && Objects.equals(name, symbol.name) && getProperties().equals(symbol.getProperties()) diff --git a/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependency.java b/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependency.java index 96123deaf1f..20e58f15218 100644 --- a/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependency.java +++ b/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolDependency.java @@ -214,7 +214,8 @@ public boolean equals(Object o) { } SymbolDependency that = (SymbolDependency) o; - return dependencyType.equals(that.dependencyType) + return super.equals(o) + && dependencyType.equals(that.dependencyType) && packageName.equals(that.packageName) && version.equals(that.version); } diff --git a/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolReference.java b/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolReference.java index d283bd7850c..faf2bef8c1a 100644 --- a/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolReference.java +++ b/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/SymbolReference.java @@ -171,7 +171,8 @@ public boolean equals(Object o) { } SymbolReference that = (SymbolReference) o; - return symbol.equals(that.symbol) + return super.equals(o) + && symbol.equals(that.symbol) && getProperties().equals(that.getProperties()) && options.equals(that.options) && alias.equals(that.alias); diff --git a/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TypedPropertiesBag.java b/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TypedPropertiesBag.java index 2081ef22d26..29e4312e4fa 100644 --- a/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TypedPropertiesBag.java +++ b/codegen/smithy-codegen-core/src/main/java/software/amazon/smithy/codegen/core/TypedPropertiesBag.java @@ -17,6 +17,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.Optional; import software.amazon.smithy.utils.MapUtils; @@ -97,6 +98,22 @@ public T expectProperty(String name, Class type) { "Property `%s` is not part of %s, `%s`", name, getClass().getSimpleName(), this))); } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } else if (!(o instanceof TypedPropertiesBag)) { + return false; + } else { + return properties.equals(((TypedPropertiesBag) o).properties); + } + } + + @Override + public int hashCode() { + return Objects.hash(properties); + } + /** * Builds a SymbolReference. */