Remove StoreTreeNodes.getChild()
[yangtools.git] / data / yang-data-tree-spi / src / main / java / org / opendaylight / yangtools / yang / data / tree / spi / AbstractRecursiveCandidateNode.java
1 /*
2  * Copyright (c) 2015 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.tree.spi;
9
10 import com.google.common.collect.Collections2;
11 import java.util.Collection;
12 import java.util.Optional;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
17
18 abstract class AbstractRecursiveCandidateNode extends AbstractDataTreeCandidateNode {
19     AbstractRecursiveCandidateNode(final DistinctNodeContainer<PathArgument, NormalizedNode> data) {
20         super(data);
21     }
22
23     @Override
24     public final Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
25         return data().findChildByArg(identifier).map(this::createChild);
26     }
27
28     @Override
29     public final Collection<DataTreeCandidateNode> getChildNodes() {
30         return Collections2.transform(data().body(), this::createChild);
31     }
32
33     abstract DataTreeCandidateNode createContainer(DistinctNodeContainer<PathArgument, NormalizedNode> childData);
34
35     abstract DataTreeCandidateNode createLeaf(NormalizedNode childData);
36
37     @SuppressWarnings("unchecked")
38     private DataTreeCandidateNode createChild(final NormalizedNode childData) {
39         if (childData instanceof DistinctNodeContainer) {
40             return createContainer((DistinctNodeContainer<PathArgument, NormalizedNode>) childData);
41         }
42         return createLeaf(childData);
43     }
44 }