/** * Remove the child node with the given {@code name}. * @param name name of the child node to remove * @return {@code true} if a child node {@code name} existed, {@code false} otherwise. */ boolean removeChildNode(String name) { assert base != null; MutableNodeState child = nodes.get(name); if (child != null) { boolean existed = child.exists(); child.reset(MISSING_NODE); return existed; } else { nodes.put(name, new MutableNodeState(MISSING_NODE)); return base.hasChildNode(name); } }
@Override public boolean isModified() { return state.isModified(builder.base()); }
@Override public boolean isReplaced(String name) { return state.isReplaced(builder.base(), name); }
/** * Equivalent to * <pre> * MutableNodeState child = getChildNode(name, true); * child.reset(state); * return child; * </pre> * * @throws IllegalArgumentException if the given name string is empty * or contains the forward slash character */ @NotNull MutableNodeState setChildNode(String name, NodeState state) throws IllegalArgumentException { assert base != null; MutableNodeState child = nodes.get(name); if (child == null) { checkValidName(name); child = new MutableNodeState(state); if (base.hasChildNode(name)) { child.replaced = true; } nodes.put(name, child); } else { child.replaced = true; child.reset(state); } return child; }
properties.clear(); for (Entry<String, MutableNodeState> entry : nodes.entrySet()) { entry.getValue().reset(base.getChildNode(entry.getKey())); String name = entry.getKey(); if (!nodes.containsKey(name)) { nodes.put(name, new MutableNodeState(entry.getValue()));
public final long setState(NodeState state) { this.state = new MutableNodeState(state); // To be able to make a distinction between set() and reset(), we revision++; // increment the revision twice and return revision++; // return the intermediate value }
/** * Set the value of a property */ void setProperty(PropertyState property) { String name = property.getName(); checkValidName(name); properties.put(name, property); }
@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; } }
@NotNull @Override public NodeBuilder removeProperty(String name) { checkState(exists(), "This builder does not exist: " + name); if (head().getMutableNodeState().removeProperty(checkNotNull(name))) { updated(); } return this; }
@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(); }
@NotNull @Override public NodeBuilder setChildNode(@NotNull String name, @NotNull NodeState state) { checkState(exists(), "This builder does not exist: " + this.name); head().getMutableNodeState().setChildNode(name, checkNotNull(state)); MemoryNodeBuilder builder = createChildBuilder(name); updated(); return builder; }
/** * Equivalent to * <pre> * MutableNodeState child = getChildNode(name, true); * child.reset(state); * return child; * </pre> * * @throws IllegalArgumentException if the given name string is empty * or contains the forward slash character */ @Nonnull MutableNodeState setChildNode(String name, NodeState state) throws IllegalArgumentException { assert base != null; MutableNodeState child = nodes.get(name); if (child == null) { checkValidName(name); child = new MutableNodeState(state); if (base.hasChildNode(name)) { child.replaced = true; } nodes.put(name, child); } else { child.replaced = true; child.reset(state); } return child; }
properties.clear(); for (Entry<String, MutableNodeState> entry : nodes.entrySet()) { entry.getValue().reset(base.getChildNode(entry.getKey())); String name = entry.getKey(); if (!nodes.containsKey(name)) { nodes.put(name, new MutableNodeState(entry.getValue()));
public final long setState(NodeState state) { this.state = new MutableNodeState(state); // To be able to make a distinction between set() and reset(), we revision++; // increment the revision twice and return revision++; // return the intermediate value }
/** * Set the value of a property */ void setProperty(PropertyState property) { String name = property.getName(); checkValidName(name); properties.put(name, property); }
@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; } }
@Nonnull @Override public NodeBuilder removeProperty(String name) { checkState(exists(), "This builder does not exist: " + name); if (head().getMutableNodeState().removeProperty(checkNotNull(name))) { updated(); } return this; }
@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(); }
@Nonnull @Override public NodeBuilder setChildNode(@Nonnull String name, @Nonnull NodeState state) { checkState(exists(), "This builder does not exist: " + this.name); head().getMutableNodeState().setChildNode(name, checkNotNull(state)); MemoryNodeBuilder builder = createChildBuilder(name); updated(); return builder; }