Refactor PathArgument to DataObjectStep
[mdsal.git] / binding / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / InstanceIdentifierV3.java
index 80fcf144417f3978987822482ff1b5b6e7cdfac5..4158b1f3c205612080553550c01b3b6a060bc7d8 100644 (file)
@@ -8,23 +8,20 @@
 package org.opendaylight.yangtools.yang.binding;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
 import java.io.Externalizable;
 import java.io.IOException;
+import java.io.NotSerializableException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.io.ObjectStreamException;
 import java.io.Serial;
-import java.util.ArrayList;
-import java.util.List;
 import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 
 class InstanceIdentifierV3<T extends DataObject> implements Externalizable {
     @Serial
     private static final long serialVersionUID = 3L;
 
-    private @Nullable Iterable<PathArgument> pathArguments;
+    private @Nullable Iterable<DataObjectStep<?>> pathArguments;
     private @Nullable Class<T> targetType;
     private boolean wildcarded;
     private int hash;
@@ -34,18 +31,11 @@ class InstanceIdentifierV3<T extends DataObject> implements Externalizable {
         // For Externalizable
     }
 
-    InstanceIdentifierV3(final InstanceIdentifier<T> source) {
-        pathArguments = source.pathArguments;
-        targetType = source.getTargetType();
-        wildcarded = source.isWildcarded();
-        hash = source.hashCode();
-    }
-
     final int getHash() {
         return hash;
     }
 
-    final Iterable<PathArgument> getPathArguments() {
+    final Iterable<DataObjectStep<?>> getPathArguments() {
         return pathArguments;
     }
 
@@ -59,13 +49,7 @@ class InstanceIdentifierV3<T extends DataObject> implements Externalizable {
 
     @Override
     public void writeExternal(final ObjectOutput out) throws IOException {
-        out.writeObject(targetType);
-        out.writeBoolean(wildcarded);
-        out.writeInt(hash);
-        out.writeInt(Iterables.size(pathArguments));
-        for (Object o : pathArguments) {
-            out.writeObject(o);
-        }
+        throw new NotSerializableException(InstanceIdentifierV3.class.getName());
     }
 
     @Override
@@ -75,14 +59,14 @@ class InstanceIdentifierV3<T extends DataObject> implements Externalizable {
         hash = in.readInt();
 
         final int size = in.readInt();
-        final List<PathArgument> args = new ArrayList<>();
+        final var builder = ImmutableList.<DataObjectStep<?>>builderWithExpectedSize(size);
         for (int i = 0; i < size; ++i) {
-            args.add((PathArgument) in.readObject());
+            builder.add((DataObjectStep<?>) in.readObject());
         }
-        pathArguments = ImmutableList.copyOf(args);
+        pathArguments = builder.build();
     }
 
-    @Serial
+    @java.io.Serial
     Object readResolve() throws ObjectStreamException {
         return new InstanceIdentifier<>(targetType, pathArguments, wildcarded, hash);
     }