Improve ApiPath.Step with hashCode()/equals()
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / ApiPath.java
index 7bcb5574dc3a80e5092c71bb2129e48471cca3ba..ed9f5a1c61bf9f47fca4ffc0437d72b4a37429d5 100644 (file)
@@ -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);