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;
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;
}
nesting++;
}
if(current.isPresent()) {
- final InstanceIdentifier currentPath = new InstanceIdentifier(path.getPath().subList(0, nesting));
+ final InstanceIdentifier currentPath = InstanceIdentifier.create(path.getPath().subList(0, nesting));
return new SimpleEntry<InstanceIdentifier,T>(currentPath,current.get());
}
* present. At any rate we check state just to be on the safe side.
*/
Preconditions.checkState(nesting > 0);
- final InstanceIdentifier parentPath = new InstanceIdentifier(path.getPath().subList(0, nesting - 1));
+ final InstanceIdentifier parentPath = InstanceIdentifier.create(path.getPath().subList(0, nesting - 1));
return new SimpleEntry<InstanceIdentifier,T>(parentPath,parent.get());
}