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 final class ChoiceNodeContextNode extends AbstractMixinContextNode<NodeIdentifier> {
19 private final ImmutableMap<QName, DataSchemaContextNode<?>> byQName;
20 private final ImmutableMap<PathArgument, DataSchemaContextNode<?>> byArg;
22 ChoiceNodeContextNode(final ChoiceSchemaNode schema) {
23 super(NodeIdentifier.create(schema.getQName()), schema);
24 ImmutableMap.Builder<QName, DataSchemaContextNode<?>> byQNameBuilder = ImmutableMap.builder();
25 ImmutableMap.Builder<PathArgument, DataSchemaContextNode<?>> byArgBuilder = ImmutableMap.builder();
27 for (CaseSchemaNode caze : schema.getCases()) {
28 for (DataSchemaNode cazeChild : caze.getChildNodes()) {
29 DataSchemaContextNode<?> childOp = DataSchemaContextNode.of(cazeChild);
30 byArgBuilder.put(childOp.getIdentifier(), childOp);
31 for (QName qname : childOp.getQNameIdentifiers()) {
32 byQNameBuilder.put(qname, childOp);
36 byQName = byQNameBuilder.build();
37 byArg = byArgBuilder.build();
41 public DataSchemaContextNode<?> getChild(final PathArgument child) {
42 return byArg.get(child);
46 public DataSchemaContextNode<?> getChild(final QName child) {
47 return byQName.get(child);