import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
/**
- * Node which is not leaf, but has child {@link NormalizedNode}s as its valzue.
+ * Node which is not leaf, but has child {@link NormalizedNode}s as its value.
*
* <p>
- * NormalizedNodeContainer does not have a value, but it has a child
- * nodes. Definition of possible and valid child nodes is introduced
- * in subclasses of this interface.
+ * NormalizedNodeContainer does not have a value, but it has a child nodes. Definition of possible and valid child nodes
+ * is introduced in subclasses of this interface.
*
* <p>
- * This interface should not be used directly, but rather use of of derived subinterfaces
- * such as {@link DataContainerNode}, {@link MapNode}, {@link LeafSetNode}.
+ * This interface should not be used directly, but rather use of of derived subclasses such as
+ * {@link DataContainerNode}, {@link MapNode}, {@link LeafSetNode}.
*
- * @param <I>
- * Node Identifier type
- * @param <K>
- * Child Node Identifier type
- * @param <V>
- * Child Node type
+ * @param <I> Node Identifier type
+ * @param <K> Child Node Identifier type
+ * @param <V> Child Node type
*/
public interface NormalizedNodeContainer<I extends PathArgument, K extends PathArgument,
V extends NormalizedNode<? extends K, ?>> extends NormalizedNode<I, Collection<V>> {
/**
* Returns immutable iteration of child nodes of this node.
- *
*/
@Override
Collection<V> getValue();
+ /**
+ * Return the logical size of this container, i.e. the number of children in contains.
+ *
+ * <p>
+ * Default implementation defers to the collection returned by {@link #getValue()}. Implementations are strongly
+ * encouraged to provide a more efficient implementation of this method.
+ *
+ * @return Number of child nodes in this container.
+ */
+ // FIXME: 6.0.0: consider making this method non-default
+ default int size() {
+ return getValue().size();
+ }
+
/**
* Returns child node identified by provided key.
*
- * @param child
- * Path argument identifying child node
- * @return Optional with child node if child exists.
- * {@link Optional#empty()} if child does not exists.
+ * @param child Path argument identifying child node
+ * @return Optional with child node if child exists. {@link Optional#empty()} if child does not exist.
*/
Optional<V> getChild(K child);
}
*/
if (!version.equals(subtreeVersion)) {
final Map<PathArgument, TreeNode> newChildren = MapAdaptor.getDefaultInstance().optimize(children);
- final int dataSize = getData().getValue().size();
- if (dataSize != newChildren.size()) {
- verify(dataSize > newChildren.size(), "Detected %s modified children, data has only %s",
- newChildren.size(), dataSize);
+ final int dataSize = getData().size();
+ final int childrenSize = newChildren.size();
+ if (dataSize != childrenSize) {
+ verify(dataSize > childrenSize, "Detected %s modified children, data has only %s",
+ childrenSize, dataSize);
ret = new LazyContainerNode(data, version, newChildren, subtreeVersion);
} else {
ret = new MaterializedContainerNode(data, version, newChildren, subtreeVersion);
@Override
public MutableTreeNode mutable() {
final Map<PathArgument, TreeNode> snapshot = snapshotChildren();
- if (snapshot.size() == castData().getValue().size()) {
+ if (snapshot.size() == castData().size()) {
return new MaterializedMutableContainerNode(this, snapshot);
}
assertTrue(outgoingLabelsList.orElse(null) instanceof MapNode);
MapNode outgoingLabelsMap = (MapNode) outgoingLabelsList.get();
- assertEquals(2, outgoingLabelsMap.getValue().size());
+ assertEquals(2, outgoingLabelsMap.size());
Collection<MapEntryNode> labels = outgoingLabelsMap.getValue();
NodeIdentifierWithPredicates firstNodeId =
NodeIdentifierWithPredicates.of(OUTGOING_LABELS_QNAME, INDEX_QNAME, 0);
return Optional.ofNullable(children.get(child));
}
+ @Override
+ public int size() {
+ return children.size();
+ }
+
@Override
protected int valueHashCode() {
return children.hashCode();
return withChild(child);
}
-
@Override
public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, MapEntryNode, MapNode> removeChild(
final PathArgument key) {
return UnmodifiableCollection.create(children.values());
}
+ @Override
+ public int size() {
+ return children.size();
+ }
+
@Override
protected int valueHashCode() {
return children.hashCode();
return Iterables.get(children.values(), position);
}
+ @Override
+ public int size() {
+ return children.size();
+ }
+
@Override
protected int valueHashCode() {
return children.hashCode();
return children.values();
}
+ @Override
+ public final int size() {
+ return children.size();
+ }
+
@Override
protected int valueHashCode() {
return children.hashCode();
private static int numOfChildrenFromValue(final NormalizedNode<?, ?> value) {
if (value instanceof NormalizedNodeContainer) {
- return ((NormalizedNodeContainer<?, ?, ?>) value).getValue().size();
+ return ((NormalizedNodeContainer<?, ?, ?>) value).size();
} else if (value instanceof UnkeyedListNode) {
return ((UnkeyedListNode) value).getSize();
}
assertEquals(orderedMapNodeCreateNode.getSize(), orderedMapNodeCreateNull.getSize() - 1);
assertEquals(NODE_IDENTIFIER_LIST, orderedMapNodeCreateSize.getIdentifier());
assertEquals(LIST_MAIN_CHILD_1, orderedMapNodeCreateNull.getChild(0));
- assertEquals(SIZE, orderedMapNodeCreateNull.getValue().size());
+ assertEquals(SIZE, orderedMapNodeCreateNull.size());
assertEquals(orderedMapNodeSchemaAware.getChild(0), orderedMapNodeSchemaAwareMapNodeConst.getChild(0));
}
final DataTreeModification modificationAfterTx = snapshotAfterTx.newModification();
final Optional<NormalizedNode<?, ?>> readNode = modificationAfterTx.readNode(TestModel.OUTER_LIST_PATH);
assertTrue(readNode.isPresent());
- assertEquals(2, ((NormalizedNodeContainer<?,?,?>)readNode.get()).getValue().size());
+ assertEquals(2, ((NormalizedNodeContainer<?,?,?>)readNode.get()).size());
}
@Test
DataTreeSnapshot test2 = inMemoryDataTree.takeSnapshot();
minMaxListRead = test2.readNode(MIN_MAX_LIST_PATH);
assertTrue(minMaxListRead.isPresent());
- assertTrue(((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).getValue().size() == 3);
+ assertEquals(3, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
DataTreeModification tempMod2 = test2.newModification();
tempMod2.write(MIN_MAX_LIST_PATH, mapNodeBaz);
DataTreeSnapshot test3 = inMemoryDataTree.takeSnapshot();
minMaxListRead = test3.readNode(MIN_MAX_LIST_PATH);
assertTrue(minMaxListRead.isPresent());
- assertTrue(((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).getValue().size() == 1);
+ assertEquals(1, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
assertTrue(minMaxListRead.get().getValue().toString().contains("test2"));
DataTreeModification tempMod3 = test3.newModification();
final Optional<NormalizedNodeContainer<?, ?, ?>> leafList = ((NormalizedNodeContainer) masterContainer.get())
.getChild(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
assertTrue(leafList.isPresent());
- assertTrue(leafList.get().getValue().size() == 3);
+ assertEquals(3, leafList.get().size());
}
@Test
final NormalizedNode<?, ?> data = inMemoryDataTree.takeSnapshot()
.readNode(YangInstanceIdentifier.empty()).get();
assertTrue(data instanceof ContainerNode);
- assertEquals(0, ((ContainerNode) data).getValue().size());
+ assertEquals(0, ((ContainerNode) data).size());
}
@Test
private static void testLoop(final DataTreeSnapshot snapshot, final String first, final String second) {
Optional<NormalizedNode<?, ?>> minMaxListRead = snapshot.readNode(MIN_MAX_LIST_PATH);
assertTrue(minMaxListRead.isPresent());
- assertTrue(((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).getValue().size() == 2);
+ assertEquals(2, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
UnmodifiableCollection<?> collectionChildren = (UnmodifiableCollection<?>) minMaxListRead.get().getValue();
for (Object collectionChild : collectionChildren) {
final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
final Optional<NormalizedNode<?, ?>> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
assertTrue(minMaxListRead.isPresent());
- assertTrue(((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).getValue().size() == 2);
+ assertEquals(2, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
}
@Test(expected = DataValidationFailedException.class)
DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
Optional<NormalizedNode<?, ?>> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
assertTrue(minMaxListRead.isPresent());
- assertTrue(((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).getValue().size() == 2);
+ assertEquals(2, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(gooPath, gooEntryNode);
snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
assertTrue(minMaxListRead.isPresent());
- assertTrue(((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).getValue().size() == 3);
+ assertEquals(3, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
modificationTree = inMemoryDataTree.takeSnapshot().newModification();
final Optional<NormalizedNodeContainer<?, ?, ?>> leafList = ((NormalizedNodeContainer) masterContainer.get())
.getChild(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
assertTrue(leafList.isPresent());
- assertTrue(leafList.get().getValue().size() == 2);
+ assertEquals(2, leafList.get().size());
}
@Test