Populate data/ hierarchy
[yangtools.git] / data / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / DistinctNodeContainer.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
15
16 /**
17  * A {@link NormalizedNodeContainer} which contains directly-addressable children. It
18  *
19  * <p>
20  * NormalizedNodeContainer does not have a value, but it has a child nodes. Definition of possible and valid child nodes
21  * is introduced in subclasses of this interface.
22  *
23  * <p>
24  * This interface should not be used directly, but rather use of of derived subclasses such as
25  * {@link DataContainerNode}, {@link MapNode}, {@link LeafSetNode}.
26  *
27  * @param <K> Child path argument type
28  * @param <V> Child Node type
29  */
30 public interface DistinctNodeContainer<K extends PathArgument, V extends NormalizedNode>
31         extends NormalizedNodeContainer<V> {
32     /**
33      * {@inheritDoc}
34      *
35      * <p>
36      * All nodes returned in this iterable, MUST also be accessible via {@link #childByArg(PathArgument)} using their
37      * associated identifier.
38      *
39      * @return Iteration of all child nodes
40      */
41     @Override
42     Collection<@NonNull V> body();
43
44     /**
45      * Returns a child node identified by provided key.
46      *
47      * @param key Path argument identifying child node
48      * @return Matching child node, or null if no matching child exists
49      * @throws NullPointerException if {@code key} is null
50      */
51     @Nullable V childByArg(K key);
52
53     /**
54      * Attempts to find a child node identified by provided key.
55      *
56      * @param key Path argument identifying child node
57      * @return Optional with child node if child exists. {@link Optional#empty()} if child does not exist
58      * @throws NullPointerException if {@code key} is null
59      */
60     default Optional<V> findChildByArg(final K key) {
61         return Optional.ofNullable(childByArg(key));
62     }
63 }