2 * Copyright (c) 2014 Cisco Systems, Inc. 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.tree;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.base.VerifyException;
13 import java.util.Optional;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
19 * A tree node which has references to its child leaves. These are typically internal non-data leaves, such as
20 * containers, lists, etc.
22 * @param <C> Final node type
24 public interface StoreTreeNode<C extends StoreTreeNode<C>> {
26 * Returns a direct child of the node.
28 * @param arg Identifier of child
29 * @return A node if the child is existing, {@code null} otherwise.
30 * @throws NullPointerException when {@code child} is null
32 @Nullable C childByArg(PathArgument arg);
35 * Returns a direct child of the node.
37 * @param arg Identifier of child
38 * @return A child node
39 * @throws NullPointerException when {@code child} is null
40 * @throws VerifyException if the child does not exist
42 default @NonNull C getChildByArg(final PathArgument arg) {
43 return verifyNotNull(childByArg(arg), "Child %s does not exist");
47 * Returns a direct child of the node.
49 * @param arg Identifier of child
50 * @return Optional with node if the child exists, {@link Optional#empty()} otherwise.
51 * @throws NullPointerException when {@code child} is null
53 @NonNull default Optional<C> findChildByArg(final PathArgument arg) {
54 return Optional.ofNullable(childByArg(arg));