/* * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.netconf.cli.reader.impl; import com.google.common.base.Preconditions; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; class SeparatedNodes { private final Set keyNodes; private final Set mandatoryNotKey; private final Set otherNodes; public SeparatedNodes(final Set keyNodes, final Set mandatoryNotKey, final Set otherNodes) { this.keyNodes = keyNodes; this.mandatoryNotKey = mandatoryNotKey; this.otherNodes = otherNodes; } public Set getKeyNodes() { return keyNodes; } public Set getMandatoryNotKey() { return mandatoryNotKey; } public Set getOthers() { return otherNodes; } static SeparatedNodes separateNodes(final DataNodeContainer dataNodeContainer) { return separateNodes(dataNodeContainer, false); } static SeparatedNodes separateNodes(final DataNodeContainer dataNodeContainer, final boolean removeConfigFalseNodes) { final Set keys = new HashSet<>(); final Set mandatoryNotKeys = new HashSet<>(); final Set others = new HashSet<>(); List keyQNames = Collections.emptyList(); if (dataNodeContainer instanceof ListSchemaNode) { keyQNames = ((ListSchemaNode) dataNodeContainer).getKeyDefinition(); } for (final DataSchemaNode dataSchemaNode : dataNodeContainer.getChildNodes()) { if (removeConfigFalseNodes) { if (!dataSchemaNode.isConfiguration()) { continue; } } if (keyQNames.contains(dataSchemaNode.getQName())) { Preconditions.checkArgument(dataSchemaNode instanceof LeafSchemaNode); keys.add(dataSchemaNode); } else if (dataSchemaNode.getConstraints().isMandatory()) { mandatoryNotKeys.add(dataSchemaNode); } else { others.add(dataSchemaNode); } } return new SeparatedNodes(keys, mandatoryNotKeys, others); } }