*/
package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerNode;
-import com.google.common.collect.Maps;
+abstract class AbstractImmutableDataContainerNodeBuilder<I extends YangInstanceIdentifier.PathArgument, R extends DataContainerNode<I>> implements DataContainerNodeBuilder<I, R> {
-abstract class AbstractImmutableDataContainerNodeBuilder<I extends InstanceIdentifier.PathArgument, R extends DataContainerNode<I>>
- implements DataContainerNodeBuilder<I, R> {
-
- private Map<InstanceIdentifier.PathArgument, DataContainerChild<? extends InstanceIdentifier.PathArgument, ?>> value;
+ private Map<YangInstanceIdentifier.PathArgument, DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> value;
private I nodeIdentifier;
/*
private boolean dirty;
protected AbstractImmutableDataContainerNodeBuilder() {
- this.value = Maps.newHashMap();
+ this.value = new HashMap<>();
+ this.dirty = false;
+ }
+
+ protected AbstractImmutableDataContainerNodeBuilder(final int sizeHint) {
+ this.value = new HashMap<>(sizeHint);
+ this.dirty = false;
+ }
+
+ protected AbstractImmutableDataContainerNodeBuilder(final AbstractImmutableDataContainerNode<I> node) {
+ this.nodeIdentifier = node.getIdentifier();
+ this.value = node.getChildren();
+ this.dirty = true;
}
protected final I getNodeIdentifier() {
private void checkDirty() {
if (dirty) {
- value = Maps.newHashMap(value);
+ value = new HashMap<>(value);
dirty = false;
}
}
@Override
- public DataContainerNodeBuilder<I, R> withValue(final List<DataContainerChild<? extends InstanceIdentifier.PathArgument, ?>> value) {
+ public DataContainerNodeBuilder<I, R> withValue(final List<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> value) {
// TODO Replace or putAll ?
- for (final DataContainerChild<? extends InstanceIdentifier.PathArgument, ?> dataContainerChild : value) {
+ for (final DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> dataContainerChild : value) {
withChild(dataContainerChild);
}
return this;
return this;
}
+ @Override
+ public DataContainerNodeBuilder<I, R> withoutChild(final PathArgument key) {
+ checkDirty();
+ this.value.remove(key);
+ return this;
+ }
+
@Override
public DataContainerNodeBuilder<I, R> withNodeIdentifier(final I nodeIdentifier) {
this.nodeIdentifier = nodeIdentifier;
final DataContainerChild<? extends PathArgument, ?> child) {
return withChild(child);
}
+
+ @Override
+ public NormalizedNodeContainerBuilder<I, PathArgument, DataContainerChild<? extends PathArgument, ?>, R> removeChild(final PathArgument key) {
+ return withoutChild(key);
+ }
}