Split out static classes
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / ChoiceModificationStrategy.java
1 /*
2  * Copyright (c) 2014 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.impl.schema.tree;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11 import com.google.common.base.Optional;
12 import com.google.common.collect.ImmutableMap;
13 import java.util.Map;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
18 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder;
19 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
20 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
22
23 final class ChoiceModificationStrategy extends NormalizedNodeContainerModificationStrategy {
24     private final Map<YangInstanceIdentifier.PathArgument, ModificationApplyOperation> childNodes;
25
26     ChoiceModificationStrategy(final ChoiceSchemaNode schemaNode) {
27         super(ChoiceNode.class);
28         ImmutableMap.Builder<YangInstanceIdentifier.PathArgument, ModificationApplyOperation> child = ImmutableMap.builder();
29
30         for (ChoiceCaseNode caze : schemaNode.getCases()) {
31             for (DataSchemaNode cazeChild : caze.getChildNodes()) {
32                 SchemaAwareApplyOperation childNode = SchemaAwareApplyOperation.from(cazeChild);
33                 child.put(new YangInstanceIdentifier.NodeIdentifier(cazeChild.getQName()), childNode);
34             }
35         }
36         childNodes = child.build();
37     }
38
39     @Override
40     public Optional<ModificationApplyOperation> getChild(final YangInstanceIdentifier.PathArgument child) {
41         return Optional.fromNullable(childNodes.get(child));
42     }
43
44     @Override
45     @SuppressWarnings("rawtypes")
46     protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
47         checkArgument(original instanceof ChoiceNode);
48         return ImmutableChoiceNodeBuilder.create((ChoiceNode) original);
49     }
50 }