import static com.google.common.base.Preconditions.checkState;
-import java.util.LinkedHashMap;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import org.opendaylight.yangtools.concepts.Identifiable;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
import com.google.common.primitives.UnsignedLong;
public class StoreMetadataNode implements Immutable, Identifiable<PathArgument>, StoreTreeNode<StoreMetadataNode> {
this.children = Preconditions.checkNotNull(children);
}
+ public static StoreMetadataNode createEmpty(final NormalizedNode<?, ?> data) {
+ return new StoreMetadataNode(data, UnsignedLong.ZERO, UnsignedLong.ZERO,
+ Collections.<PathArgument, StoreMetadataNode>emptyMap());
+ }
+
+ public StoreMetadataNode(final NormalizedNode<?, ?> data, final UnsignedLong nodeVersion,
+ final UnsignedLong subtreeVersion) {
+ this(data, nodeVersion, subtreeVersion, Collections.<PathArgument, StoreMetadataNode>emptyMap());
+ }
+
public static Builder builder() {
return new Builder();
}
+ public static Builder builder(StoreMetadataNode node) {
+ return new Builder(node);
+ }
+
public UnsignedLong getNodeVersion() {
return this.nodeVersion;
}
return this.data;
}
- public Iterable<StoreMetadataNode> getChildren() {
- return Iterables.unmodifiableIterable(children.values());
- }
-
@Override
public Optional<StoreMetadataNode> getChild(final PathArgument key) {
return Optional.fromNullable(children.get(key));
private UnsignedLong nodeVersion;
private UnsignedLong subtreeVersion;
private NormalizedNode<?, ?> data;
- private Map<PathArgument, StoreMetadataNode> children = new LinkedHashMap<>();
+ private Map<PathArgument, StoreMetadataNode> children;
private boolean dirty = false;
- private Builder() {}
+ private Builder() {
+ children = new HashMap<>();
+ }
+ public Builder(StoreMetadataNode node) {
+ children = new HashMap<>(node.children);
+ }
public UnsignedLong getVersion() {
return nodeVersion;
public Builder add(final StoreMetadataNode node) {
if (dirty) {
- children = new LinkedHashMap<>(children);
+ children = new HashMap<>(children);
dirty = false;
}
children.put(node.getIdentifier(), node);
return this;
}
+ public Builder remove(final PathArgument id) {
+ if (dirty) {
+ children = new HashMap<>(children);
+ dirty = false;
+ }
+ children.remove(id);
+ return this;
+ }
+
public StoreMetadataNode build() {
checkState(data != null, "Data node should not be null.");
checkState(subtreeVersion.compareTo(nodeVersion) >= 0,
public static StoreMetadataNode createRecursively(final NormalizedNode<?, ?> node, final UnsignedLong version) {
return createRecursively(node, version, version);
}
-
}