+/*
+ * 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.sal.restconf.impl;
+import com.google.common.base.Preconditions;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.ModifyAction;
import org.opendaylight.yangtools.yang.data.api.SimpleNode;
import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
-import com.google.common.base.Preconditions;
-
public final class CompositeNodeWrapper implements NodeWrapper<CompositeNode>, CompositeNode {
private MutableCompositeNode compositeNode;
private QName name;
private List<NodeWrapper<?>> values = new ArrayList<>();
- public CompositeNodeWrapper(String localName) {
+ public CompositeNodeWrapper(final String localName) {
this.localName = Preconditions.checkNotNull(localName);
}
- public CompositeNodeWrapper(URI namespace, String localName) {
+ public CompositeNodeWrapper(final URI namespace, final String localName) {
this(localName);
this.namespace = namespace;
}
-
+
@Override
- public void setQname(QName name) {
+ public void setQname(final QName name) {
Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
this.name = name;
}
-
+
@Override
public QName getQname() {
return name;
}
@Override
- public void setNamespace(URI namespace) {
+ public void setNamespace(final URI namespace) {
Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
this.namespace = namespace;
}
- public void addValue(NodeWrapper<?> value) {
+ public void addValue(final NodeWrapper<?> value) {
Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
values.add(value);
}
- public void removeValue(NodeWrapper<CompositeNode> value) {
+ public void removeValue(final NodeWrapper<CompositeNode> value) {
Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
values.remove(value);
}
-
+
public List<NodeWrapper<?>> getValues() {
Preconditions.checkState(compositeNode == null, "Data can be inconsistent.");
return Collections.unmodifiableList(values);
}
-
+
@Override
public boolean isChangeAllowed() {
return compositeNode == null ? true : false;
Preconditions.checkNotNull(namespace);
name = new QName(namespace, localName);
}
-
- List<Node<?>> nodeValues = new ArrayList<>();
+
+ List<Node<?>> nodeValues = new ArrayList<>(values.size());
for (NodeWrapper<?> nodeWrapper : values) {
nodeValues.add(nodeWrapper.unwrap());
}
compositeNode = NodeFactory.createMutableCompositeNode(name, null, nodeValues, null, null);
-
+
values = null;
namespace = null;
localName = null;
return unwrap().getNodeType();
}
+ @Deprecated
@Override
public CompositeNode getParent() {
return unwrap().getParent();
return unwrap().getModificationAction();
}
+ /**
+ * @deprecated Use {@link #getValue()} instead.
+ */
+ @Deprecated
@Override
public List<Node<?>> getChildren() {
- return unwrap().getChildren();
+ return unwrap().getValue();
}
@Override
- public List<CompositeNode> getCompositesByName(QName children) {
+ public List<CompositeNode> getCompositesByName(final QName children) {
return unwrap().getCompositesByName(children);
}
@Override
- public List<CompositeNode> getCompositesByName(String children) {
+ public List<CompositeNode> getCompositesByName(final String children) {
return unwrap().getCompositesByName(children);
}
@Override
- public List<SimpleNode<?>> getSimpleNodesByName(QName children) {
+ public List<SimpleNode<?>> getSimpleNodesByName(final QName children) {
return unwrap().getSimpleNodesByName(children);
}
@Override
- public List<SimpleNode<?>> getSimpleNodesByName(String children) {
+ public List<SimpleNode<?>> getSimpleNodesByName(final String children) {
return unwrap().getSimpleNodesByName(children);
}
@Override
- public CompositeNode getFirstCompositeByName(QName container) {
+ public CompositeNode getFirstCompositeByName(final QName container) {
return unwrap().getFirstCompositeByName(container);
}
@Override
- public SimpleNode<?> getFirstSimpleByName(QName leaf) {
+ public SimpleNode<?> getFirstSimpleByName(final QName leaf) {
return unwrap().getFirstSimpleByName(leaf);
}
}
@Override
- public List<Node<?>> setValue(List<Node<?>> value) {
+ public List<Node<?>> setValue(final List<Node<?>> value) {
return unwrap().setValue(value);
}
}
@Override
- public boolean containsKey(Object key) {
+ public boolean containsKey(final Object key) {
return unwrap().containsKey(key);
}
@Override
- public boolean containsValue(Object value) {
+ public boolean containsValue(final Object value) {
return unwrap().containsValue(value);
}
@Override
- public List<Node<?>> get(Object key) {
+ public List<Node<?>> get(final Object key) {
return unwrap().get(key);
}
@Override
- public List<Node<?>> put(QName key, List<Node<?>> value) {
+ public List<Node<?>> put(final QName key, final List<Node<?>> value) {
return unwrap().put(key, value);
}
@Override
- public List<Node<?>> remove(Object key) {
+ public List<Node<?>> remove(final Object key) {
return unwrap().remove(key);
}
@Override
- public void putAll(Map<? extends QName, ? extends List<Node<?>>> m) {
+ public void putAll(final Map<? extends QName, ? extends List<Node<?>>> m) {
unwrap().putAll(m);
}