@Override public boolean remove() { if (!isRoot() && exists()) { head().getMutableNodeState(); // Make sure the removed node is connected parent.head().getMutableNodeState().removeChildNode(name); updated(); return true; } else { return false; } }
@Override public MutableNodeState getMutableNodeState() { // switch to connected state recursively up to the parent MutableNodeState parentState = builder.parent.head().getMutableNodeState(); MutableNodeState state = parentState.getMutableChildNode(builder.name); // triggers a head state transition at next access return new ConnectedHead(builder, state).getMutableNodeState(); }
@Override public void setRoot(NodeState newRoot) { checkNotMerged(); this.root = ModifiedNodeState.squeeze(newRoot); }
/** * Replaces the current state of this builder with the given node state. * The base state remains unchanged. * * @param newState new state */ protected void set(NodeState newState) { if (parent == null) { // updating the base revision forces all sub-builders to refresh baseRevision = rootHead.setState(newState); } else { parent.setChildNode(name, newState); } }
@Override public boolean isReplaced() { return head().isReplaced(); }
@Override public Head update() { if (revision != builder.rootBuilder.baseRevision) { // the root builder's base state has been reset: transition back // to unconnected and connect again if necessary. // No need to pass base() instead of base as the subsequent // call to update will take care of updating to the latest state. builder.head = new UnconnectedHead(builder, builder.base); return builder.head.update(); } else { return this; } }
@Override public boolean isModified() { return head().isModified(); }
/** * Create a multi valued {@code PropertyState} from a list of strings. * @param name The name of the property state * @param values The values of the property state * @return The new property state of type {@link Type#STRINGS} */ public static PropertyState stringProperty(String name, Iterable<String> values) { return new MultiStringPropertyState(name, values); }
/** * Create a new instance for building scalar {@code PropertyState} instances * of the given {@code type}. * @param type type of the {@code PropertyState} instances to be built. * @return {@code PropertyBuilder} for {@code type} */ public static <T> PropertyBuilder<T> scalar(Type<T> type) { return new PropertyBuilder<T>(type); }
/** * Create a {@code PropertyState} from a URI. No validation is performed * on the string passed for {@code value}. * @param name The name of the property state * @param value The value of the property state * @return The new property state of type {@link Type#URI} */ public static PropertyState uriProperty(String name, String value) { return new GenericPropertyState(name, value, URI); }
/** * Create a multi valued {@code PropertyState} from a list of booleans. * @param name The name of the property state * @param values The values of the property state * @return The new property state of type {@link Type#BOOLEANS} */ public static PropertyState booleanProperty(String name, Iterable<Boolean> values) { return new MultiBooleanPropertyState(name, values); }
/** * Create a multi valued {@code PropertyState} from a list of references. * No validation is performed on the strings passed for {@code values}. * @param name The name of the property state * @param values The values of the property state * @return The new property state of type {@link Type#REFERENCES} */ public static PropertyState referenceProperty(String name, Iterable<String> values) { return new MultiGenericPropertyState(name, values, REFERENCES); }
@Override public boolean remove() { if (!isRoot() && exists()) { head().getMutableNodeState(); // Make sure the removed node is connected parent.head().getMutableNodeState().removeChildNode(name); updated(); return true; } else { return false; } }
@Override public void setRoot(NodeState newRoot) { checkNotMerged(); this.root = ModifiedNodeState.squeeze(newRoot); }
@Override public MutableNodeState getMutableNodeState() { // switch to connected state recursively up to the parent MutableNodeState parentState = builder.parent.head().getMutableNodeState(); MutableNodeState state = parentState.getMutableChildNode(builder.name); // triggers a head state transition at next access return new ConnectedHead(builder, state).getMutableNodeState(); }
@Override public boolean isReplaced(String name) { return head().isReplaced(name); }
@Override public Head update() { if (revision != builder.rootBuilder.baseRevision) { // the root builder's base state has been reset: transition back // to unconnected and connect again if necessary. // No need to pass base() instead of base as the subsequent // call to update will take care of updating to the latest state. builder.head = new UnconnectedHead(builder, builder.base); return builder.head.update(); } else { return this; } }
@Override public boolean isModified() { return head().isModified(); }
@Override public boolean isReplaced() { return head().isReplaced(); }
@Override public boolean isReplaced(String name) { return head().isReplaced(name); }