Add NormalizedNodeContainer.size()
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / NormalizedNodeContainer.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.data.api.schema;
9
10 import java.util.Collection;
11 import java.util.Optional;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
13
14 /**
15  * Node which is not leaf, but has child {@link NormalizedNode}s as its value.
16  *
17  * <p>
18  * NormalizedNodeContainer does not have a value, but it has a child nodes. Definition of possible and valid child nodes
19  * is introduced in subclasses of this interface.
20  *
21  * <p>
22  * This interface should not be used directly, but rather use of of derived subclasses such as
23  * {@link DataContainerNode}, {@link MapNode}, {@link LeafSetNode}.
24  *
25  * @param <I> Node Identifier type
26  * @param <K> Child Node Identifier type
27  * @param <V> Child Node type
28  */
29 public interface NormalizedNodeContainer<I extends PathArgument, K extends PathArgument,
30        V extends NormalizedNode<? extends K, ?>> extends NormalizedNode<I, Collection<V>> {
31
32     @Override
33     I getIdentifier();
34
35     /**
36      * Returns immutable iteration of child nodes of this node.
37      */
38     @Override
39     Collection<V> getValue();
40
41     /**
42      * Return the logical size of this container, i.e. the number of children in contains.
43      *
44      * <p>
45      * Default implementation defers to the collection returned by {@link #getValue()}. Implementations are strongly
46      * encouraged to provide a more efficient implementation of this method.
47      *
48      * @return Number of child nodes in this container.
49      */
50     // FIXME: 6.0.0: consider making this method non-default
51     default int size() {
52         return getValue().size();
53     }
54
55     /**
56      * Returns child node identified by provided key.
57      *
58      * @param child Path argument identifying child node
59      * @return Optional with child node if child exists. {@link Optional#empty()} if child does not exist.
60      */
61     Optional<V> getChild(K child);
62 }