2 * Copyright (c) 2015 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.util;
10 import com.google.common.collect.ImmutableMap;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
18 class ChoiceNodeContextNode extends AbstractMixinContextNode<NodeIdentifier> {
20 private final ImmutableMap<QName, DataSchemaContextNode<?>> byQName;
21 private final ImmutableMap<PathArgument, DataSchemaContextNode<?>> byArg;
23 protected ChoiceNodeContextNode(final ChoiceSchemaNode schema) {
24 super(NodeIdentifier.create(schema.getQName()), schema);
25 ImmutableMap.Builder<QName, DataSchemaContextNode<?>> byQNameBuilder = ImmutableMap.builder();
26 ImmutableMap.Builder<PathArgument, DataSchemaContextNode<?>> byArgBuilder = ImmutableMap.builder();
28 for (CaseSchemaNode caze : schema.getCases().values()) {
29 for (DataSchemaNode cazeChild : caze.getChildNodes()) {
30 DataSchemaContextNode<?> childOp = fromDataSchemaNode(cazeChild);
31 byArgBuilder.put(childOp.getIdentifier(), childOp);
32 for (QName qname : childOp.getQNameIdentifiers()) {
33 byQNameBuilder.put(qname, childOp);
37 byQName = byQNameBuilder.build();
38 byArg = byArgBuilder.build();
42 public DataSchemaContextNode<?> getChild(final PathArgument child) {
43 return byArg.get(child);
47 public DataSchemaContextNode<?> getChild(final QName child) {
48 return byQName.get(child);