import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.util.UnmodifiableCollection;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedNode;
-public class ImmutableOrderedLeafSetNodeBuilder<T> implements ListNodeBuilder<T, LeafSetEntryNode<T>> {
+public class ImmutableUserLeafSetNodeBuilder<T> implements ListNodeBuilder<T, UserLeafSetNode<T>> {
private Map<NodeWithValue, LeafSetEntryNode<T>> value;
private NodeIdentifier nodeIdentifier;
private boolean dirty;
- protected ImmutableOrderedLeafSetNodeBuilder() {
+ protected ImmutableUserLeafSetNodeBuilder() {
value = new LinkedHashMap<>();
dirty = false;
}
- protected ImmutableOrderedLeafSetNodeBuilder(final ImmutableOrderedLeafSetNode<T> node) {
+ protected ImmutableUserLeafSetNodeBuilder(final ImmutableUserLeafSetNode<T> node) {
nodeIdentifier = node.getIdentifier();
value = node.getChildren();
dirty = true;
}
- public static <T> @NonNull ListNodeBuilder<T, LeafSetEntryNode<T>> create() {
- return new ImmutableOrderedLeafSetNodeBuilder<>();
+ public static <T> @NonNull ListNodeBuilder<T, UserLeafSetNode<T>> create() {
+ return new ImmutableUserLeafSetNodeBuilder<>();
}
- public static <T> @NonNull ListNodeBuilder<T, LeafSetEntryNode<T>> create(final LeafSetNode<T> node) {
- if (!(node instanceof ImmutableOrderedLeafSetNode<?>)) {
+ public static <T> @NonNull ListNodeBuilder<T, UserLeafSetNode<T>> create(
+ final UserLeafSetNode<T> node) {
+ if (!(node instanceof ImmutableUserLeafSetNode<?>)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
- return new ImmutableOrderedLeafSetNodeBuilder<>((ImmutableOrderedLeafSetNode<T>) node);
+ return new ImmutableUserLeafSetNodeBuilder<>((ImmutableUserLeafSetNode<T>) node);
}
private void checkDirty() {
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withChild(final LeafSetEntryNode<T> child) {
+ public ImmutableUserLeafSetNodeBuilder<T> withChild(final LeafSetEntryNode<T> child) {
checkDirty();
this.value.put(child.getIdentifier(), child);
return this;
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withoutChild(final PathArgument key) {
+ public ImmutableUserLeafSetNodeBuilder<T> withoutChild(final PathArgument key) {
checkDirty();
this.value.remove(key);
return this;
}
@Override
- public OrderedLeafSetNode<T> build() {
+ public UserLeafSetNode<T> build() {
dirty = true;
- return new ImmutableOrderedLeafSetNode<>(nodeIdentifier, value);
+ return new ImmutableUserLeafSetNode<>(nodeIdentifier, value);
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
+ public ImmutableUserLeafSetNodeBuilder<T> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
this.nodeIdentifier = withNodeIdentifier;
return this;
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withValue(final Collection<LeafSetEntryNode<T>> withValue) {
+ public ImmutableUserLeafSetNodeBuilder<T> withValue(final Collection<LeafSetEntryNode<T>> withValue) {
checkDirty();
for (final LeafSetEntryNode<T> leafSetEntry : withValue) {
withChild(leafSetEntry);
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withChildValue(final T childValue) {
+ public ImmutableUserLeafSetNodeBuilder<T> withChildValue(final T childValue) {
return withChild(ImmutableLeafSetEntryNodeBuilder.<T>create()
.withNodeIdentifier(new NodeWithValue<>(nodeIdentifier.getNodeType(), childValue))
.withValue(childValue).build());
}
- protected static final class ImmutableOrderedLeafSetNode<T> extends
- AbstractImmutableNormalizedNode<NodeIdentifier, Collection<LeafSetEntryNode<T>>> implements
- OrderedLeafSetNode<T> {
-
+ protected static final class ImmutableUserLeafSetNode<T>
+ extends AbstractImmutableNormalizedNode<NodeIdentifier, UserLeafSetNode<?>>
+ implements UserLeafSetNode<T> {
private final Map<NodeWithValue, LeafSetEntryNode<T>> children;
- ImmutableOrderedLeafSetNode(final NodeIdentifier nodeIdentifier,
+ ImmutableUserLeafSetNode(final NodeIdentifier nodeIdentifier,
final Map<NodeWithValue, LeafSetEntryNode<T>> children) {
super(nodeIdentifier);
this.children = children;
}
@Override
- public Optional<LeafSetEntryNode<T>> getChild(final NodeWithValue child) {
- return Optional.ofNullable(children.get(child));
+ public LeafSetEntryNode<T> childByArg(final NodeWithValue child) {
+ return children.get(child);
}
@Override
}
@Override
- protected int valueHashCode() {
- return children.hashCode();
+ public int size() {
+ return children.size();
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
- private Map<NodeWithValue, LeafSetEntryNode<T>> getChildren() {
- return Collections.unmodifiableMap(children);
+ @Override
+ public Collection<LeafSetEntryNode<T>> body() {
+ return UnmodifiableCollection.create(children.values());
}
@Override
- protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
- return children.equals(((ImmutableOrderedLeafSetNode<?>) other).children);
+ protected Class<UserLeafSetNode<?>> implementedType() {
+ return (Class) UserLeafSetNode.class;
}
@Override
- public int getSize() {
- return children.size();
+ protected int valueHashCode() {
+ return children.hashCode();
}
@Override
- public Collection<LeafSetEntryNode<T>> getValue() {
- return UnmodifiableCollection.create(children.values());
+ protected boolean valueEquals(final UserLeafSetNode<?> other) {
+ return children.equals(((ImmutableUserLeafSetNode<?>) other).children);
+ }
+
+ @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+ justification = "https://github.com/spotbugs/spotbugs/issues/811")
+ private Map<NodeWithValue, LeafSetEntryNode<T>> getChildren() {
+ return Collections.unmodifiableMap(children);
}
}
@Override
- public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, LeafSetEntryNode<T>, LeafSetNode<T>> addChild(
- final LeafSetEntryNode<T> child) {
+ public ImmutableUserLeafSetNodeBuilder<T> addChild(final LeafSetEntryNode<T> child) {
return withChild(child);
}
@Override
- public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, LeafSetEntryNode<T>, LeafSetNode<T>>
- removeChild(final PathArgument key) {
+ public ImmutableUserLeafSetNodeBuilder<T> removeChild(final PathArgument key) {
return withoutChild(key);
}
}