Fix yang-data-impl code smells 89/71889/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 9 May 2018 09:13:44 +0000 (11:13 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 9 May 2018 09:21:59 +0000 (11:21 +0200)
This is a pass at addressing Sonar-reported issues.

Change-Id: I39a3aaf3369c6144cc9f03636242809a3de4f4d8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefValidatation.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableNormalizedValueAttrNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractDataNodeContainerModificationStrategy.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/SchemaAwareApplyOperation.java

index 7db06727c146f8ced4d35e975c668a7f848d46dd..e39c88ec70ef4c4014354a1539de0f847ff60515 100644 (file)
@@ -272,7 +272,7 @@ public final class LeafRefValidatation {
                 }
             }
         }
-        // FIXME if (node instance of UnkeyedListNode ...
+        // FIXME: check UnkeyedListNode case
     }
 
     private static LeafRefContext findReferencingCtxUnderChoice(
index cef9a03adad5c37da90be5f61b13f27b567c2f72..d7d322af41db49bb8db3021bad0aa3c5946a77fd 100644 (file)
@@ -53,13 +53,9 @@ public abstract class AbstractImmutableNormalizedValueAttrNode<K extends PathArg
     @Override
     protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
         // We can not call directly getValue.equals because of Empty Type
-        // RequireInstanceStatementSupport leaves which allways have NULL value
-
-        if (!Objects.deepEquals(value(), other.getValue())) {
-            return false;
-        }
+        // RequireInstanceStatementSupport leaves which always have NULL value
 
         // FIXME: are attributes part of hashCode/equals?
-        return true;
+        return Objects.deepEquals(value(), other.getValue());
     }
 }
index 4fd177a2c797f2e6c8a7953a08d15be3a3c5229f..30ad81b041fe25b21fa7c9afaf65537d1fddd117 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
@@ -45,7 +47,7 @@ abstract class AbstractDataNodeContainerModificationStrategy<T extends DataNodeC
                     }
 
                     final DataSchemaNode child = schema.getDataChildByName(key.getNodeType());
-                    Preconditions.checkArgument(child != null, "Schema %s does not have a node for child %s", schema,
+                    checkArgument(child != null, "Schema %s does not have a node for child %s", schema,
                             key.getNodeType());
                     return SchemaAwareApplyOperation.from(child, treeConfig);
                 }
@@ -56,8 +58,8 @@ abstract class AbstractDataNodeContainerModificationStrategy<T extends DataNodeC
     protected AbstractDataNodeContainerModificationStrategy(final T schema,
             final Class<? extends NormalizedNode<?, ?>> nodeClass, final DataTreeConfiguration treeConfig) {
         super(nodeClass, treeConfig);
-        this.schema = Preconditions.checkNotNull(schema,"schema");
-        this.treeConfig = Preconditions.checkNotNull(treeConfig,"treeConfig");
+        this.schema = requireNonNull(schema,"schema");
+        this.treeConfig = requireNonNull(treeConfig,"treeConfig");
     }
 
     protected final T getSchema() {
@@ -70,7 +72,7 @@ abstract class AbstractDataNodeContainerModificationStrategy<T extends DataNodeC
             return Optional.ofNullable(childCache.get(identifier));
         } catch (ExecutionException | UncheckedExecutionException e) {
             LOG.trace("Child {} not present in container schema {} children {}", identifier, this,
-                schema.getChildNodes(), e.getCause());
+                schema.getChildNodes(), e);
             return Optional.empty();
         }
     }
index daad9fcf95957dd64c9afe648a5fb5a29b3ead0c..fbd63bdc4faa6c92bc82a7e8a3902535b1d916d1 100644 (file)
@@ -155,8 +155,10 @@ abstract class SchemaAwareApplyOperation extends ModificationApplyOperation {
              * it should not cause transaction to fail, since result of this merge
              * leads to same data.
              */
-            if (!original.get().getData().equals(current.get().getData())) {
-                checkNotConflicting(path, original.get(), current.get());
+            final TreeNode orig = original.get();
+            final TreeNode cur = current.get();
+            if (!orig.getData().equals(cur.getData())) {
+                checkNotConflicting(path, orig, cur);
             }
         }
     }