2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.api.schema;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.base.VerifyException;
13 import java.util.Collection;
14 import java.util.Optional;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
20 * A {@link NormalizedNodeContainer} which contains directly-addressable children. It
23 * NormalizedNodeContainer does not have a value, but it has a child nodes. Definition of possible and valid child nodes
24 * is introduced in subclasses of this interface.
27 * This interface should not be used directly, but rather use of of derived subclasses such as
28 * {@link DataContainerNode}, {@link MapNode}, {@link LeafSetNode}.
30 * @param <K> Child path argument type
31 * @param <V> Child Node type
33 public interface DistinctNodeContainer<K extends PathArgument, V extends NormalizedNode>
34 extends NormalizedNodeContainer<V> {
39 * All nodes returned in this iterable, MUST also be accessible via {@link #childByArg(PathArgument)} using their
40 * associated identifier.
42 * @return Iteration of all child nodes
45 Collection<@NonNull V> body();
48 * Returns a child node identified by provided key.
50 * @param key Path argument identifying child node
51 * @return Matching child node, or null if no matching child exists
52 * @throws NullPointerException if {@code key} is null
54 @Nullable V childByArg(K key);
57 * Attempts to find a child node identified by provided key.
59 * @param key Path argument identifying child node
60 * @return Optional with child node if child exists. {@link Optional#empty()} if child does not exist
61 * @throws NullPointerException if {@code key} is null
63 default Optional<V> findChildByArg(final K key) {
64 return Optional.ofNullable(childByArg(key));
68 * Returns a child node identified by provided key, asserting its presence.
70 * @param key Path argument identifying child node
71 * @return Matching child node
72 * @throws NullPointerException if {@code key} is null
73 * @throws VerifyException if the child does not exist
75 default @NonNull V getChildByArg(final K key) {
76 return verifyNotNull(childByArg(key));