Finish public DataObjectReference class hierarchy 89/112289/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 25 Jun 2024 18:42:48 +0000 (20:42 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 25 Jun 2024 21:01:00 +0000 (23:01 +0200)
Introduce private binding.impl package and drop the basic design of
InstanceIdentifier-independent implementations.

JIRA: YANGTOOLS-1608
Change-Id: I6e8e3c04adc65d75f989c8e26e5124d46242352a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/DataObjectIdentifier.java
binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/DataObjectReference.java
binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/AbstractDataObjectReference.java [new file with mode: 0644]
binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/DataObjectIdentifierImpl.java [new file with mode: 0644]
binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/DataObjectIdentifierWithKey.java [new file with mode: 0644]
binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/DataObjectReferenceImpl.java [new file with mode: 0644]
binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/DataObjectReferenceWithKey.java [new file with mode: 0644]
binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/ORv1.java [new file with mode: 0644]
binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/package-info.java [new file with mode: 0644]
binding/binding-spec/src/main/java/org/opendaylight/yangtools/yang/binding/InstanceIdentifier.java
binding/binding-spec/src/main/java/org/opendaylight/yangtools/yang/binding/KeyedInstanceIdentifier.java

index 06147f32999f3a4b53365778aad99a5ea3f638b1..822e8f7ef8b1df84cb59208912b4b3611c4124dd 100644 (file)
@@ -7,7 +7,11 @@
  */
 package org.opendaylight.yangtools.binding;
 
+import com.google.common.collect.ImmutableList;
+import java.util.List;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.binding.impl.DataObjectIdentifierImpl;
+import org.opendaylight.yangtools.binding.impl.DataObjectIdentifierWithKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.KeyedBuilder;
 
 /**
@@ -16,21 +20,38 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.KeyedBuilder;
  *
  * @param <T> type of {@link DataObject} held in the last step.
  */
-// FIXME: YANGTOOLS-1577: seal this type
-public non-sealed interface DataObjectIdentifier<T extends DataObject>
-        extends DataObjectReference<T>, BindingInstanceIdentifier {
+public sealed interface DataObjectIdentifier<T extends DataObject>
+        extends DataObjectReference<T>, BindingInstanceIdentifier
+        permits DataObjectIdentifier.WithKey, DataObjectIdentifierImpl {
     /**
      * A {@link DataObjectIdentifier} pointing to a {@link KeyAware} {@link DataObject}, typically a map entry.
      *
      * @param <K> Key type
      * @param <T> KeyAware type
      */
-    non-sealed interface WithKey<T extends KeyAware<K> & DataObject, K extends Key<T>>
-            extends DataObjectIdentifier<T>, DataObjectReference.WithKey<T, K> {
+    sealed interface WithKey<T extends KeyAware<K> & DataObject, K extends Key<T>>
+            extends DataObjectIdentifier<T>, DataObjectReference.WithKey<T, K>
+            permits DataObjectIdentifierWithKey {
         @Override
         KeyedBuilder<T, K> toBuilder();
     }
 
+    static @NonNull DataObjectIdentifier<?> ofUnsafeSteps(
+            final Iterable<? extends @NonNull ExactDataObjectStep<?>> steps) {
+        return ofUnsafeSteps(ImmutableList.copyOf(steps));
+    }
+
+    static @NonNull DataObjectIdentifier<?> ofUnsafeSteps(
+            final List<? extends @NonNull ExactDataObjectStep<?>> steps) {
+        return ofUnsafeSteps(ImmutableList.copyOf(steps));
+    }
+
+    static @NonNull DataObjectIdentifier<?> ofUnsafeSteps(
+            final ImmutableList<? extends @NonNull ExactDataObjectStep<?>> steps) {
+        // FIXME: YANGTOOLS-1577: DataObjectReferenceImpl.ofUnsafeSteps() instead
+        return DataObjectIdentifierImpl.ofUnsafeSteps(steps);
+    }
+
     @Override
     Iterable<? extends @NonNull ExactDataObjectStep<?>> steps();
 
index 95a715b34aabe89061387e665e5e7051f20a3108..ba3ca60bf1a20dcd4687206cb9d00cffe0b4cbf6 100644 (file)
@@ -7,8 +7,13 @@
  */
 package org.opendaylight.yangtools.binding;
 
+import com.google.common.collect.ImmutableList;
 import java.io.Serializable;
+import java.util.List;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.binding.impl.AbstractDataObjectReference;
+import org.opendaylight.yangtools.binding.impl.DataObjectReferenceImpl;
+import org.opendaylight.yangtools.binding.impl.DataObjectReferenceWithKey;
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.Builder;
@@ -38,7 +43,7 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 //*       {@link InexactDataObjectStep#matches(DataObjectStep)}.
 //* </ul>
 public sealed interface DataObjectReference<T extends DataObject> extends Immutable, Serializable
-        permits DataObjectIdentifier, DataObjectReference.WithKey, InstanceIdentifier {
+        permits DataObjectIdentifier, DataObjectReference.WithKey, AbstractDataObjectReference {
     /**
      * A {@link DataObjectReference} pointing to a {@link KeyAware} {@link DataObject}, typically a map entry.
      *
@@ -47,7 +52,7 @@ public sealed interface DataObjectReference<T extends DataObject> extends Immuta
      */
     sealed interface WithKey<T extends KeyAware<K> & DataObject, K extends Key<T>>
             extends DataObjectReference<T>, KeyAware<K>
-            permits DataObjectIdentifier.WithKey, KeyedInstanceIdentifier {
+            permits DataObjectIdentifier.WithKey, DataObjectReferenceWithKey, KeyedInstanceIdentifier {
         @Override
         KeyedBuilder<T, K> toBuilder();
 
@@ -64,6 +69,19 @@ public sealed interface DataObjectReference<T extends DataObject> extends Immuta
         }
     }
 
+    static @NonNull DataObjectReference<?> ofUnsafeSteps(final Iterable<? extends @NonNull DataObjectStep<?>> steps) {
+        return ofUnsafeSteps(ImmutableList.copyOf(steps));
+    }
+
+    static @NonNull DataObjectReference<?> ofUnsafeSteps(final List<? extends @NonNull DataObjectStep<?>> steps) {
+        return ofUnsafeSteps(ImmutableList.copyOf(steps));
+    }
+
+    static @NonNull DataObjectReference<?> ofUnsafeSteps(
+            final ImmutableList<? extends @NonNull DataObjectStep<?>> steps) {
+        return DataObjectReferenceImpl.ofUnsafeSteps(steps);
+    }
+
     /**
      * Return the steps of this reference. Returned {@link Iterable} does not support removals and contains one or more
      * non-null items.
@@ -96,7 +114,7 @@ public sealed interface DataObjectReference<T extends DataObject> extends Immuta
      * @return A builder instance
      * @deprecated Use {@link #toBuilder()} instead.
      */
-    @Deprecated(since = "14.0.0", forRemoval = true)
+    @Deprecated(since = "14.0.0")
     default @NonNull Builder<T> builder() {
         return toBuilder();
     }
diff --git a/binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/AbstractDataObjectReference.java b/binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/AbstractDataObjectReference.java
new file mode 100644 (file)
index 0000000..df847cd
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.impl;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.binding.DataObject;
+import org.opendaylight.yangtools.binding.DataObjectReference;
+import org.opendaylight.yangtools.binding.DataObjectStep;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Base implementation of {@link DataObjectReference}.
+ */
+public abstract sealed class AbstractDataObjectReference<T extends DataObject, S extends DataObjectStep<?>>
+        implements DataObjectReference<T>
+        permits DataObjectIdentifierImpl, DataObjectReferenceImpl, InstanceIdentifier {
+    @java.io.Serial
+    private static final long serialVersionUID = 1L;
+
+    // FIXME: YANGTOOLS-1577: final
+    @Override
+    public abstract Iterable<? extends @NonNull S> steps();
+
+    // FIXME: YANGTOOLS-1577: final
+    @Override
+    public abstract int hashCode();
+
+    // FIXME: YANGTOOLS-1577: final
+    @Override
+    public abstract boolean equals(Object obj);
+
+    @Override
+    public final String toString() {
+        // FIXME: YANGTOOLS-1577: pretty-print steps instead
+        return addToStringAttributes(MoreObjects.toStringHelper(contract())).toString();
+    }
+
+    protected @NonNull Class<?> contract() {
+        return DataObjectReference.class;
+    }
+
+    /**
+     * Add class-specific toString attributes.
+     *
+     * @param toStringHelper ToStringHelper instance
+     * @return ToStringHelper instance which was passed in
+     */
+    protected abstract ToStringHelper addToStringAttributes(ToStringHelper toStringHelper);
+
+    protected final void throwNSE() throws NotSerializableException {
+        throw new NotSerializableException(getClass().getName());
+    }
+
+    @java.io.Serial
+    protected final Object writeReplace() throws ObjectStreamException {
+        return toSerialForm();
+    }
+
+    protected @NonNull Object toSerialForm() {
+        return new ORv1(this);
+    }
+
+    @java.io.Serial
+    private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
+        throwNSE();
+    }
+
+    @java.io.Serial
+    private void readObjectNoData() throws ObjectStreamException {
+        throwNSE();
+    }
+
+    @java.io.Serial
+    private void writeObject(final ObjectOutputStream stream) throws IOException {
+        throwNSE();
+    }
+}
diff --git a/binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/DataObjectIdentifierImpl.java b/binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/DataObjectIdentifierImpl.java
new file mode 100644 (file)
index 0000000..2d75a5d
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.impl;
+
+import com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.binding.DataObject;
+import org.opendaylight.yangtools.binding.DataObjectIdentifier;
+import org.opendaylight.yangtools.binding.ExactDataObjectStep;
+
+// FIXME: YANGTOOLS-1577: non-abstract
+public abstract sealed class DataObjectIdentifierImpl<T extends DataObject>
+        extends AbstractDataObjectReference<T, ExactDataObjectStep<?>> implements DataObjectIdentifier<T>
+        permits DataObjectIdentifierWithKey {
+    @java.io.Serial
+    private static final long serialVersionUID = 1L;
+
+    public static final @NonNull DataObjectIdentifierImpl<?> ofUnsafeSteps(
+            final ImmutableList<? extends @NonNull ExactDataObjectStep<?>> steps) {
+        // FIXME: YANGTOOLS-1577: implement this
+        throw new UnsupportedOperationException();
+    }
+
+    @java.io.Serial
+    private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
+        throwNSE();
+    }
+
+    @java.io.Serial
+    private void readObjectNoData() throws ObjectStreamException {
+        throwNSE();
+    }
+
+    @java.io.Serial
+    private void writeObject(final ObjectOutputStream stream) throws IOException {
+        throwNSE();
+    }
+}
diff --git a/binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/DataObjectIdentifierWithKey.java b/binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/DataObjectIdentifierWithKey.java
new file mode 100644 (file)
index 0000000..fc80f73
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.impl;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.binding.DataObject;
+import org.opendaylight.yangtools.binding.DataObjectIdentifier.WithKey;
+import org.opendaylight.yangtools.binding.Key;
+import org.opendaylight.yangtools.binding.KeyAware;
+
+// FIXME: YANGTOOLS-1577: final
+public abstract non-sealed class DataObjectIdentifierWithKey<T extends KeyAware<K> & DataObject, K extends Key<T>>
+        extends DataObjectIdentifierImpl<T> implements WithKey<T, K> {
+    @java.io.Serial
+    private static final long serialVersionUID = 1L;
+
+    private final @NonNull K key;
+
+    protected DataObjectIdentifierWithKey(final K key) {
+        this.key = requireNonNull(key);
+    }
+
+    @Override
+    public final K key() {
+        return key;
+    }
+
+    @java.io.Serial
+    private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
+        throwNSE();
+    }
+
+    @java.io.Serial
+    private void readObjectNoData() throws ObjectStreamException {
+        throwNSE();
+    }
+
+    @java.io.Serial
+    private void writeObject(final ObjectOutputStream stream) throws IOException {
+        throwNSE();
+    }
+}
diff --git a/binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/DataObjectReferenceImpl.java b/binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/DataObjectReferenceImpl.java
new file mode 100644 (file)
index 0000000..a06d4fb
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.impl;
+
+import com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.binding.DataObject;
+import org.opendaylight.yangtools.binding.DataObjectReference;
+import org.opendaylight.yangtools.binding.DataObjectStep;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+// FIXME: YANGTOOLS-1577: non-abstract
+public abstract sealed class DataObjectReferenceImpl<T extends DataObject>
+        extends AbstractDataObjectReference<T, DataObjectStep<?>>
+        permits DataObjectReferenceWithKey {
+    @java.io.Serial
+    private static final long serialVersionUID = 1L;
+
+    public static final @NonNull DataObjectReference<?> ofUnsafeSteps(
+            final ImmutableList<? extends @NonNull DataObjectStep<?>> steps) {
+        // FIXNE: YANGTOOLS-1577: dispatch to this class
+        return InstanceIdentifier.unsafeOf(steps);
+    }
+
+    @java.io.Serial
+    private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
+        throwNSE();
+    }
+
+    @java.io.Serial
+    private void readObjectNoData() throws ObjectStreamException {
+        throwNSE();
+    }
+
+    @java.io.Serial
+    private void writeObject(final ObjectOutputStream stream) throws IOException {
+        throwNSE();
+    }
+}
diff --git a/binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/DataObjectReferenceWithKey.java b/binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/DataObjectReferenceWithKey.java
new file mode 100644 (file)
index 0000000..7e5ef2b
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.impl;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.binding.DataObject;
+import org.opendaylight.yangtools.binding.DataObjectReference.WithKey;
+import org.opendaylight.yangtools.binding.Key;
+import org.opendaylight.yangtools.binding.KeyAware;
+
+// FIXME: YANGTOOLS-1577: final
+public abstract non-sealed class DataObjectReferenceWithKey<T extends KeyAware<K> & DataObject, K extends Key<T>>
+        extends DataObjectReferenceImpl<T> implements WithKey<T, K> {
+    @java.io.Serial
+    private static final long serialVersionUID = 1L;
+
+    private final @NonNull K key;
+
+    protected DataObjectReferenceWithKey(final K key) {
+        this.key = requireNonNull(key);
+    }
+
+    @Override
+    public final K key() {
+        return key;
+    }
+
+    @java.io.Serial
+    private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
+        throwNSE();
+    }
+
+    @java.io.Serial
+    private void readObjectNoData() throws ObjectStreamException {
+        throwNSE();
+    }
+
+    @java.io.Serial
+    private void writeObject(final ObjectOutputStream stream) throws IOException {
+        throwNSE();
+    }
+}
diff --git a/binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/ORv1.java b/binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/ORv1.java
new file mode 100644 (file)
index 0000000..f3585c5
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.binding.impl;
+
+import com.google.common.collect.ImmutableList;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.ObjectStreamException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.binding.DataObjectReference;
+import org.opendaylight.yangtools.binding.DataObjectStep;
+
+final class ORv1 implements Externalizable {
+    @java.io.Serial
+    private static final long serialVersionUID = 1L;
+
+    private ImmutableList<@NonNull DataObjectStep<?>> steps;
+
+    @SuppressWarnings("redundantModifier")
+    public ORv1() {
+        // For Externalizable
+    }
+
+    ORv1(final DataObjectReference<?> source) {
+        steps = ImmutableList.copyOf(source.steps());
+    }
+
+    @Override
+    public void writeExternal(final ObjectOutput out) throws IOException {
+        out.writeInt(steps.size());
+        for (var step : steps) {
+            out.writeObject(step);
+        }
+    }
+
+    @Override
+    public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
+        final int size = in.readInt();
+        final var builder = ImmutableList.<DataObjectStep<?>>builderWithExpectedSize(size);
+        for (int i = 0; i < size; ++i) {
+            builder.add((DataObjectStep<?>) in.readObject());
+        }
+        steps = builder.build();
+    }
+
+    @java.io.Serial
+    private Object readResolve() throws ObjectStreamException {
+        return DataObjectReferenceImpl.ofUnsafeSteps(steps);
+    }
+}
diff --git a/binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/package-info.java b/binding/binding-spec/src/main/java/org/opendaylight/yangtools/binding/impl/package-info.java
new file mode 100644 (file)
index 0000000..09e1b1a
--- /dev/null
@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+/**
+ * Internal implementation details. This package exists only for the use with
+ * {@link org.opendaylight.yangtools.yang.binding.InstanceIdentifier}, so the dance we are doing with class hierarchy
+ * is not (entirely) visible.
+ */
+package org.opendaylight.yangtools.binding.impl;
\ No newline at end of file
index 9312e99aa8657c157c003dea7b9d69e8e255ef2a..68262cb103a03e5bb24f27ca40bcb6c59ae5af88 100644 (file)
@@ -13,13 +13,11 @@ import static com.google.common.base.Verify.verifyNotNull;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
-import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.base.VerifyException;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import java.io.IOException;
-import java.io.NotSerializableException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.ObjectStreamException;
@@ -34,7 +32,6 @@ import org.opendaylight.yangtools.binding.Augmentation;
 import org.opendaylight.yangtools.binding.ChildOf;
 import org.opendaylight.yangtools.binding.ChoiceIn;
 import org.opendaylight.yangtools.binding.DataObject;
