Clean up public entrypoints 19/85419/6
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 28 Oct 2019 20:58:58 +0000 (21:58 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 31 Oct 2019 16:11:14 +0000 (17:11 +0100)
This API is centered around NormalizedNodeStreamVersion, which
defines versions supported by this artifact. An enum cannot really
be rehosted in an API-friendly way, which really makes it an
API entrypoint. Embrace that, eliminating NormalizedNodeInputOutput,
which acted in the same way.

JIRA: YANGTOOLS-1035
Change-Id: I8878bf6df3348981eb9165380844374885176ab1
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/AbstractMagnesiumDataInput.java
yang/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/NormalizedNodeDataInput.java
yang/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/NormalizedNodeDataOutput.java
yang/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/NormalizedNodeInputOutput.java [deleted file]
yang/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/NormalizedNodeStreamVersion.java

index 0c2ec5611b0c7ce920aa9b828eb4020cf71253cc..21b143286e3722c0a673f0980df09be2f91bb99f 100644 (file)
@@ -63,12 +63,6 @@ abstract class AbstractMagnesiumDataInput extends AbstractNormalizedNodeDataInpu
     private static final byte @NonNull[] BINARY_0 = new byte[0];
     private static final @NonNull AugmentationIdentifier EMPTY_AID = AugmentationIdentifier.create(ImmutableSet.of());
 
-    // FIXME: these should be available as constants
-    private static final @NonNull Uint8 UINT8_0 = Uint8.valueOf(0);
-    private static final @NonNull Uint16 UINT16_0 = Uint16.valueOf(0);
-    private static final @NonNull Uint32 UINT32_0 = Uint32.valueOf(0);
-    private static final @NonNull Uint64 UINT64_0 = Uint64.valueOf(0);
-
     private final List<AugmentationIdentifier> codedAugments = new ArrayList<>();
     private final List<NodeIdentifier> codedNodeIdentifiers = new ArrayList<>();
     private final List<QNameModule> codedModules = new ArrayList<>();
@@ -742,21 +736,21 @@ abstract class AbstractMagnesiumDataInput extends AbstractNormalizedNodeDataInpu
             case MagnesiumValue.UINT8:
                 return Uint8.fromByteBits(input.readByte());
             case MagnesiumValue.UINT8_0:
-                return UINT8_0;
+                return Uint8.ZERO;
             case MagnesiumValue.UINT16:
                 return Uint16.fromShortBits(input.readShort());
             case MagnesiumValue.UINT16_0:
-                return UINT16_0;
+                return Uint16.ZERO;
             case MagnesiumValue.UINT32:
                 return Uint32.fromIntBits(input.readInt());
             case MagnesiumValue.UINT32_0:
-                return UINT32_0;
+                return Uint32.ZERO;
             case MagnesiumValue.UINT32_2B:
                 return Uint32.fromIntBits(input.readShort() & 0xFFFF);
             case MagnesiumValue.UINT64:
                 return Uint64.fromLongBits(input.readLong());
             case MagnesiumValue.UINT64_0:
-                return UINT64_0;
+                return Uint64.ZERO;
             case MagnesiumValue.UINT64_4B:
                 return Uint64.fromLongBits(input.readInt() & 0xFFFFFFFFL);
             case MagnesiumValue.BIGDECIMAL:
index 2020685090d154accad05d7584018ea3f0eaaa80..c15948bda9d6c61f1442c5841fad70c9c7798c85 100644 (file)
@@ -84,4 +84,31 @@ public interface NormalizedNodeDataInput extends DataInput {
     default Optional<NormalizedNode<?, ?>> readOptionalNormalizedNode() throws IOException {
         return readBoolean() ? Optional.of(readNormalizedNode()) : Optional.empty();
     }
+
+    /**
+     * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method first reads
+     * and validates that the input contains a valid NormalizedNode stream.
+     *
+     * @param input the DataInput to read from
+     * @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
+     */
+    static @NonNull NormalizedNodeDataInput newDataInput(final @NonNull DataInput input) throws IOException {
+        return new VersionedNormalizedNodeDataInput(input).delegate();
+    }
+
+    /**
+     * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method does not
+     * perform any initial validation of the input stream.
+     *
+     * @param input the DataInput to read from
+     * @return a new {@link NormalizedNodeDataInput} instance
+     * @deprecated Use {@link #newDataInput(DataInput)} instead.
+     */
+    // FIXME: 5.0.0: deprecate for removal
+    @Deprecated
+    static @NonNull NormalizedNodeDataInput newDataInputWithoutValidation(final @NonNull DataInput input) {
+        return new VersionedNormalizedNodeDataInput(input);
+    }
 }
index 9bf503d4d120a9a6d09d95f050f2f56b822a4271..a8cb9b1368158d73285bccbcfd5a4f0d7ee42871 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.yangtools.yang.data.codec.binfmt;
 import com.google.common.annotations.Beta;
 import java.io.DataOutput;
 import java.io.IOException;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -23,10 +23,11 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
  * and {@link SchemaPath}s.
  */
 @Beta
+@NonNullByDefault
 public interface NormalizedNodeDataOutput extends AutoCloseable, DataOutput {
-    void writeQName(@NonNull QName qname) throws IOException;
+    void writeQName(QName qname) throws IOException;
 
-    void writeNormalizedNode(@NonNull NormalizedNode<?, ?> normalizedNode) throws IOException;
+    void writeNormalizedNode(NormalizedNode<?, ?> normalizedNode) throws IOException;
 
     void writePathArgument(PathArgument pathArgument) throws IOException;
 
diff --git a/yang/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/NormalizedNodeInputOutput.java b/yang/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/NormalizedNodeInputOutput.java
deleted file mode 100644 (file)
index 5428f15..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.yang.data.codec.binfmt;
-
-import com.google.common.annotations.Beta;
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import org.eclipse.jdt.annotation.NonNull;
-
-@Beta
-public final class NormalizedNodeInputOutput {
-    private NormalizedNodeInputOutput() {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method first reads
-     * and validates that the input contains a valid NormalizedNode stream.
-     *
-     * @param input the DataInput to read from
-     * @return a new {@link NormalizedNodeDataInput} instance
-     * @throws IOException if an error occurs reading from the input
-     */
-    public static NormalizedNodeDataInput newDataInput(final @NonNull DataInput input) throws IOException {
-        return new VersionedNormalizedNodeDataInput(input).delegate();
-    }
-
-    /**
-     * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method does not
-     * perform any initial validation of the input stream.
-     *
-     * @param input the DataInput to read from
-     * @return a new {@link NormalizedNodeDataInput} instance
-     */
-    public static NormalizedNodeDataInput newDataInputWithoutValidation(final @NonNull DataInput input) {
-        return new VersionedNormalizedNodeDataInput(input);
-    }
-
-    /**
-     * Creates a new {@link NormalizedNodeDataOutput} instance that writes to the given output and latest current
-     * stream version.
-     *
-     * @param output the DataOutput to write to
-     * @return a new {@link NormalizedNodeDataOutput} instance
-     */
-    public static NormalizedNodeDataOutput newDataOutput(final @NonNull DataOutput output) {
-        return new SodiumSR1DataOutput(output);
-    }
-
-    /**
-     * Creates a new {@link NormalizedNodeDataOutput} instance that writes to the given output.
-     *
-     * @param output the DataOutput to write to
-     * @param version Streaming version to use
-     * @return a new {@link NormalizedNodeDataOutput} instance
-     */
-    public static NormalizedNodeDataOutput newDataOutput(final @NonNull DataOutput output,
-            final @NonNull NormalizedNodeStreamVersion version) {
-        switch (version) {
-            case LITHIUM:
-                return new LithiumNormalizedNodeOutputStreamWriter(output);
-            case NEON_SR2:
-                return new NeonSR2NormalizedNodeOutputStreamWriter(output);
-            case SODIUM_SR1:
-                return new SodiumSR1DataOutput(output);
-            case MAGNESIUM:
-                return new MagnesiumDataOutput(output);
-            default:
-                throw new IllegalStateException("Unhandled version " + version);
-        }
-    }
-
-}
index e3cba2110feeaea306dda8cc2f53f614a8771707..3bf680b93abc3cda37df16cfb9badd8358501b6a 100644 (file)
@@ -8,7 +8,11 @@
 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;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.data.api.schema.ValueNode;
 
 /**
  * Enumeration of all stream versions this implementation supports on both input and output.
@@ -16,8 +20,65 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 @Beta
 @NonNullByDefault
 public enum NormalizedNodeStreamVersion {
-    LITHIUM,
-    NEON_SR2,
-    SODIUM_SR1,
-    MAGNESIUM;
+    /**
+     * Original stream version, as shipped in OpenDaylight Lithium simultaneous release. The caveat here is that this
+     * version has augmented in OpenDaylight Oxygen to retrofit a non-null representation of the empty type.
+     */
+    // FIXME: 5.0.0: consider deprecating this version
+    LITHIUM {
+        @Override
+        public NormalizedNodeDataOutput newDataOutput(DataOutput output) {
+            return new LithiumNormalizedNodeOutputStreamWriter(output);
+        }
+    },
+    /**
+     * Updated stream version, as shipped in OpenDaylight Neon SR2 release. Improves identifier encoding over
+     * {@link #LITHIUM}, so that QName caching is more effective.
+     */
+    NEON_SR2 {
+        @Override
+        public NormalizedNodeDataOutput newDataOutput(DataOutput output) {
+            return new NeonSR2NormalizedNodeOutputStreamWriter(output);
+        }
+    },
+    /**
+     * First shipping in Sodium SR1. Improved stream coding to eliminate redundancies present in {@link #NEON_SR2}.
+     * Supports {code Uint8} et al. as well as {@link BigInteger}.
+     */
+    SODIUM_SR1 {
+        @Override
+        public NormalizedNodeDataOutput newDataOutput(DataOutput output) {
+            return new SodiumSR1DataOutput(output);
+        }
+    },
+    /**
+     * First shipping is Magnesium. Does not support {@link BigInteger} mirroring it being superseded by {@link Uint64}
+     * in {@link ValueNode#getValue()}.
+     */
+    MAGNESIUM {
+        @Override
+        public NormalizedNodeDataOutput newDataOutput(DataOutput output) {
+            return new MagnesiumDataOutput(output);
+        }
+    };
+
+    /**
+     * Return the current runtime version. Guaranteed to not throw {@link UnsupportedOperationException} from
+     * {@link #newDataOutput(DataOutput)}.
+     *
+     * @return Current runtime version.
+     */
+    public static NormalizedNodeStreamVersion current() {
+        return MAGNESIUM;
+    }
+
+    /**
+     * Creates a new {@link NormalizedNodeDataOutput} instance that writes to the given output.
+     *
+     * @param output the DataOutput to write to
+     * @return a new {@link NormalizedNodeDataOutput} instance
+     * @throws NullPointerException if {@code output} is null
+     * @throws UnsupportedOperationException if this version cannot be created in this runtime
+     */
+    public abstract NormalizedNodeDataOutput newDataOutput(DataOutput output);
 }