Reorganize AbstractNormalizedNodeDataOutput
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / stream / LithiumNormalizedNodeOutputStreamWriter.java
index a0aa813f64dd90cc0cceea7608f1c9aae5e950e8..b14bc1904ac8c59e49f7d68e83cee34429caec9b 100644 (file)
@@ -9,11 +9,9 @@ package org.opendaylight.controller.cluster.datastore.node.utils.stream;
 
 import java.io.DataOutput;
 import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 
 /**
  * NormalizedNodeOutputStreamWriter will be used by distributed datastore to send normalized node in
@@ -29,43 +27,28 @@ import org.opendaylight.yangtools.yang.common.Revision;
  * <p>Based on the each node, the node type is also written to the stream, that helps in reconstructing the object,
  * while reading.
  */
-class LithiumNormalizedNodeOutputStreamWriter extends AbstractNormalizedNodeDataOutput {
-    private final Map<String, Integer> stringCodeMap = new HashMap<>();
-
+final class LithiumNormalizedNodeOutputStreamWriter extends AbstractLithiumDataOutput {
     LithiumNormalizedNodeOutputStreamWriter(final DataOutput output) {
         super(output);
     }
 
     @Override
-    protected short streamVersion() {
+    short streamVersion() {
         return TokenTypes.LITHIUM_VERSION;
     }
 
     @Override
-    protected void writeQName(final QName qname) throws IOException {
-        writeString(qname.getLocalName());
-        writeModule(qname.getModule());
+    void writeQNameInternal(final QName qname) throws IOException {
+        defaultWriteQName(qname);
     }
 
+    @Override
     void writeModule(final QNameModule module) throws IOException {
-        writeString(module.getNamespace().toString());
-        writeString(module.getRevision().map(Revision::toString).orElse(null));
+        defaultWriteModule(module);
     }
 
     @Override
-    protected final void writeString(final String string) throws IOException {
-        if (string != null) {
-            final Integer value = stringCodeMap.get(string);
-            if (value == null) {
-                stringCodeMap.put(string, stringCodeMap.size());
-                writeByte(TokenTypes.IS_STRING_VALUE);
-                writeUTF(string);
-            } else {
-                writeByte(TokenTypes.IS_CODE_VALUE);
-                writeInt(value);
-            }
-        } else {
-            writeByte(TokenTypes.IS_NULL_VALUE);
-        }
+    void writeAugmentationIdentifier(final AugmentationIdentifier aid) throws IOException {
+        defaultWriteAugmentationIdentifier(aid);
     }
 }