From: Robert Varga Date: Fri, 22 Oct 2021 20:30:57 +0000 (+0200) Subject: Improve ApiPath.Step with hashCode()/equals() X-Git-Tag: v2.0.6~42 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=c449af39813b8389a248e3f4a0cbbfe2f9d4ac60;p=netconf.git Improve ApiPath.Step with hashCode()/equals() Users will be expecting a reasonable comparison behaviour, make sure we have that covered. Change-Id: I1df17ea035b5442e9f2b2ea908a5b9f404bb2823 Signed-off-by: Robert Varga --- diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/ApiPath.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/ApiPath.java index 7bcb5574dc..ed9f5a1c61 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/ApiPath.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/ApiPath.java @@ -15,6 +15,7 @@ import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects.ToStringHelper; import com.google.common.collect.ImmutableList; import java.text.ParseException; +import java.util.Objects; import javax.ws.rs.PathParam; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -53,6 +54,16 @@ public final class ApiPath implements Immutable { return module; } + @Override + public abstract int hashCode(); + + @Override + public abstract boolean equals(@Nullable Object obj); + + final boolean equals(final Step other) { + return Objects.equals(module, other.module) && identifier.equals(other.identifier); + } + @Override public final String toString() { return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString(); @@ -70,6 +81,16 @@ public final class ApiPath implements Immutable { ApiIdentifier(final @Nullable String module, final String identifier) { super(module, identifier); } + + @Override + public int hashCode() { + return Objects.hash(module(), identifier()); + } + + @Override + public boolean equals(final @Nullable Object obj) { + return this == obj || obj instanceof ApiIdentifier && equals((ApiIdentifier) obj); + } } /** @@ -87,6 +108,23 @@ public final class ApiPath implements Immutable { return keyValues; } + @Override + public int hashCode() { + return Objects.hash(module(), identifier(), keyValues); + } + + @Override + public boolean equals(final @Nullable Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof ListInstance)) { + return false; + } + final var other = (ListInstance) obj; + return equals(other) && keyValues.equals(other.keyValues); + } + @Override ToStringHelper addToStringAttributes(final ToStringHelper helper) { return super.addToStringAttributes(helper).add("keyValues", keyValues);