-import org.opendaylight.yangtools.binding.DataObjectReference;
 import org.opendaylight.yangtools.binding.DataObjectStep;
 import org.opendaylight.yangtools.binding.DataRoot;
 import org.opendaylight.yangtools.binding.ExactDataObjectStep;
@@ -43,6 +40,7 @@ import org.opendaylight.yangtools.binding.KeyAware;
 import org.opendaylight.yangtools.binding.KeyStep;
 import org.opendaylight.yangtools.binding.KeylessStep;
 import org.opendaylight.yangtools.binding.NodeStep;
+import org.opendaylight.yangtools.binding.impl.AbstractDataObjectReference;
 import org.opendaylight.yangtools.concepts.HierarchicalIdentifier;
 import org.opendaylight.yangtools.util.HashCodeBuilder;
 
@@ -74,8 +72,8 @@ import org.opendaylight.yangtools.util.HashCodeBuilder;
  * <p>
  * This would be the same as using a path like so, "/nodes/node/openflow:1" to refer to the openflow:1 node
  */
-public sealed class InstanceIdentifier<T extends DataObject>
-        implements DataObjectReference<T>, HierarchicalIdentifier<InstanceIdentifier<? extends DataObject>>
+public sealed class InstanceIdentifier<T extends DataObject> extends AbstractDataObjectReference<T, DataObjectStep<?>>
+        implements HierarchicalIdentifier<InstanceIdentifier<? extends DataObject>>
         permits KeyedInstanceIdentifier {
     @java.io.Serial
     private static final long serialVersionUID = 3L;
@@ -175,16 +173,11 @@ public sealed class InstanceIdentifier<T extends DataObject>
     }
 
     @Override
