BUG-1440: use a precondition instead of a throw 44/10544/2
authorRobert Varga <rovarga@cisco.com>
Sun, 31 Aug 2014 08:46:07 +0000 (10:46 +0200)
committerRobert Varga <rovarga@cisco.com>
Sun, 31 Aug 2014 11:23:54 +0000 (13:23 +0200)
Removes string concat in exception text and makes the code more
readable.

Change-Id: I8a672b0e355b61119db3e48bc290853bbc78a429
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/ListEntryNodeDataWithSchema.java

index 8f23f4c4f661bb5d35a09e7185f87eea6c4834e2..3e877bbfd73c213e32030041660db41c4e37aef1 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.data.codec.gson;
 
 import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
 
 import java.io.IOException;
@@ -40,7 +41,7 @@ class ListEntryNodeDataWithSchema extends CompositeNodeDataWithSchema {
 
     @Override
     public void addChild(final AbstractNodeDataWithSchema newChild) {
-        DataSchemaNode childSchema = newChild.getSchema();
+        final DataSchemaNode childSchema = newChild.getSchema();
         if (childSchema instanceof LeafSchemaNode && isPartOfKey((LeafSchemaNode) childSchema)) {
             qNameToKeys.put(childSchema.getQName(), (SimpleNodeDataWithSchema)newChild);
         }
@@ -64,14 +65,14 @@ class ListEntryNodeDataWithSchema extends CompositeNodeDataWithSchema {
             writer.startUnkeyedListItem(provideNodeIdentifier(), childSizeHint());
             super.write(writer);
             writer.endNode();
-        } else if (keyCount == qNameToKeys.size()) {
-            writer.startMapEntryNode(
-                new NodeIdentifierWithPredicates(getSchema().getQName(), Maps.transformValues(qNameToKeys, VALUE_FUNCTION)),
-                childSizeHint());
-            super.write(writer);
-            writer.endNode();
-        } else {
-            throw new IllegalStateException("Some of keys of " + getSchema().getQName() + " are missing in input.");
+            return;
         }
+
+        Preconditions.checkState(keyCount == qNameToKeys.size(), "Input is missing some of the keys of %s", getSchema().getQName());
+        writer.startMapEntryNode(
+            new NodeIdentifierWithPredicates(getSchema().getQName(), Maps.transformValues(qNameToKeys, VALUE_FUNCTION)),
+            childSizeHint());
+        super.write(writer);
+        writer.endNode();
     }
 }