From 2accf0476feb1078dd365970ab609be1ae17de58 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 22 May 2015 18:45:02 +0200 Subject: [PATCH] Take advantage of YangInstanceIdentifier methods getPathArguments() returns a list, so we can ditch Iterables. Change-Id: I5f83a46505bdea0c0b89d634a8b5e708b95a96bd Signed-off-by: Robert Varga --- .../data/api/YangInstanceIdentifierTest.java | 28 +++++++++---------- .../yang/data/impl/schema/ImmutableNodes.java | 2 +- .../impl/schema/InstanceIdToSimpleNodes.java | 3 +- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/yang/yang-data-api/src/test/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifierTest.java b/yang/yang-data-api/src/test/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifierTest.java index 95363b0ce9..4d976fed17 100644 --- a/yang/yang-data-api/src/test/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifierTest.java +++ b/yang/yang-data-api/src/test/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifierTest.java @@ -14,7 +14,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import java.io.ByteArrayInputStream; @@ -24,6 +23,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Collections; import java.util.Iterator; +import java.util.List; import java.util.Map.Entry; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -97,7 +97,7 @@ public class YangInstanceIdentifierTest { YangInstanceIdentifier newID = id.node( nodeName3 ); assertNotNull( "InstanceIdentifier is null", newID ); - assertEquals( "Path size", 3, Iterables.size(newID.getPathArguments()) ); + assertEquals( "Path size", 3, newID.getPathArguments().size() ); Iterator it = newID.getPathArguments().iterator(); assertEquals( "PathArg 1 node type", nodeName1, it.next().getNodeType() ); @@ -107,7 +107,7 @@ public class YangInstanceIdentifierTest { newID = id.node( new NodeIdentifier( nodeName3 ) ); assertNotNull( "InstanceIdentifier is null", newID ); - assertEquals( "Path size", 3, Iterables.size(newID.getPathArguments()) ); + assertEquals( "Path size", 3, newID.getPathArguments().size() ); it = newID.getPathArguments().iterator(); assertEquals( "PathArg 1 node type", nodeName1, it.next().getNodeType() ); @@ -127,14 +127,14 @@ public class YangInstanceIdentifierTest { Optional relative = id1.relativeTo( id2 ); assertEquals( "isPresent", true, relative.isPresent() ); - Iterable p = relative.get().getPathArguments(); - assertEquals( "Path size", 2, Iterables.size(p) ); - assertEquals( "PathArg 1 node type", nodeName3, Iterables.get(p, 0).getNodeType() ); - assertEquals( "PathArg 2 node type", nodeName4, Iterables.get(p, 1).getNodeType() ); + List p = relative.get().getPathArguments(); + assertEquals( "Path size", 2, p.size() ); + assertEquals( "PathArg 1 node type", nodeName3, p.get(0).getNodeType() ); + assertEquals( "PathArg 2 node type", nodeName4, p.get(1).getNodeType() ); relative = id2.relativeTo( id3 ); assertEquals( "isPresent", true, relative.isPresent() ); - assertEquals( "Path size", 0, Iterables.size(relative.get().getPathArguments()) ); + assertEquals( "Path size", 0, relative.get().getPathArguments().size() ); relative = id2.relativeTo( id1 ); assertEquals( "isPresent", false, relative.isPresent() ); @@ -168,8 +168,8 @@ public class YangInstanceIdentifierTest { YangInstanceIdentifier newID = YangInstanceIdentifier.of( nodeName1 ); assertNotNull( "InstanceIdentifier is null", newID ); - assertEquals( "Path size", 1, Iterables.size(newID.getPathArguments()) ); - assertEquals( "PathArg 1 node type", nodeName1, Iterables.get(newID.getPathArguments(), 0).getNodeType() ); + assertEquals( "Path size", 1, newID.getPathArguments().size() ); + assertEquals( "PathArg 1 node type", nodeName1, newID.getPathArguments().get(0).getNodeType() ); assertNotNull( newID.toString() ); // for code coverage } @@ -183,7 +183,7 @@ public class YangInstanceIdentifierTest { .nodeWithKey( nodeName3, key2, "bar" ).build(); assertNotNull( "InstanceIdentifier is null", newID ); - assertEquals( "Path size", 3, Iterables.size(newID.getPathArguments()) ); + assertEquals( "Path size", 3, newID.getPathArguments().size() ); Iterator it = newID.getPathArguments().iterator(); assertEquals( "PathArg 1 node type", nodeName1, it.next().getNodeType() ); @@ -193,7 +193,7 @@ public class YangInstanceIdentifierTest { newID = YangInstanceIdentifier.builder( newID ).node( nodeName4 ).build(); assertNotNull( "InstanceIdentifier is null", newID ); - assertEquals( "Path size", 4, Iterables.size(newID.getPathArguments()) ); + assertEquals( "Path size", 4, newID.getPathArguments().size() ); it = newID.getPathArguments().iterator(); assertEquals( "PathArg 1 node type", nodeName1, it.next().getNodeType() ); @@ -204,8 +204,8 @@ public class YangInstanceIdentifierTest { newID = YangInstanceIdentifier.builder().node( nodeName1 ).build(); assertNotNull( "InstanceIdentifier is null", newID ); - assertEquals( "Path size", 1, Iterables.size(newID.getPathArguments()) ); - assertEquals( "PathArg 1 node type", nodeName1, Iterables.get(newID.getPathArguments(), 0).getNodeType() ); + assertEquals( "Path size", 1, newID.getPathArguments().size() ); + assertEquals( "PathArg 1 node type", nodeName1, newID.getPathArguments().get(0).getNodeType() ); } private void verifyNodeIdentifierWithPredicates(final String prefix, diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java index c7013c4a70..12c2b14851 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java @@ -127,7 +127,7 @@ public final class ImmutableNodes { public static NormalizedNode fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id, final Optional> deepestElement, final Optional> operation) { Preconditions.checkNotNull(ctx); Preconditions.checkNotNull(id); - final YangInstanceIdentifier.PathArgument topLevelElement = id.getPathArguments().iterator().next(); + final YangInstanceIdentifier.PathArgument topLevelElement = id.getPathArguments().get(0); final DataSchemaNode dataChildByName = ctx.getDataChildByName(topLevelElement.getNodeType()); Preconditions.checkNotNull(dataChildByName, "Cannot find %s node in schema context. Instance identifier has to start from root", topLevelElement); final InstanceIdToNodes instanceIdToNodes = InstanceIdToNodes.fromSchemaAndQNameChecked(ctx, topLevelElement.getNodeType()); diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToSimpleNodes.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToSimpleNodes.java index 7a3e86a77a..5f19939531 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToSimpleNodes.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToSimpleNodes.java @@ -11,7 +11,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Optional; import com.google.common.base.Preconditions; -import com.google.common.collect.Iterables; import java.util.Map; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.ModifyAction; @@ -35,7 +34,7 @@ abstract class InstanceIdToSimpleNodes create(final YangInstanceIdentifier instanceId, final Optional> deepestChild, final Optional> operation) { checkNotNull(instanceId); - final YangInstanceIdentifier.PathArgument pathArgument = Iterables.get(instanceId.getPathArguments(), 0); + final YangInstanceIdentifier.PathArgument pathArgument = instanceId.getPathArguments().get(0); final NormalizedNodeAttrBuilder> builder = getBuilder(pathArgument); if(deepestChild.isPresent()) { -- 2.36.6