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.controller.netconf.cli.reader.impl;
10 import com.google.common.base.Preconditions;
11 import java.util.Collections;
12 import java.util.HashSet;
13 import java.util.List;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
17 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
21 class SeparatedNodes {
22 private final Set<DataSchemaNode> keyNodes;
23 private final Set<DataSchemaNode> mandatoryNotKey;
24 private final Set<DataSchemaNode> otherNodes;
26 public SeparatedNodes(final Set<DataSchemaNode> keyNodes, final Set<DataSchemaNode> mandatoryNotKey,
27 final Set<DataSchemaNode> otherNodes) {
28 this.keyNodes = keyNodes;
29 this.mandatoryNotKey = mandatoryNotKey;
30 this.otherNodes = otherNodes;
33 public Set<DataSchemaNode> getKeyNodes() {
37 public Set<DataSchemaNode> getMandatoryNotKey() {
38 return mandatoryNotKey;
41 public Set<DataSchemaNode> getOthers() {
45 static SeparatedNodes separateNodes(final DataNodeContainer dataNodeContainer) {
46 return separateNodes(dataNodeContainer, false);
49 static SeparatedNodes separateNodes(final DataNodeContainer dataNodeContainer, final boolean removeConfigFalseNodes) {
50 final Set<DataSchemaNode> keys = new HashSet<>();
51 final Set<DataSchemaNode> mandatoryNotKeys = new HashSet<>();
52 final Set<DataSchemaNode> others = new HashSet<>();
54 List<QName> keyQNames = Collections.emptyList();
55 if (dataNodeContainer instanceof ListSchemaNode) {
56 keyQNames = ((ListSchemaNode) dataNodeContainer).getKeyDefinition();
59 for (final DataSchemaNode dataSchemaNode : dataNodeContainer.getChildNodes()) {
60 if (removeConfigFalseNodes) {
61 if (!dataSchemaNode.isConfiguration()) {
65 if (keyQNames.contains(dataSchemaNode.getQName())) {
66 Preconditions.checkArgument(dataSchemaNode instanceof LeafSchemaNode);
67 keys.add(dataSchemaNode);
68 } else if (dataSchemaNode.getConstraints().isMandatory()) {
69 mandatoryNotKeys.add(dataSchemaNode);
71 others.add(dataSchemaNode);
75 return new SeparatedNodes(keys, mandatoryNotKeys, others);