Rename OrderedNodeContainer.getChild(int) 39/95839/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 19 Apr 2021 18:24:31 +0000 (20:24 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 19 Apr 2021 18:41:58 +0000 (20:41 +0200)
childAt(int) is a better name for this method, as it does not conflict
with other possible uses. Also move the FIXME related to body() type
override to the top of the class and make sure it does not contain
commented-out code.

JIRA: YANGTOOLS-1022
Change-Id: I583ede8fdd7e91748775475470b09c94b54d8cfe
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/OrderedNodeContainer.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/UserMapNode.java
yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableUnkeyedListNodeBuilder.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableUserLeafSetNodeBuilder.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableUserMapNodeBuilder.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java

index 48b3fbf8c4f1a7d98c806dadcd18f4b28c1d7612..a066b7cf9afff3bbf8447c8828ee7b538948fe24 100644 (file)
@@ -16,6 +16,8 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
  *
  * @param <V> child type
  */
+// FIXME: 8.0.0: we really want to do a List<@NonNull V> body(), but need to reconcile that with key-based lookup in
+//               implementations -- and those are using only a Map internally.
 public interface OrderedNodeContainer<V extends NormalizedNode>
         extends NormalizedNodeContainer<V>, MixinNode, OrderingAware.User {
     @Override
@@ -28,12 +30,7 @@ public interface OrderedNodeContainer<V extends NormalizedNode>
      * @return Child Node
      * @throws IndexOutOfBoundsException Out of bound Exception
      */
-    // FIXME: 7.0.0: rename to 'childAt(int)'
-    @NonNull V getChild(int position);
-
-    // FIXME: 7.0.0: do we really mean 'List' for body?
-    //    @Override
-    //    List<V> body();
+    @NonNull V childAt(int position);
 
     @Override
     int hashCode();
index 34f50fb01597868d838fede49046e740816c53ac..00b1badfdb0133ab717c5950e03d9ffc6b95c3d7 100644 (file)
@@ -19,7 +19,7 @@ public interface UserMapNode extends MapNode, OrderedNodeContainer<MapEntryNode>
      * {@inheritDoc}
      *
      * <p>
-     * The implementation is required to define a user-visible iteration order, which must match {@link #getChild(int)}.
+     * The implementation is required to define a user-visible iteration order, which must match {@link #childAt(int)}.
      */
     @Override
     Map<NodeIdentifierWithPredicates, MapEntryNode> asMap();
index 0f589de9626fd0600e569c02a05bdd9ba9ac808d..f3704b54b3229d8f5710efb9dc61b8852479561a 100644 (file)
@@ -57,7 +57,7 @@ public class Bug4501Test {
         assertTrue(transformedInput instanceof UnkeyedListNode);
 
         final UnkeyedListNode hop = (UnkeyedListNode) transformedInput;
-        final DataContainerChild lrsBits = hop.getChild(0).childByArg(
+        final DataContainerChild lrsBits = hop.childAt(0).childByArg(
                 NodeIdentifier.create(QName.create("foo", "lrs-bits")));
 
         assertEquals(ImmutableSet.of("lookup", "rloc-probe", "strict"), lrsBits.body());
index 3d96375233e406ef016411d9009d9f7c8211728e..dfb2a49ca51c857340177a30ca920a485ed71551 100644 (file)
@@ -128,7 +128,7 @@ public class ImmutableUnkeyedListNodeBuilder implements CollectionNodeBuilder<Un
         }
 
         @Override
-        public UnkeyedListEntryNode getChild(final int position) {
+        public UnkeyedListEntryNode childAt(final int position) {
             throw new IndexOutOfBoundsException();
         }
 
@@ -167,7 +167,7 @@ public class ImmutableUnkeyedListNodeBuilder implements CollectionNodeBuilder<Un
         }
 
         @Override
-        public UnkeyedListEntryNode getChild(final int position) {
+        public UnkeyedListEntryNode childAt(final int position) {
             return children.get(position);
         }
 
index 95f844a99b5b299d9a8a424f452632150e2ece8b..f45f9da541ce595301a712c4c9b4cefa447998d2 100644 (file)
@@ -118,7 +118,7 @@ public class ImmutableUserLeafSetNodeBuilder<T> implements ListNodeBuilder<T, Us
         }
 
         @Override
-        public LeafSetEntryNode<T> getChild(final int position) {
+        public LeafSetEntryNode<T> childAt(final int position) {
             return Iterables.get(children.values(), position);
         }
 
index eb9935b299c5337c74df29b132f75bb3d58af536..4e887379f6487c16efe24fd6fba3c7e1c1f37c45 100644 (file)
@@ -139,7 +139,7 @@ public class ImmutableUserMapNodeBuilder implements CollectionNodeBuilder<MapEnt
         }
 
         @Override
-        public MapEntryNode getChild(final int position) {
+        public MapEntryNode childAt(final int position) {
             return Iterables.get(children.values(), position);
         }
 
index 085e42dfc07263e52ee0c8880455d8573c4302f5..699d0b66177f5b4a01eb5f0392ee8588bc3b6378 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.yangtools.yang.data.impl.schema;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.mock;
 
 import java.io.File;
@@ -130,9 +131,9 @@ public class BuilderTest {
         assertEquals(SIZE, orderedMapNodeCreateNull.size());
         assertEquals(orderedMapNodeCreateNode.size(), orderedMapNodeCreateNull.size() - 1);
         assertEquals(NODE_IDENTIFIER_LIST, orderedMapNodeCreateSize.getIdentifier());
-        assertEquals(LIST_MAIN_CHILD_1, orderedMapNodeCreateNull.getChild(0));
+        assertEquals(LIST_MAIN_CHILD_1, orderedMapNodeCreateNull.childAt(0));
         assertEquals(SIZE, orderedMapNodeCreateNull.size());
-        assertEquals(orderedMapNodeSchemaAware.getChild(0), orderedMapNodeSchemaAwareMapNodeConst.getChild(0));
+        assertEquals(orderedMapNodeSchemaAware.childAt(0), orderedMapNodeSchemaAwareMapNodeConst.childAt(0));
     }
 
     @Test
@@ -157,7 +158,7 @@ public class BuilderTest {
         assertNotNull(Builders.anyXmlBuilder());
         assertNotNull(orderedLeafSetShemaAware);
         assertEquals(1, ((UserLeafSetNode<?>)orderedLeafSet).size());
-        assertEquals("baz", orderedLeafSet.getChild(0).body());
+        assertEquals("baz", orderedLeafSet.childAt(0).body());
         assertNull(orderedLeafSet.childByArg(BAR_PATH));
         assertEquals(1, leafSetCollection.size());
         assertEquals(1, SchemaAwareleafSetCollection.size());
@@ -211,16 +212,12 @@ public class BuilderTest {
                 .build();
         final UnkeyedListNode unkeyedListNodeCreated = ImmutableUnkeyedListNodeBuilder.create(unkeyedListNode)
                 .build();
-        try {
-            unkeyedListNodeSize.getChild(1);
-        } catch (IndexOutOfBoundsException e) {
-            // Ignored on purpose
-        }
+
+        assertThrows(IndexOutOfBoundsException.class, () -> unkeyedListNodeSize.childAt(1));
 
         assertNotNull(unkeyedListNodeSize.body());
-        assertEquals(unkeyedListEntryNode, unkeyedListNodeCreated.getChild(0));
-        assertEquals(unkeyedListNode.getNodeType().getLocalName(), unkeyedListNodeSize.getNodeType()
-                .getLocalName());
+        assertEquals(unkeyedListEntryNode, unkeyedListNodeCreated.childAt(0));
+        assertEquals(unkeyedListNode.getNodeType().getLocalName(), unkeyedListNodeSize.getNodeType().getLocalName());
         assertNotNull(unkeyedListNodeCreated);
     }