Rework NormalizedNode type hierarchy
[yangtools.git] / yang / 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 <I> Path argument type
28  * @param <K> Child path argument type
29  * @param <V> Child Node type
30  */
31 public interface DistinctNodeContainer<I extends PathArgument, K extends PathArgument, V extends NormalizedNode>
32         extends NormalizedNodeContainer<I, V> {
33     /**
34      * {@inheritDoc}
35      *
36      * <p>
37      * All nodes returned in this iterable, MUST also be accessible via {@link #childByArg(PathArgument)} using their
38      * associated identifier.
39      *
40      * @return Iteration of all child nodes
41      */
42     @Override
43     Collection<@NonNull V> body();
44
45     /**
46      * Returns a child node identified by provided key.
47      *
48      * @param key Path argument identifying child node
49      * @return Matching child node, or null if no matching child exists
50      * @throws NullPointerException if {@code key} is null
51      */
52     @Nullable V childByArg(K key);
53
54     /**
55      * Attempts to find a child node identified by provided key.
56      *
57      * @param key Path argument identifying child node
58      * @return Optional with child node if child exists. {@link Optional#empty()} if child does not exist
59      * @throws NullPointerException if {@code key} is null
60      */
61     default Optional<V> findChildByArg(final K key) {
62         return Optional.ofNullable(childByArg(key));
63     }
64 }