Switch (DOM)DataTreeIdentifier to serialization proxy
[mdsal.git] / dom / mdsal-dom-api / src / main / java / org / opendaylight / mdsal / dom / api / DOMDataTreeIdentifier.java
index b3947e903577dd890127f890a643fd4553dc4399..9b2a6ce4d167b8b8d2c1b5724c3c20c4d4fd5295 100644 (file)
@@ -10,23 +10,20 @@ package org.opendaylight.mdsal.dom.api;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects;
-import java.io.Serializable;
-import java.util.Iterator;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.concepts.Path;
+import org.opendaylight.yangtools.concepts.HierarchicalIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 
 /**
  * A unique identifier for a particular subtree. It is composed of the logical data store type and the instance
  * identifier of the root node.
  */
 @NonNullByDefault
-public final class DOMDataTreeIdentifier implements Immutable, Path<DOMDataTreeIdentifier>, Serializable,
+public final class DOMDataTreeIdentifier implements HierarchicalIdentifier<DOMDataTreeIdentifier>,
         Comparable<DOMDataTreeIdentifier> {
+    @java.io.Serial
     private static final long serialVersionUID = 1L;
 
     private final YangInstanceIdentifier rootIdentifier;
@@ -62,7 +59,7 @@ public final class DOMDataTreeIdentifier implements Immutable, Path<DOMDataTreeI
     }
 
     public DOMDataTreeIdentifier toOptimized() {
-        final YangInstanceIdentifier opt = rootIdentifier.toOptimized();
+        final var opt = rootIdentifier.toOptimized();
         return opt == rootIdentifier ? this : new DOMDataTreeIdentifier(datastoreType, opt);
     }
 
@@ -73,14 +70,8 @@ public final class DOMDataTreeIdentifier implements Immutable, Path<DOMDataTreeI
 
     @Override
     public boolean equals(final @Nullable Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!(obj instanceof DOMDataTreeIdentifier)) {
-            return false;
-        }
-        DOMDataTreeIdentifier other = (DOMDataTreeIdentifier) obj;
-        return datastoreType == other.datastoreType && rootIdentifier.equals(other.rootIdentifier);
+        return this == obj || obj instanceof DOMDataTreeIdentifier other && datastoreType == other.datastoreType
+            && rootIdentifier.equals(other.rootIdentifier);
     }
 
     @Override
@@ -90,16 +81,16 @@ public final class DOMDataTreeIdentifier implements Immutable, Path<DOMDataTreeI
             return cmp;
         }
 
-        final Iterator<PathArgument> myIter = rootIdentifier.getPathArguments().iterator();
-        final Iterator<PathArgument> otherIter = domDataTreeIdentifier.rootIdentifier.getPathArguments().iterator();
+        final var myIter = rootIdentifier.getPathArguments().iterator();
+        final var otherIter = domDataTreeIdentifier.rootIdentifier.getPathArguments().iterator();
 
         while (myIter.hasNext()) {
             if (!otherIter.hasNext()) {
                 return 1;
             }
 
-            final PathArgument myPathArg = myIter.next();
-            final PathArgument otherPathArg = otherIter.next();
+            final var myPathArg = myIter.next();
+            final var otherPathArg = otherIter.next();
             cmp = myPathArg.compareTo(otherPathArg);
             if (cmp != 0) {
                 return cmp;
@@ -113,4 +104,9 @@ public final class DOMDataTreeIdentifier implements Immutable, Path<DOMDataTreeI
     public String toString() {
         return MoreObjects.toStringHelper(this).add("datastore", datastoreType).add("root", rootIdentifier).toString();
     }
+
+    @java.io.Serial
+    Object writeReplace() {
+        return new DTIv1(this);
+    }
 }