BUG-865: do not use InstanceIdentifier.getPath() 50/8850/1
authorRobert Varga <rovarga@cisco.com>
Tue, 8 Jul 2014 22:01:01 +0000 (00:01 +0200)
committerRobert Varga <rovarga@cisco.com>
Wed, 9 Jul 2014 11:55:47 +0000 (13:55 +0200)
The method was only used to speed up an ArrayList, which in turn was only
ever used for debugging. Instead of using a precodintion which forces us
to do this, just track the offset of the offending entry. If we find
ourselves in the error territory, we can then take getPathArguments(),
limit it to proper size and print it out.

Change-Id: I3c1786fe77cef005a6463c22b5be8bb8672c26bb
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/TreeNodeUtils.java

index 5739f44743b014ce52c2874f980da4a384c32cec..5aaeb34a989f98b92bbe5213acca341d54c3d4ba 100644 (file)
@@ -11,11 +11,10 @@ import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
 
 import java.util.AbstractMap.SimpleEntry;
-import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
@@ -48,12 +47,16 @@ public final class TreeNodeUtils {
 
     public static <T extends StoreTreeNode<T>> T findNodeChecked(final T tree, final InstanceIdentifier path) {
         T current = tree;
-        List<PathArgument> nested = new ArrayList<>(path.getPath().size());
+
+        int i = 1;
         for(PathArgument pathArg : path.getPathArguments()) {
             Optional<T> potential = current.getChild(pathArg);
-            nested.add(pathArg);
-            Preconditions.checkArgument(potential.isPresent(),"Child %s is not present in tree.",nested);
+            if (!potential.isPresent()) {
+                throw new IllegalArgumentException(String.format("Child %s is not present in tree.",
+                        Iterables.toString(Iterables.limit(path.getPathArguments(), i))));
+            }
             current = potential.get();
+            ++i;
         }
         return current;
     }