import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
@Override
public boolean apply(final @Nonnull ModifiedNode input) {
Preconditions.checkNotNull(input);
- switch (input.getType()) {
+ switch (input.getOperation()) {
case DELETE:
case MERGE:
case WRITE:
return true;
- case SUBTREE_MODIFIED:
- case UNMODIFIED:
+ case TOUCH:
+ case NONE:
return false;
}
- throw new IllegalArgumentException(String.format("Unhandled modification type %s", input.getType()));
+ throw new IllegalArgumentException(String.format("Unhandled modification type %s", input.getOperation()));
}
};
private final Map<PathArgument, ModifiedNode> children;
private final Optional<TreeNode> original;
private final PathArgument identifier;
- private ModificationType modificationType = ModificationType.UNMODIFIED;
+ private LogicalOperation operation = LogicalOperation.NONE;
private Optional<TreeNode> snapshotCache;
private NormalizedNode<?, ?> value;
return identifier;
}
- /**
- *
- * Returns original store metadata
- * @return original store metadata
- */
@Override
Optional<TreeNode> getOriginal() {
return original;
}
- /**
- * Returns modification type
- *
- * @return modification type
- */
+
@Override
- ModificationType getType() {
- return modificationType;
+ LogicalOperation getOperation() {
+ return operation;
}
/**
*/
ModifiedNode modifyChild(final PathArgument child, final boolean isOrdered) {
clearSnapshot();
- if (modificationType == ModificationType.UNMODIFIED) {
- updateModificationType(ModificationType.SUBTREE_MODIFIED);
+ if (operation == LogicalOperation.NONE) {
+ updateModificationType(LogicalOperation.TOUCH);
}
final ModifiedNode potential = children.get(child);
if (potential != null) {
* @return all recorded direct child modifications
*/
@Override
- Iterable<ModifiedNode> getChildren() {
+ Collection<ModifiedNode> getChildren() {
return children.values();
}
* Records a delete for associated node.
*/
void delete() {
- final ModificationType newType;
+ final LogicalOperation newType;
- switch (modificationType) {
+ switch (operation) {
case DELETE:
- case UNMODIFIED:
+ case NONE:
// We need to record this delete.
- newType = ModificationType.DELETE;
+ newType = LogicalOperation.DELETE;
break;
case MERGE:
- case SUBTREE_MODIFIED:
+ case TOUCH:
case WRITE:
/*
* We are canceling a previous modification. This is a bit tricky,
* As documented in BUG-2470, a delete of data introduced in this
* transaction needs to be turned into a no-op.
*/
- newType = original.isPresent() ? ModificationType.DELETE : ModificationType.UNMODIFIED;
+ newType = original.isPresent() ? LogicalOperation.DELETE : LogicalOperation.NONE;
break;
default:
- throw new IllegalStateException("Unhandled deletion of node with " + modificationType);
+ throw new IllegalStateException("Unhandled deletion of node with " + operation);
}
clearSnapshot();
*/
void write(final NormalizedNode<?, ?> value) {
clearSnapshot();
- updateModificationType(ModificationType.WRITE);
+ updateModificationType(LogicalOperation.WRITE);
children.clear();
this.value = value;
}
void merge(final NormalizedNode<?, ?> value) {
clearSnapshot();
- updateModificationType(ModificationType.MERGE);
+ updateModificationType(LogicalOperation.MERGE);
/*
* Blind overwrite of any previous data is okay, no matter whether the node
final ModifiedNode child = it.next();
child.seal();
- if (child.modificationType == ModificationType.UNMODIFIED) {
+ if (child.operation == LogicalOperation.NONE) {
it.remove();
}
}
- // A SUBTREE_MODIFIED node without any children is a no-op
- if (modificationType == ModificationType.SUBTREE_MODIFIED && children.isEmpty()) {
- updateModificationType(ModificationType.UNMODIFIED);
+ // A TOUCH node without any children is a no-op
+ if (operation == LogicalOperation.TOUCH && children.isEmpty()) {
+ updateModificationType(LogicalOperation.NONE);
}
}
return snapshot;
}
- private void updateModificationType(final ModificationType type) {
- modificationType = type;
+ private void updateModificationType(final LogicalOperation type) {
+ operation = type;
clearSnapshot();
}
@Override
public String toString() {
return "NodeModification [identifier=" + identifier + ", modificationType="
- + modificationType + ", childModification=" + children + "]";
+ + operation + ", childModification=" + children + "]";
}
/**