BUG-2856: optimize key/leaf reference checking 48/16948/1
authorRobert Varga <rovarga@cisco.com>
Sun, 22 Mar 2015 10:20:35 +0000 (11:20 +0100)
committerRobert Varga <rovarga@cisco.com>
Sun, 22 Mar 2015 10:22:36 +0000 (11:22 +0100)
Since we are already iterating through the key map, we can provide the
corresponding expected value, without forcing another lookup. Introduce
a new method to take advantage of that.

Change-Id: Ia2a40f0ea2f647566059e2d68ec776bc6abc776d
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableMapEntryNodeBuilder.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/valid/DataValidationException.java

index 7dac8ab6c5903c48fa3ee5084b78793da76c01b6..445cf5519199ac0b896b1b8a80d5b7553928b481 100644 (file)
@@ -105,7 +105,7 @@ public class ImmutableMapEntryNodeBuilder extends AbstractImmutableDataContainer
                 LOG.debug("Adding leaf {} implied by key {}", leaf, key);
                 withChild(leaf);
             } else {
-                DataValidationException.checkListKey(childNode, getNodeIdentifier().getKeyValues(), key.getKey(), getNodeIdentifier());
+                DataValidationException.checkListKey(getNodeIdentifier(), key.getKey(), key.getValue(), childNode.getValue());
             }
         }
 
index e370c131d73f1f87683f311263c65496b28c29ec..a37d6c34e2fd1653f1c24f8ae838f344f5a74082 100644 (file)
@@ -51,17 +51,21 @@ public class DataValidationException extends RuntimeException {
         }
     }
 
+    public static void checkListKey(final NodeIdentifierWithPredicates nodeId, final QName keyQName, final Object expected, final Object actual) {
+        // Objects.equals() does not deal with arrays, but is faster
+        if (!Objects.equals(expected, actual) && !Objects.deepEquals(expected, actual)) {
+            throw new IllegalListKeyException(keyQName, nodeId, actual, expected);
+        }
+    }
+
     public static void checkListKey(final DataContainerChild<?, ?> childNode, final Map<QName, Object> keyValues, final QName keyQName,
             final NodeIdentifierWithPredicates nodeId) {
         checkListKey(childNode, keyQName, nodeId);
 
-        final Object expected = nodeId.getKeyValues().get(keyQName);
+        final Object expected = keyValues.get(keyQName);
         final Object actual = childNode.getValue();
 
-        // Objects.equals() does not deal with arrays, but is faster
-        if (!Objects.equals(expected, actual) && !Objects.deepEquals(expected, actual)) {
-            throw new IllegalListKeyException(keyQName, nodeId, actual, expected);
-        }
+        checkListKey(nodeId, keyQName, expected, actual);
     }
 
     public static void checkListKey(final DataContainerChild<?, ?> childNode, final QName keyQName, final NodeIdentifierWithPredicates nodeId) {