-    public final String toString() {
-        return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
+    protected final Class<?> contract() {
+        return getClass();
     }
 
-    /**
-     * Add class-specific toString attributes.
-     *
-     * @param toStringHelper ToStringHelper instance
-     * @return ToStringHelper instance which was passed in
-     */
+    @Override
     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
         return toStringHelper.add("targetType", targetType).add("path", Iterables.toString(pathArguments));
     }
@@ -403,8 +396,8 @@ public sealed class InstanceIdentifier<T extends DataObject>
         return childIdentifier(new NodeStep<>(container));
     }
 
-    @java.io.Serial
-    Object writeReplace() throws ObjectStreamException {
+    @Override
+    protected Object toSerialForm() {
         return new IIv4<>(this);
     }
 
@@ -423,10 +416,6 @@ public sealed class InstanceIdentifier<T extends DataObject>
         throwNSE();
     }
 
-    private void throwNSE() throws NotSerializableException {
-        throw new NotSerializableException(getClass().getName());
-    }
-
     @Override
     public Builder<T> toBuilder() {
         return new RegularBuilder<>(this);
index c55e6081ead77f14472ad34543dce07ea22c8930..d63a03bdf5bd7d7b3a15c52e3f8560af69ea2a1c 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.binding;
 
-import java.io.ObjectStreamException;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.binding.DataObject;
 import org.opendaylight.yangtools.binding.DataObjectReference.WithKey;
@@ -55,7 +54,7 @@ public final class KeyedInstanceIdentifier<T extends KeyAware<K> & DataObject, K
     }
 
     @Override
-    Object writeReplace() throws ObjectStreamException {
+    protected Object toSerialForm() {
         return new KIIv4<>(this);
     }
 }