Fix CS warnings in sal-clustering-commons and enable enforcement
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / transformer / NormalizedNodePruner.java
index 91d323ea73b69cb52797b30423bbc3ca54d1d8f2..5363661c0e69518027647ef5c905188ff0d6735c 100644 (file)
@@ -33,8 +33,7 @@ import org.slf4j.LoggerFactory;
 
 /**
  * The NormalizedNodePruner removes all nodes from the input NormalizedNode that do not have a corresponding
- * schema element in the passed in SchemaContext
- *
+ * schema element in the passed in SchemaContext.
  */
 public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
     private static final Logger LOG = LoggerFactory.getLogger(NormalizedNodePruner.class);
@@ -51,19 +50,20 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
 
     @SuppressWarnings("unchecked")
     @Override
-    public void leafNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, Object o) throws IOException, IllegalArgumentException {
+    public void leafNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, Object value)
+            throws IOException, IllegalArgumentException {
 
         checkNotSealed();
 
         NormalizedNodeBuilderWrapper parent = stack.peek();
-        LeafNode<Object> leafNode = Builders.leafBuilder().withNodeIdentifier(nodeIdentifier).withValue(o).build();
-        if(parent != null) {
-            if(hasValidSchema(nodeIdentifier.getNodeType(), parent)) {
+        LeafNode<Object> leafNode = Builders.leafBuilder().withNodeIdentifier(nodeIdentifier).withValue(value).build();
+        if (parent != null) {
+            if (hasValidSchema(nodeIdentifier.getNodeType(), parent)) {
                 parent.builder().addChild(leafNode);
             }
         } else {
             // If there's no parent node then this is a stand alone LeafNode.
-            if(nodePathSchemaNode != null) {
+            if (nodePathSchemaNode != null) {
                 this.normalizedNode = leafNode;
             }
 
@@ -72,16 +72,16 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
     }
 
     @Override
-    public void startLeafSet(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
-
+    public void startLeafSet(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         addBuilder(Builders.leafSetBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
-    public void startOrderedLeafSet(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
-
+    public void startOrderedLeafSet(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int str)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         addBuilder(Builders.orderedLeafSetBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
@@ -89,20 +89,22 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
 
     @SuppressWarnings({ "unchecked" })
     @Override
-    public void leafSetEntryNode(QName name, Object o) throws IOException, IllegalArgumentException {
+    public void leafSetEntryNode(QName name, Object value) throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         NormalizedNodeBuilderWrapper parent = stack.peek();
-        if(parent != null) {
-            if(hasValidSchema(name, parent)) {
-                parent.builder().addChild(Builders.leafSetEntryBuilder().withValue(o).withNodeIdentifier(
-                        new YangInstanceIdentifier.NodeWithValue<>(parent.nodeType(), o)).build());
+        if (parent != null) {
+            if (hasValidSchema(name, parent)) {
+                parent.builder().addChild(Builders.leafSetEntryBuilder().withValue(value)
+                        .withNodeIdentifier(new YangInstanceIdentifier.NodeWithValue<>(parent.nodeType(), value))
+                        .build());
             }
         } else {
-            // If there's no parent LeafSetNode then this is a stand alone LeafSetEntryNode.
-            if(nodePathSchemaNode != null) {
-                this.normalizedNode = Builders.leafSetEntryBuilder().withValue(o).withNodeIdentifier(
-                        new YangInstanceIdentifier.NodeWithValue<>(name, o)).build();
+            // If there's no parent LeafSetNode then this is a stand alone
+            // LeafSetEntryNode.
+            if (nodePathSchemaNode != null) {
+                this.normalizedNode = Builders.leafSetEntryBuilder().withValue(value).withNodeIdentifier(
+                        new YangInstanceIdentifier.NodeWithValue<>(name, value)).build();
             }
 
             sealed = true;
@@ -110,68 +112,71 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
     }
 
     @Override
-    public void startContainerNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
-
+    public void startContainerNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         addBuilder(Builders.containerBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
-    public void startYangModeledAnyXmlNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
+    public void startYangModeledAnyXmlNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalArgumentException {
         throw new UnsupportedOperationException("Not implemented yet");
     }
 
     @Override
-    public void startUnkeyedList(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
-
+    public void startUnkeyedList(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         addBuilder(Builders.unkeyedListBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
-    public void startUnkeyedListItem(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalStateException {
-
+    public void startUnkeyedListItem(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalStateException {
         checkNotSealed();
 
         addBuilder(Builders.unkeyedListEntryBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
-    public void startMapNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
-
+    public void startMapNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         addBuilder(Builders.mapBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
-    public void startMapEntryNode(YangInstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifierWithPredicates, int i) throws IOException, IllegalArgumentException {
-
+    public void startMapEntryNode(YangInstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifierWithPredicates,
+            int count)  throws IOException, IllegalArgumentException {
         checkNotSealed();
 
-        addBuilder(Builders.mapEntryBuilder().withNodeIdentifier(nodeIdentifierWithPredicates), nodeIdentifierWithPredicates);
+        addBuilder(Builders.mapEntryBuilder().withNodeIdentifier(nodeIdentifierWithPredicates),
+                nodeIdentifierWithPredicates);
     }
 
     @Override
-    public void startOrderedMapNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
-
+    public void startOrderedMapNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         addBuilder(Builders.orderedMapBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
-    public void startChoiceNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int i) throws IOException, IllegalArgumentException {
-
+    public void startChoiceNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, int count)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         addBuilder(Builders.choiceBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
-    public void startAugmentationNode(YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier) throws IOException, IllegalArgumentException {
+    public void startAugmentationNode(YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier)
+            throws IOException, IllegalArgumentException {
 
         checkNotSealed();
 
@@ -180,19 +185,20 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
 
     @SuppressWarnings("unchecked")
     @Override
-    public void anyxmlNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, Object o) throws IOException, IllegalArgumentException {
+    public void anyxmlNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, Object value)
+            throws IOException, IllegalArgumentException {
         checkNotSealed();
 
         NormalizedNodeBuilderWrapper parent = stack.peek();
-        AnyXmlNode anyXmlNode = Builders.anyXmlBuilder().withNodeIdentifier(nodeIdentifier).
-                withValue((DOMSource) o).build();
-        if(parent != null) {
-            if(hasValidSchema(nodeIdentifier.getNodeType(), parent)) {
+        AnyXmlNode anyXmlNode = Builders.anyXmlBuilder().withNodeIdentifier(nodeIdentifier).withValue((DOMSource) value)
+                .build();
+        if (parent != null) {
+            if (hasValidSchema(nodeIdentifier.getNodeType(), parent)) {
                 parent.builder().addChild(anyXmlNode);
             }
         } else {
             // If there's no parent node then this is a stand alone AnyXmlNode.
-            if(nodePathSchemaNode != null) {
+            if (nodePathSchemaNode != null) {
                 this.normalizedNode = anyXmlNode;
             }
 
@@ -200,27 +206,27 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
         }
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public void endNode() throws IOException, IllegalStateException {
-
         checkNotSealed();
 
         NormalizedNodeBuilderWrapper child = stack.pop();
 
         Preconditions.checkState(child != null, "endNode called on an empty stack");
 
-        if(!child.getSchema().isPresent()) {
+        if (!child.getSchema().isPresent()) {
             LOG.debug("Schema not found for {}", child.identifier());
             return;
         }
 
-        NormalizedNode<?,?> normalizedNode = child.builder().build();
+        NormalizedNode<?,?> newNode = child.builder().build();
 
-        if(stack.size() > 0) {
+        if (stack.size() > 0) {
             NormalizedNodeBuilderWrapper parent = stack.peek();
-            parent.builder().addChild(normalizedNode);
+            parent.builder().addChild(newNode);
         } else {
-            this.normalizedNode = normalizedNode;
+            this.normalizedNode = newNode;
             sealed = true;
         }
     }
@@ -235,17 +241,17 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
 
     }
 
-    public NormalizedNode<?,?> normalizedNode(){
+    public NormalizedNode<?,?> normalizedNode() {
         return normalizedNode;
     }
 
-    private void checkNotSealed(){
+    private void checkNotSealed() {
         Preconditions.checkState(!sealed, "Pruner can be used only once");
     }
 
     private static boolean hasValidSchema(QName name, NormalizedNodeBuilderWrapper parent) {
         boolean valid = parent.getSchema().isPresent() && parent.getSchema().get().getChild(name) != null;
-        if(!valid) {
+        if (!valid) {
             LOG.debug("Schema not found for {}", name);
         }
 
@@ -253,12 +259,12 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
     }
 
     private NormalizedNodeBuilderWrapper addBuilder(NormalizedNodeContainerBuilder<?,?,?,?> builder,
-            PathArgument identifier){
+            PathArgument identifier) {
         final Optional<DataSchemaContextNode<?>> schemaNode;
         NormalizedNodeBuilderWrapper parent = stack.peek();
-        if(parent == null) {
+        if (parent == null) {
             schemaNode = Optional.fromNullable(nodePathSchemaNode);
-        } else if(parent.getSchema().isPresent()) {
+        } else if (parent.getSchema().isPresent()) {
             schemaNode = Optional.fromNullable(parent.getSchema().get().getChild(identifier));
         } else {
             schemaNode = Optional.absent();
@@ -272,9 +278,9 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
     private static DataSchemaContextNode<?> findSchemaNodeForNodePath(YangInstanceIdentifier nodePath,
             SchemaContext schemaContext) {
         DataSchemaContextNode<?> schemaNode = DataSchemaContextTree.from(schemaContext).getRoot();
-        for(PathArgument arg : nodePath.getPathArguments()) {
+        for (PathArgument arg : nodePath.getPathArguments()) {
             schemaNode = schemaNode.getChild(arg);
-            if(schemaNode == null) {
+            if (schemaNode == null) {
                 break;
             }
         }
@@ -286,26 +292,26 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
     static class SimpleStack<E> {
         List<E> stack = new LinkedList<>();
 
-        void push(E element){
+        void push(E element) {
             stack.add(element);
         }
 
-        E pop(){
-            if(size() == 0){
+        E pop() {
+            if (size() == 0) {
                 return null;
             }
             return stack.remove(stack.size() - 1);
         }
 
-        E peek(){
-            if(size() == 0){
+        E peek() {
+            if (size() == 0) {
                 return null;
             }
 
             return stack.get(stack.size() - 1);
         }
 
-        int size(){
+        int size() {
             return stack.size();
         }
     }