public class ReadOnlyBuilder extends java.lang.Object implements NodeBuilder
UnsupportedOperationException
on
all attempts to modify the given base state.Constructor and Description |
---|
ReadOnlyBuilder(NodeState state) |
Modifier and Type | Method and Description |
---|---|
ReadOnlyBuilder |
child(java.lang.String name)
Returns a builder for constructing changes to the named child node.
|
Blob |
createBlob(java.io.InputStream stream) |
boolean |
exists()
Checks whether this builder represents a node that exists.
|
NodeState |
getBaseState()
Returns the original base state that this builder is modifying.
|
boolean |
getBoolean(java.lang.String name)
Returns the boolean value of the named property.
|
NodeBuilder |
getChildNode(java.lang.String name)
Returns a builder for constructing changes to the named child node.
|
long |
getChildNodeCount(long max)
Returns the current number of child nodes.
|
java.lang.Iterable<java.lang.String> |
getChildNodeNames()
Returns the names of current child nodes.
|
java.lang.String |
getName(java.lang.String name)
Returns the name value of the named property.
|
java.lang.Iterable<java.lang.String> |
getNames(java.lang.String name)
Returns the name values of the named property.
|
NodeState |
getNodeState()
Returns an immutable node state that matches the current state of
the builder.
|
java.lang.Iterable<? extends PropertyState> |
getProperties()
Returns the current properties.
|
PropertyState |
getProperty(java.lang.String name)
Returns the current state of the named property, or
null
if the property is not set. |
long |
getPropertyCount()
Returns the current number of properties.
|
java.lang.String |
getString(java.lang.String name)
Returns the name value of the named property.
|
boolean |
hasChildNode(java.lang.String name)
Checks whether the named child node currently exists.
|
boolean |
hasProperty(java.lang.String name)
Checks whether the named property exists.
|
boolean |
isModified()
Check whether this builder represents a modified node, which has either modified properties
or removed or added child nodes.
|
boolean |
isNew()
Check whether this builder represents a new node, which is not present in the base state.
|
boolean |
isNew(java.lang.String name)
Check whether the named property is new, i.e.
|
boolean |
isReplaced()
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. |
boolean |
isReplaced(java.lang.String name)
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. |
boolean |
moveTo(NodeBuilder newParent,
java.lang.String newName)
Move this child to a new parent with a new name.
|
boolean |
remove()
Remove this child node from its parent.
|
NodeBuilder |
removeProperty(java.lang.String name)
Remove the named property.
|
NodeBuilder |
setChildNode(java.lang.String name)
Adds the named child node and returns a builder for modifying it.
|
NodeBuilder |
setChildNode(java.lang.String name,
NodeState nodeState)
Adds or replaces a subtree.
|
NodeBuilder |
setProperty(PropertyState property)
Set a property state
|
<T> NodeBuilder |
setProperty(java.lang.String name,
T value)
Set a property state
|
<T> NodeBuilder |
setProperty(java.lang.String name,
T value,
Type<T> type)
Set a property state
|
public ReadOnlyBuilder(NodeState state)
public boolean exists()
NodeBuilder
exists
in interface NodeBuilder
true
if the node exists, false
otherwisepublic boolean isNew()
NodeBuilder
isNew
in interface NodeBuilder
true
for a new nodepublic boolean isNew(java.lang.String name)
NodeBuilder
isNew
in interface NodeBuilder
name
- property nametrue
for a new propertypublic boolean isModified()
NodeBuilder
isModified
in interface NodeBuilder
true
for a modified nodepublic boolean isReplaced()
NodeBuilder
NodeBuilder.setChildNode(String)
call.isReplaced
in interface NodeBuilder
true
for a replaced nodepublic boolean isReplaced(java.lang.String name)
NodeBuilder
NodeBuilder.setProperty(PropertyState)
call.isReplaced
in interface NodeBuilder
name
- property nametrue
for a replaced propertypublic NodeState getNodeState()
NodeBuilder
getNodeState
in interface NodeBuilder
public NodeState getBaseState()
NodeBuilder
exists
method
returns false
) if this builder represents a new node that
didn't exist in the base content tree.getBaseState
in interface NodeBuilder
public long getChildNodeCount(long max)
NodeBuilder
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).
getChildNodeCount
in interface NodeBuilder
max
- the maximum valuepublic boolean hasChildNode(java.lang.String name)
NodeBuilder
hasChildNode
in interface NodeBuilder
name
- child node nametrue
if the named child node exists,
false
otherwisepublic java.lang.Iterable<java.lang.String> getChildNodeNames()
NodeBuilder
getChildNodeNames
in interface NodeBuilder
public NodeBuilder setChildNode(java.lang.String name, NodeState nodeState)
NodeBuilder
setChildNode
in interface NodeBuilder
name
- name of the child node containing the new subtreenodeState
- subtreepublic boolean remove()
NodeBuilder
remove
in interface NodeBuilder
true
for existing nodes, false
otherwisepublic boolean moveTo(NodeBuilder newParent, java.lang.String newName)
NodeBuilder
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.
moveTo
in interface NodeBuilder
newParent
- builder for the new parent.newName
- name of this child at the new parenttrue
on success, false
otherwisepublic long getPropertyCount()
NodeBuilder
getPropertyCount
in interface NodeBuilder
public java.lang.Iterable<? extends PropertyState> getProperties()
NodeBuilder
getProperties
in interface NodeBuilder
public boolean hasProperty(java.lang.String name)
NodeBuilder
getProperty(name) != null
, but may be optimized
to avoid having to load the property value.hasProperty
in interface NodeBuilder
name
- property nametrue
if the named property exists,
false
otherwisepublic PropertyState getProperty(java.lang.String name)
NodeBuilder
null
if the property is not set.getProperty
in interface NodeBuilder
name
- property namepublic boolean getBoolean(java.lang.String name)
NodeBuilder
PropertyState property = builder.getProperty(name);
return property != null
&& property.getType() == Type.BOOLEAN
&& property.getValue(Type.BOOLEAN);
getBoolean
in interface NodeBuilder
name
- property namefalse
public java.lang.String getString(java.lang.String name)
NodeBuilder
PropertyState property = builder.getProperty(name);
if (property != null && property.getType() == Type.STRING) {
return property.getValue(Type.STRING);
} else {
return null;
}
getString
in interface NodeBuilder
name
- property namenull
public java.lang.String getName(java.lang.String name)
NodeBuilder
PropertyState property = builder.getProperty(name);
if (property != null && property.getType() == Type.NAME) {
return property.getValue(Type.NAME);
} else {
return null;
}
getName
in interface NodeBuilder
name
- property namenull
public java.lang.Iterable<java.lang.String> getNames(java.lang.String name)
NodeBuilder
PropertyState property = builder.getProperty(name);
if (property != null && property.getType() == Type.NAMES) {
return property.getValue(Type.NAMES);
} else {
return Collections.emptyList();
}
getNames
in interface NodeBuilder
name
- property namepublic NodeBuilder removeProperty(java.lang.String name)
NodeBuilder
name
does not exist.removeProperty
in interface NodeBuilder
name
- name of the propertypublic NodeBuilder setProperty(PropertyState property)
NodeBuilder
setProperty
in interface NodeBuilder
property
- The property state to setpublic <T> NodeBuilder setProperty(java.lang.String name, T value)
NodeBuilder
setProperty
in interface NodeBuilder
T
- The type of this property. Must be one of String, Blob, byte[], Long, Integer, Double, Boolean, BigDecimal
name
- The name of this propertyvalue
- The value of this propertypublic <T> NodeBuilder setProperty(java.lang.String name, T value, Type<T> type)
NodeBuilder
setProperty
in interface NodeBuilder
T
- The type of this property.name
- The name of this propertyvalue
- The value of this propertypublic ReadOnlyBuilder child(java.lang.String name)
NodeBuilder
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.
child
in interface NodeBuilder
name
- name of the child nodepublic NodeBuilder getChildNode(java.lang.String name)
NodeBuilder
IllegalStateException
s to be thrown.getChildNode
in interface NodeBuilder
name
- name of the child nodepublic NodeBuilder setChildNode(java.lang.String name)
NodeBuilder
setChildNode
in interface NodeBuilder
name
- name of the child nodepublic Blob createBlob(java.io.InputStream stream) throws java.io.IOException
createBlob
in interface NodeBuilder
java.io.IOException
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"