Class ReadOnlyBuilder

    • Constructor Detail

      • ReadOnlyBuilder

        public ReadOnlyBuilder​(@NotNull
                               @NotNull NodeState state)
    • Method Detail

      • exists

        public boolean exists()
        Description copied from interface: NodeBuilder
        Checks whether this builder represents a node that exists.
        Specified by:
        exists in interface NodeBuilder
        Returns:
        true if the node exists, false otherwise
      • isNew

        public boolean isNew()
        Description copied from interface: NodeBuilder
        Check whether this builder represents a new node, which is not present in the base state.
        Specified by:
        isNew in interface NodeBuilder
        Returns:
        true for a new node
      • isNew

        public boolean isNew​(String name)
        Description copied from interface: NodeBuilder
        Check whether the named property is new, i.e. not present in the base state.
        Specified by:
        isNew in interface NodeBuilder
        Parameters:
        name - property name
        Returns:
        true for a new property
      • isModified

        public boolean isModified()
        Description copied from interface: NodeBuilder
        Check whether this builder represents a modified node, which has either modified properties or removed or added child nodes.
        Specified by:
        isModified in interface NodeBuilder
        Returns:
        true for a modified node
      • isReplaced

        public boolean isReplaced()
        Description copied from interface: NodeBuilder
        Check whether this builder represents a node that used to exist but was then replaced with other content, for example as a result of a NodeBuilder.setChildNode(String) call.
        Specified by:
        isReplaced in interface NodeBuilder
        Returns:
        true for a replaced node
      • isReplaced

        public boolean isReplaced​(String name)
        Description copied from interface: NodeBuilder
        Check whether the named property exists in the base state but is replaced with other content, for example as a result of a NodeBuilder.setProperty(PropertyState) call.
        Specified by:
        isReplaced in interface NodeBuilder
        Parameters:
        name - property name
        Returns:
        true for a replaced property
      • getNodeState

        @NotNull
        public @NotNull NodeState getNodeState()
        Description copied from interface: NodeBuilder
        Returns an immutable node state that matches the current state of the builder.
        Specified by:
        getNodeState in interface NodeBuilder
        Returns:
        immutable node state
      • getBaseState

        @NotNull
        public @NotNull NodeState getBaseState()
        Description copied from interface: NodeBuilder
        Returns the original base state that this builder is modifying. The return value may be non-existent (i.e. its exists method returns false) if this builder represents a new node that didn't exist in the base content tree.
        Specified by:
        getBaseState in interface NodeBuilder
        Returns:
        base node state, possibly non-existent
      • getChildNodeCount

        public long getChildNodeCount​(long max)
        Description copied from interface: NodeBuilder
        Returns the current number of child nodes.

        If an implementation does know the exact value, it returns it (even if the value is higher than max). If the implementation does not know the exact value, and the child node count is higher than max, it may return Long.MAX_VALUE. The cost of the operation is at most O(max).

        Specified by:
        getChildNodeCount in interface NodeBuilder
        Parameters:
        max - the maximum value
        Returns:
        number of child nodes
      • hasChildNode

        public boolean hasChildNode​(@NotNull
                                    @NotNull String name)
        Description copied from interface: NodeBuilder
        Checks whether the named child node currently exists.
        Specified by:
        hasChildNode in interface NodeBuilder
        Parameters:
        name - child node name
        Returns:
        true if the named child node exists, false otherwise
      • setChildNode

        @NotNull
        public @NotNull NodeBuilder setChildNode​(@NotNull
                                                 @NotNull String name,
                                                 @NotNull
                                                 @NotNull NodeState nodeState)
        Description copied from interface: NodeBuilder
        Adds or replaces a subtree.
        Specified by:
        setChildNode in interface NodeBuilder
        Parameters:
        name - name of the child node containing the new subtree
        nodeState - subtree
        Returns:
        child builder
      • remove

        public boolean remove()
        Description copied from interface: NodeBuilder
        Remove this child node from its parent.
        Specified by:
        remove in interface NodeBuilder
        Returns:
        true for existing nodes, false otherwise
      • moveTo

        public boolean moveTo​(@NotNull
                              @NotNull NodeBuilder newParent,
                              @NotNull
                              @NotNull String newName)
        Description copied from interface: NodeBuilder
        Move this child to a new parent with a new name. When the move succeeded this builder has been moved to newParent as child newName. Otherwise neither this builder nor newParent are modified.

        The move succeeds if both, this builder and newParent exist, there is no child with newName at newParent and newParent is not in the subtree of this builder.

        The move fails if the this builder or newParent does not exist or if there is already a child newName at newParent.

        For all remaining cases (e.g. moving a builder into its own subtree) it is left to the implementation whether the move succeeds or fails as long as the state of the involved builder stays consistent.

        Specified by:
        moveTo in interface NodeBuilder
        Parameters:
        newParent - builder for the new parent.
        newName - name of this child at the new parent
        Returns:
        true on success, false otherwise
      • getPropertyCount

        public long getPropertyCount()
        Description copied from interface: NodeBuilder
        Returns the current number of properties.
        Specified by:
        getPropertyCount in interface NodeBuilder
        Returns:
        number of properties
      • hasProperty

        public boolean hasProperty​(String name)
        Description copied from interface: NodeBuilder
        Checks whether the named property exists. The implementation is equivalent to getProperty(name) != null, but may be optimized to avoid having to load the property value.
        Specified by:
        hasProperty in interface NodeBuilder
        Parameters:
        name - property name
        Returns:
        true if the named property exists, false otherwise
      • getProperty

        public PropertyState getProperty​(String name)
        Description copied from interface: NodeBuilder
        Returns the current state of the named property, or null if the property is not set.
        Specified by:
        getProperty in interface NodeBuilder
        Parameters:
        name - property name
        Returns:
        property state
      • getBoolean

        public boolean getBoolean​(@NotNull
                                  @NotNull String name)
        Description copied from interface: NodeBuilder
        Returns the boolean value of the named property. The implementation is equivalent to the following code, but may be optimized.
         
         PropertyState property = builder.getProperty(name);
         return property != null
             && property.getType() == Type.BOOLEAN
             && property.getValue(Type.BOOLEAN);
         
         
        Specified by:
        getBoolean in interface NodeBuilder
        Parameters:
        name - property name
        Returns:
        boolean value of the named property, or false
      • getString

        @Nullable
        public @Nullable String getString​(@NotNull
                                          @NotNull String name)
        Description copied from interface: NodeBuilder
        Returns the name value of the named property. The implementation is equivalent to the following code, but may be optimized.
         
         PropertyState property = builder.getProperty(name);
         if (property != null && property.getType() == Type.STRING) {
             return property.getValue(Type.STRING);
         } else {
             return null;
         }
         
         
        Specified by:
        getString in interface NodeBuilder
        Parameters:
        name - property name
        Returns:
        string value of the named property, or null
      • getName

        @Nullable
        public @Nullable String getName​(@NotNull
                                        @NotNull String name)
        Description copied from interface: NodeBuilder
        Returns the name value of the named property. The implementation is equivalent to the following code, but may be optimized.
         
         PropertyState property = builder.getProperty(name);
         if (property != null && property.getType() == Type.NAME) {
             return property.getValue(Type.NAME);
         } else {
             return null;
         }
         
         
        Specified by:
        getName in interface NodeBuilder
        Parameters:
        name - property name
        Returns:
        name value of the named property, or null
      • getNames

        @NotNull
        public @NotNull Iterable<String> getNames​(@NotNull
                                                  @NotNull String name)
        Description copied from interface: NodeBuilder
        Returns the name values of the named property. The implementation is equivalent to the following code, but may be optimized.
         
         PropertyState property = builder.getProperty(name);
         if (property != null && property.getType() == Type.NAMES) {
             return property.getValue(Type.NAMES);
         } else {
             return Collections.emptyList();
         }
         
         
        Specified by:
        getNames in interface NodeBuilder
        Parameters:
        name - property name
        Returns:
        name values of the named property, or an empty collection
      • removeProperty

        @NotNull
        public @NotNull NodeBuilder removeProperty​(String name)
        Description copied from interface: NodeBuilder
        Remove the named property. This method has no effect if a property of the given name does not exist.
        Specified by:
        removeProperty in interface NodeBuilder
        Parameters:
        name - name of the property
      • setProperty

        @NotNull
        public @NotNull NodeBuilder setProperty​(@NotNull
                                                @NotNull PropertyState property)
        Description copied from interface: NodeBuilder
        Set a property state
        Specified by:
        setProperty in interface NodeBuilder
        Parameters:
        property - The property state to set
        Returns:
        this builder
      • setProperty

        @NotNull
        public <T> @NotNull NodeBuilder setProperty​(String name,
                                                    @NotNull
                                                    T value)
        Description copied from interface: NodeBuilder
        Set a property state
        Specified by:
        setProperty in interface NodeBuilder
        Type Parameters:
        T - The type of this property. Must be one of String, Blob, byte[], Long, Integer, Double, Boolean, BigDecimal
        Parameters:
        name - The name of this property
        value - The value of this property
        Returns:
        this builder
      • setProperty

        @NotNull
        public <T> @NotNull NodeBuilder setProperty​(String name,
                                                    @NotNull
                                                    T value,
                                                    Type<T> type)
        Description copied from interface: NodeBuilder
        Set a property state
        Specified by:
        setProperty in interface NodeBuilder
        Type Parameters:
        T - The type of this property.
        Parameters:
        name - The name of this property
        value - The value of this property
        Returns:
        this builder
      • child

        @NotNull
        public @NotNull ReadOnlyBuilder child​(@NotNull
                                              @NotNull String name)
        Description copied from interface: NodeBuilder
        Returns a builder for constructing changes to the named child node. If the named child node does not already exist, a new empty child node is automatically created as the base state of the returned child builder. Otherwise the existing child node state is used as the base state of the returned builder.

        All updates to the returned child builder will implicitly affect also this builder, as if a setNode(name, childBuilder.getNodeState()) method call had been made after each update. Repeated calls to this method with the same name will return the same child builder instance until an explicit NodeBuilder.setChildNode(String, NodeState) or NodeBuilder.remove() call is made, at which point the link between this builder and a previously returned child builder for that child node name will get broken.

        Specified by:
        child in interface NodeBuilder
        Parameters:
        name - name of the child node
        Returns:
        child builder
      • getChildNode

        @NotNull
        public @NotNull NodeBuilder getChildNode​(@NotNull
                                                 @NotNull String name)
        Description copied from interface: NodeBuilder
        Returns a builder for constructing changes to the named child node. If the named child node does not already exist, the returned builder will refer to a non-existent node and trying to modify it will cause IllegalStateExceptions to be thrown.
        Specified by:
        getChildNode in interface NodeBuilder
        Parameters:
        name - name of the child node
        Returns:
        child builder, possibly non-existent
      • setChildNode

        @NotNull
        public @NotNull NodeBuilder setChildNode​(@NotNull
                                                 @NotNull String name)
        Description copied from interface: NodeBuilder
        Adds the named child node and returns a builder for modifying it. Possible previous content in the named subtree is removed.
        Specified by:
        setChildNode in interface NodeBuilder
        Parameters:
        name - name of the child node
        Returns:
        child builder