Fix CS warnings in sal-clustering-commons and enable enforcement
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / utils / SerializationUtils.java
index 1cb436d5a349cf341a2279bfe60bd2cbab908473..f29b7d8b8bc8911767cd9a957a69e1b5270fc58d 100644 (file)
@@ -35,13 +35,13 @@ public final class SerializationUtils {
     public static final ThreadLocal<NormalizedNodeDataOutput> REUSABLE_WRITER_TL = new ThreadLocal<>();
     public static final ThreadLocal<NormalizedNodeDataInput> REUSABLE_READER_TL = new ThreadLocal<>();
 
-    public static interface Applier<T> {
+    public interface Applier<T> {
         void apply(T instance, YangInstanceIdentifier path, NormalizedNode<?, ?> node);
     }
 
     private static NormalizedNodeDataOutput streamWriter(DataOutput out) throws IOException {
         NormalizedNodeDataOutput streamWriter = REUSABLE_WRITER_TL.get();
-        if(streamWriter == null) {
+        if (streamWriter == null) {
             streamWriter = NormalizedNodeInputOutput.newDataOutput(out);
         }
 
@@ -50,7 +50,7 @@ public final class SerializationUtils {
 
     private static NormalizedNodeDataInput streamReader(DataInput in) throws IOException {
         NormalizedNodeDataInput streamReader = REUSABLE_READER_TL.get();
-        if(streamReader == null) {
+        if (streamReader == null) {
             streamReader = new NormalizedNodeInputStreamReader(in);
         }
 
@@ -82,17 +82,14 @@ public final class SerializationUtils {
         }
     }
 
-    public static void serializeNormalizedNode(NormalizedNode<?, ?> node, DataOutput out) {
-        try {
-            out.writeBoolean(node != null);
-            if(node != null) {
-                NormalizedNodeDataOutput streamWriter = streamWriter(out);
-                streamWriter.writeNormalizedNode(node);
-            }
-        } catch (IOException e) {
-            throw new IllegalArgumentException(String.format("Error serializing NormalizedNode %s",
-                    node), e);
+    private static NormalizedNode<?, ?> tryDeserializeNormalizedNode(DataInput in) throws IOException {
+        boolean present = in.readBoolean();
+        if (present) {
+            NormalizedNodeDataInput streamReader = streamReader(in);
+            return streamReader.readNormalizedNode();
         }
+
+        return null;
     }
 
     public static NormalizedNode<?, ?> deserializeNormalizedNode(DataInput in) {
@@ -103,24 +100,14 @@ public final class SerializationUtils {
         }
     }
 
-    private static NormalizedNode<?, ?> tryDeserializeNormalizedNode(DataInput in) throws IOException {
-        boolean present = in.readBoolean();
-        if(present) {
-            NormalizedNodeDataInput streamReader = streamReader(in);
-            return streamReader.readNormalizedNode();
-        }
-
-        return null;
-    }
-
     public static NormalizedNode<?, ?> deserializeNormalizedNode(byte [] bytes) {
         try {
             return tryDeserializeNormalizedNode(new DataInputStream(new ByteArrayInputStream(bytes)));
-        } catch(InvalidNormalizedNodeStreamException e) {
+        } catch (InvalidNormalizedNodeStreamException e) {
             // Probably from legacy protobuf serialization - try that.
             try {
                 NormalizedNodeMessages.Node serializedNode = NormalizedNodeMessages.Node.parseFrom(bytes);
-                return new NormalizedNodeToNodeCodec(null).decode(serializedNode);
+                return new NormalizedNodeToNodeCodec().decode(serializedNode);
             } catch (InvalidProtocolBufferException e2) {
                 throw new IllegalArgumentException("Error deserializing NormalizedNode", e);
             }
@@ -129,6 +116,19 @@ public final class SerializationUtils {
         }
     }
 
+    public static void serializeNormalizedNode(NormalizedNode<?, ?> node, DataOutput out) {
+        try {
+            out.writeBoolean(node != null);
+            if (node != null) {
+                NormalizedNodeDataOutput streamWriter = streamWriter(out);
+                streamWriter.writeNormalizedNode(node);
+            }
+        } catch (IOException e) {
+            throw new IllegalArgumentException(String.format("Error serializing NormalizedNode %s",
+                    node), e);
+        }
+    }
+
     public static byte [] serializeNormalizedNode(NormalizedNode<?, ?> node) {
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         serializeNormalizedNode(node, new DataOutputStream(bos));