Promote yang-data-codec-binfmt to stable status 48/102948/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 28 Oct 2022 21:59:53 +0000 (23:59 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 28 Oct 2022 22:29:49 +0000 (00:29 +0200)
All interfaces are deemed stable enough, with clear demarcation at major
revisions. Note that the writeout of everything of but latest version is
deprecated for removal.

Change-Id: I6311ce04f1613eaefc60863d93df64bef73efe2a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/DataTreeCandidateInputOutput.java
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/NormalizedNodeDataInput.java
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/NormalizedNodeDataOutput.java
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/NormalizedNodeStreamVersion.java

index 2754f36221569b07a17b945f171754dc885d2e35..e6c3e06efab32572ec109684143b26812163eba6 100644 (file)
@@ -7,14 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.data.codec.binfmt;
 
-import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableList;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.ReusableStreamReceiver;
 import org.opendaylight.yangtools.yang.data.impl.schema.ReusableImmutableNormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate;
@@ -29,7 +26,6 @@ import org.slf4j.LoggerFactory;
  * Utility serialization/deserialization for {@link DataTreeCandidate}. Note that this utility does not maintain
  * before-image information across serialization.
  */
-@Beta
 public final class DataTreeCandidateInputOutput {
     private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidateInputOutput.class);
     private static final byte DELETE = 0;
@@ -40,7 +36,7 @@ public final class DataTreeCandidateInputOutput {
     private static final byte DISAPPEARED = 5;
 
     private DataTreeCandidateInputOutput() {
-
+        // Hidden on purpose
     }
 
     public static @NonNull DataTreeCandidate readDataTreeCandidate(final NormalizedNodeDataInput in)
@@ -50,35 +46,21 @@ public final class DataTreeCandidateInputOutput {
 
     public static @NonNull DataTreeCandidate readDataTreeCandidate(final NormalizedNodeDataInput in,
             final ReusableStreamReceiver receiver) throws IOException {
-        final YangInstanceIdentifier rootPath = in.readYangInstanceIdentifier();
+        final var rootPath = in.readYangInstanceIdentifier();
         final byte type = in.readByte();
 
-        final DataTreeCandidateNode rootNode;
-        switch (type) {
-            case APPEARED:
-                rootNode = ModifiedDataTreeCandidateNode.create(ModificationType.APPEARED, readChildren(in, receiver));
-                break;
-            case DELETE:
-                rootNode = DeletedDataTreeCandidateNode.create();
-                break;
-            case DISAPPEARED:
-                rootNode = ModifiedDataTreeCandidateNode.create(ModificationType.DISAPPEARED,
-                    readChildren(in, receiver));
-                break;
-            case SUBTREE_MODIFIED:
-                rootNode = ModifiedDataTreeCandidateNode.create(ModificationType.SUBTREE_MODIFIED,
-                    readChildren(in, receiver));
-                break;
-            case WRITE:
-                rootNode = DataTreeCandidateNodes.written(in.readNormalizedNode(receiver));
-                break;
-            case UNMODIFIED:
-                rootNode = UnmodifiedRootDataTreeCandidateNode.INSTANCE;
-                break;
-            default:
-                throw unhandledNodeType(type);
-        }
-
+        final var rootNode = switch (type) {
+            case APPEARED -> ModifiedDataTreeCandidateNode.create(
+                ModificationType.APPEARED, readChildren(in, receiver));
+            case DELETE -> DeletedDataTreeCandidateNode.create();
+            case DISAPPEARED -> ModifiedDataTreeCandidateNode.create(
+                ModificationType.DISAPPEARED, readChildren(in, receiver));
+            case SUBTREE_MODIFIED -> ModifiedDataTreeCandidateNode.create(
+                ModificationType.SUBTREE_MODIFIED, readChildren(in, receiver));
+            case WRITE -> DataTreeCandidateNodes.written(in.readNormalizedNode(receiver));
+            case UNMODIFIED -> UnmodifiedRootDataTreeCandidateNode.INSTANCE;
+            default -> throw unhandledNodeType(type);
+        };
         return DataTreeCandidates.newDataTreeCandidate(rootPath, rootNode);
     }
 
@@ -86,39 +68,34 @@ public final class DataTreeCandidateInputOutput {
             throws IOException {
         out.writeYangInstanceIdentifier(candidate.getRootPath());
 
-        final DataTreeCandidateNode node = candidate.getRootNode();
+        final var node = candidate.getRootNode();
         switch (node.getModificationType()) {
-            case APPEARED:
+            case APPEARED -> {
                 out.writeByte(APPEARED);
                 writeChildren(out, node.getChildNodes());
-                break;
-            case DELETE:
-                out.writeByte(DELETE);
-                break;
-            case DISAPPEARED:
+            }
+            case DELETE -> out.writeByte(DELETE);
+            case DISAPPEARED -> {
                 out.writeByte(DISAPPEARED);
                 writeChildren(out, node.getChildNodes());
-                break;
-            case SUBTREE_MODIFIED:
+            }
+            case SUBTREE_MODIFIED -> {
                 out.writeByte(SUBTREE_MODIFIED);
                 writeChildren(out, node.getChildNodes());
-                break;
-            case UNMODIFIED:
-                out.writeByte(UNMODIFIED);
-                break;
-            case WRITE:
+            }
+            case UNMODIFIED -> out.writeByte(UNMODIFIED);
+            case WRITE -> {
                 out.writeByte(WRITE);
                 out.writeNormalizedNode(node.getDataAfter().get());
-                break;
-            default:
-                throw unhandledNodeType(node);
+            }
+            default -> throw unhandledNodeType(node);
         }
     }
 
     private static DataTreeCandidateNode readModifiedNode(final ModificationType type, final NormalizedNodeDataInput in,
             final ReusableStreamReceiver receiver) throws IOException {
-        final PathArgument identifier = in.readPathArgument();
-        final Collection<DataTreeCandidateNode> children = readChildren(in, receiver);
+        final var identifier = in.readPathArgument();
+        final var children = readChildren(in, receiver);
         if (children.isEmpty()) {
             LOG.debug("Modified node {} does not have any children, not instantiating it", identifier);
             return null;
@@ -134,9 +111,9 @@ public final class DataTreeCandidateInputOutput {
             return ImmutableList.of();
         }
 
-        final Collection<DataTreeCandidateNode> ret = new ArrayList<>(size);
+        final var ret = new ArrayList<DataTreeCandidateNode>(size);
         for (int i = 0; i < size; ++i) {
-            final DataTreeCandidateNode child = readNode(in, receiver);
+            final var child = readNode(in, receiver);
             if (child != null) {
                 ret.add(child);
             }
@@ -147,28 +124,21 @@ public final class DataTreeCandidateInputOutput {
     private static DataTreeCandidateNode readNode(final NormalizedNodeDataInput in,
             final ReusableStreamReceiver receiver) throws IOException {
         final byte type = in.readByte();
-        switch (type) {
-            case APPEARED:
-                return readModifiedNode(ModificationType.APPEARED, in, receiver);
-            case DELETE:
-                return DeletedDataTreeCandidateNode.create(in.readPathArgument());
-            case DISAPPEARED:
-                return readModifiedNode(ModificationType.DISAPPEARED, in, receiver);
-            case SUBTREE_MODIFIED:
-                return readModifiedNode(ModificationType.SUBTREE_MODIFIED, in, receiver);
-            case UNMODIFIED:
-                return null;
-            case WRITE:
-                return DataTreeCandidateNodes.written(in.readNormalizedNode(receiver));
-            default:
-                throw unhandledNodeType(type);
-        }
+        return switch (type) {
+            case APPEARED -> readModifiedNode(ModificationType.APPEARED, in, receiver);
+            case DELETE -> DeletedDataTreeCandidateNode.create(in.readPathArgument());
+            case DISAPPEARED -> readModifiedNode(ModificationType.DISAPPEARED, in, receiver);
+            case SUBTREE_MODIFIED -> readModifiedNode(ModificationType.SUBTREE_MODIFIED, in, receiver);
+            case UNMODIFIED -> null;
+            case WRITE -> DataTreeCandidateNodes.written(in.readNormalizedNode(receiver));
+            default -> throw unhandledNodeType(type);
+        };
     }
 
     private static void writeChildren(final NormalizedNodeDataOutput out,
             final Collection<DataTreeCandidateNode> children) throws IOException {
         out.writeInt(children.size());
-        for (DataTreeCandidateNode child : children) {
+        for (var child : children) {
             writeNode(out, child);
         }
     }
@@ -176,34 +146,33 @@ public final class DataTreeCandidateInputOutput {
     private static void writeNode(final NormalizedNodeDataOutput out, final DataTreeCandidateNode node)
             throws IOException {
         switch (node.getModificationType()) {
-            case APPEARED:
+            case APPEARED -> {
                 out.writeByte(APPEARED);
                 out.writePathArgument(node.getIdentifier());
                 writeChildren(out, node.getChildNodes());
-                break;
-            case DELETE:
+            }
+            case DELETE -> {
                 out.writeByte(DELETE);
                 out.writePathArgument(node.getIdentifier());
-                break;
-            case DISAPPEARED:
+            }
+            case DISAPPEARED -> {
                 out.writeByte(DISAPPEARED);
                 out.writePathArgument(node.getIdentifier());
                 writeChildren(out, node.getChildNodes());
-                break;
-            case SUBTREE_MODIFIED:
+            }
+            case SUBTREE_MODIFIED -> {
                 out.writeByte(SUBTREE_MODIFIED);
                 out.writePathArgument(node.getIdentifier());
                 writeChildren(out, node.getChildNodes());
-                break;
-            case WRITE:
+            }
+            case WRITE -> {
                 out.writeByte(WRITE);
                 out.writeNormalizedNode(node.getDataAfter().get());
-                break;
-            case UNMODIFIED:
+            }
+            case UNMODIFIED -> {
                 out.writeByte(UNMODIFIED);
-                break;
-            default:
-                throw unhandledNodeType(node);
+            }
+            default -> throw unhandledNodeType(node);
         }
     }
 
index 848e9328afe893ad1ea4875c43ec3b1bba01c170..12df8410cef8320da023d8c9a6c7c7dc033b3019 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.codec.binfmt;
 
-import com.google.common.annotations.Beta;
 import java.io.DataInput;
 import java.io.IOException;
 import java.util.Optional;
@@ -25,7 +24,6 @@ import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
  * Interface for reading {@link NormalizedNode}s, {@link YangInstanceIdentifier}s, {@link PathArgument}s
  * and {@link SchemaNodeIdentifier}s.
  */
-@Beta
 public interface NormalizedNodeDataInput extends QNameAwareDataInput {
     /**
      * Interpret current stream position as a NormalizedNode, stream its events into a NormalizedNodeStreamWriter.
@@ -33,7 +31,7 @@ public interface NormalizedNodeDataInput extends QNameAwareDataInput {
      * @param writer Writer to emit events to
      * @throws IOException if an error occurs
      * @throws IllegalStateException if the dictionary has been detached
-     * @throws NullPointerException if {@code writer} is null
+     * @throws NullPointerException if {@code writer} is {@code null}
      */
     void streamNormalizedNode(NormalizedNodeStreamWriter writer) throws IOException;
 
@@ -55,6 +53,7 @@ public interface NormalizedNodeDataInput extends QNameAwareDataInput {
      * @return Next node from the stream, or null if end of stream has been reached.
      * @throws IOException if an error occurs
      * @throws IllegalStateException if the dictionary has been detached
+     * @throws NullPointerException if {@code receiver} is {@code null}
      */
     default NormalizedNode readNormalizedNode(final ReusableStreamReceiver receiver) throws IOException {
         try {
@@ -91,6 +90,7 @@ public interface NormalizedNodeDataInput extends QNameAwareDataInput {
      * @return a new {@link NormalizedNodeDataInput} instance
      * @throws InvalidNormalizedNodeStreamException if the stream version is not supported
      * @throws IOException if an error occurs reading from the input
+     * @throws NullPointerException if {@code input} is {@code null}
      */
     static @NonNull NormalizedNodeDataInput newDataInput(final @NonNull DataInput input) throws IOException {
         return new VersionedNormalizedNodeDataInput(input).delegate();
index bfb5b9c28d82d6edd164643b21a1a5e39e7f20d6..c3d054a09da68b8b9f2c385b043c46d2dbce343e 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.codec.binfmt;
 
-import com.google.common.annotations.Beta;
 import java.io.IOException;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
@@ -21,21 +20,51 @@ import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
  * Interface for emitting {@link NormalizedNode}s, {@link YangInstanceIdentifier}s, {@link PathArgument}s
  * and {@link SchemaNodeIdentifier}s.
  */
-@Beta
 @NonNullByDefault
 public interface NormalizedNodeDataOutput extends AutoCloseable, QNameAwareDataOutput {
-
+    /**
+     * Write a {@link NormalizedNode}.
+     *
+     * @param normalizedNode NormalizedNode to write
+     * @throws IOException if an error occurs
+     * @throws NullPointerException if {@code normalizedNode} is {@code null}
+     */
     void writeNormalizedNode(NormalizedNode normalizedNode) throws IOException;
 
+    /**
+     * Write a {@link PathArgument}.
+     *
+     * @param pathArgument PathArgument to write
+     * @throws IOException if an error occurs
+     * @throws NullPointerException if {@code pathArgument} is {@code null}
+     */
     void writePathArgument(PathArgument pathArgument) throws IOException;
 
+    /**
+     * Write a {@link YangInstanceIdentifier}.
+     *
+     * @param identifier YangInstanceIdentifier to write
+     * @throws IOException if an error occurs
+     * @throws NullPointerException if {@code identifier} is {@code null}
+     */
     void writeYangInstanceIdentifier(YangInstanceIdentifier identifier) throws IOException;
 
+    /**
+     * Write a {@link SchemaNodeIdentifier}.
+     *
+     * @param path SchemaNodeIdentifier to write
+     * @throws IOException if an error occurs
+     * @throws NullPointerException if {@code path} is {@code null}
+     */
     void writeSchemaNodeIdentifier(SchemaNodeIdentifier path) throws IOException;
 
-    @Override
-    void close() throws IOException;
-
+    /**
+     * Write a {@link NormalizedNode} or {@code null} value.
+     *
+     * @param normalizedNode NormalizedNode to write, perhapss {@code null}, which will be restored on read.
+     * @throws IOException if an error occurs
+     * @throws NullPointerException if {@code normalizedNode} is {@code null}
+     */
     default void writeOptionalNormalizedNode(final @Nullable NormalizedNode normalizedNode) throws IOException {
         if (normalizedNode != null) {
             writeBoolean(true);
@@ -44,4 +73,11 @@ public interface NormalizedNodeDataOutput extends AutoCloseable, QNameAwareDataO
             writeBoolean(false);
         }
     }
+
+    /**
+     * {@inheritDoc}
+     * @throws IOException if an error occurs
+     */
+    @Override
+    void close() throws IOException;
 }
index f2f89e3937aee7e4a093eabac3302e9e36f3f954..f150245e03270d13ede86bee838125050e158915 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.codec.binfmt;
 
-import com.google.common.annotations.Beta;
 import java.io.DataOutput;
 import java.math.BigInteger;
 import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -17,7 +16,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.ValueNode;
 /**
  * Enumeration of all stream versions this implementation supports on both input and output.
  */
-@Beta
 @NonNullByDefault
 public enum NormalizedNodeStreamVersion {
     /**
@@ -32,8 +30,8 @@ public enum NormalizedNodeStreamVersion {
          *             mapping of {@code Uint8} et al. and hence results in a stream which needs to be further adapted
          *             to current definition of LeafNode.
          */
-        @Deprecated
         @Override
+        @Deprecated(since = "10.0.0", forRemoval = true)
         public NormalizedNodeDataOutput newDataOutput(final DataOutput output) {
             return new LithiumNormalizedNodeOutputStreamWriter(output);
         }
@@ -50,8 +48,8 @@ public enum NormalizedNodeStreamVersion {
          *             mapping of {@code Uint8} et al. and hence results in a stream which needs to be further adapted
          *             to current definition of LeafNode.
          */
-        @Deprecated
         @Override
+        @Deprecated(since = "10.0.0", forRemoval = true)
         public NormalizedNodeDataOutput newDataOutput(final DataOutput output) {
             return new NeonSR2NormalizedNodeOutputStreamWriter(output);
         }
@@ -62,6 +60,7 @@ public enum NormalizedNodeStreamVersion {
      */
     SODIUM_SR1 {
         @Override
+        @Deprecated(since = "10.0.0", forRemoval = true)
         public NormalizedNodeDataOutput newDataOutput(final DataOutput output) {
             return new SodiumSR1DataOutput(output);
         }