Class ImmutableTree
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.tree.impl.AbstractTree
-
- org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree
-
- All Implemented Interfaces:
Tree,ReadOnly,TreeTypeAware
public final class ImmutableTree extends AbstractTree implements TreeTypeAware, ReadOnly
Immutable implementation of theTreeinterface in order to provide the much feature rich API functionality for a givenNodeState.Tree hierarchy
Due to the nature of thisTreeimplementation creating a proper hierarchical view of the tree structure is the responsibility of the caller. It is recommended to start with the state of theroot nodeand build up the hierarchy by callingImmutableTree(ImmutableTree, String, org.apache.jackrabbit.oak.spi.state.NodeState)for every subsequent child state. Note, that this implementation will not perform any kind of validation of the passed state and methods likeisRoot(),getName()orgetPath()will just make use of the hierarchy that has been create by that sequence. In order to create a disconnected individual tree in cases where the hierarchy information is not (yet) need or known it is suggested to useImmutableTree(ImmutableTree.ParentProvider, String, org.apache.jackrabbit.oak.spi.state.NodeState)an specify an appropriateParentProviderimplementation.ParentProvider
Apart from create the tree hierarchy in traversal mode this tree implementation allows to instantiate disconnected trees that depending on the use may never or on demand retrieve hierarchy information. The following default implementations of this internal interface are present:ImmutableTree.DefaultParentProvider: used with the default usage where the parent tree is passed to the constructorImmutableTree.ParentProvider.ROOT_PROVIDER: the default parent provider for the root tree. All children will getImmutableTree.DefaultParentProviderImmutableTree.ParentProvider.UNSUPPORTED: throwsUnsupportedOperationExceptionupon hierarchy related methods likeAbstractTree.getParent(),getPath()
Filtering 'hidden' items
ThisTreeimplementation reflects the item hierarchy as exposed by the underlyingNodeState. In contrast to the mutable implementations it does not filter out 'hidden' items as identified byorg.apache.jackrabbit.oak.spi.state.NodeStateUtils#isHidden(String).Equality and hash code
In contrast toAbstractMutableTreetheImmutableTreeimplementsObject.equals(Object)andObject.hashCode(): TwoImmutableTrees are consider equal if their name and the underlyingNodeStates are equal. Note however, that according to the contract defined inNodeStatethese objects are not expected to be used as hash keys.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classImmutableTree.DefaultParentProviderstatic interfaceImmutableTree.ParentProvider-
Nested classes/interfaces inherited from interface org.apache.jackrabbit.oak.api.Tree
Tree.Status
-
-
Field Summary
-
Fields inherited from interface org.apache.jackrabbit.oak.api.Tree
EMPTY_ARRAY
-
-
Constructor Summary
Constructors Constructor Description ImmutableTree(@NotNull ImmutableTree.ParentProvider parentProvider, @NotNull String name, @NotNull NodeState state)ImmutableTree(@NotNull ImmutableTree parent, @NotNull String name, @NotNull NodeState state)ImmutableTree(@NotNull NodeState rootState)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull TreeaddChild(@NotNull String name)Add a child with the givenname.protected @NotNull ImmutableTreecreateChild(@NotNull String name)Factory method for creating child treesbooleanequals(Object o)@NotNull ImmutableTreegetChild(@NotNull String name)Get a possibly non existing child of thisTree.protected @NotNull String[]getInternalNodeNames()@NotNull StringgetName()protected @NotNull NodeBuildergetNodeBuilder()protected @Nullable AbstractTreegetParentOrNull()@NotNull StringgetPath()@Nullable TreeTypegetType()inthashCode()protected booleanisHidden(@NotNull String name)Determine whether an item should be hidden.booleanisRoot()booleanorderBefore(@Nullable String name)Orders thisTreebefore the sibling tree with the givenname.booleanremove()Remove this tree instance.voidremoveProperty(@NotNull String name)Remove the property with the given name.voidsetOrderableChildren(boolean enable)Changes the nature of this tree such that the order of the children is kept stable.<T> voidsetProperty(@NotNull String name, T value)Set a property state<T> voidsetProperty(@NotNull String name, T value, @NotNull Type<T> type)Set a property statevoidsetProperty(@NotNull PropertyState property)Set a property statevoidsetType(@NotNull TreeType type)-
Methods inherited from class org.apache.jackrabbit.oak.plugins.tree.impl.AbstractTree
buildPath, exists, getChildNames, getChildren, getChildrenCount, getNodeState, getParent, getProperties, getProperty, getPropertyCount, getPropertyStatus, getStatus, hasChild, hasOrderableChildren, hasProperty, toString
-
-
-
-
Constructor Detail
-
ImmutableTree
public ImmutableTree(@NotNull @NotNull NodeState rootState)
-
ImmutableTree
public ImmutableTree(@NotNull @NotNull ImmutableTree parent, @NotNull @NotNull String name, @NotNull @NotNull NodeState state)
-
ImmutableTree
public ImmutableTree(@NotNull @NotNull ImmutableTree.ParentProvider parentProvider, @NotNull @NotNull String name, @NotNull @NotNull NodeState state)
-
-
Method Detail
-
getType
@Nullable public @Nullable TreeType getType()
- Specified by:
getTypein interfaceTreeTypeAware
-
setType
public void setType(@NotNull @NotNull TreeType type)- Specified by:
setTypein interfaceTreeTypeAware
-
createChild
@NotNull protected @NotNull ImmutableTree createChild(@NotNull @NotNull String name)
Description copied from class:AbstractTreeFactory method for creating child trees- Specified by:
createChildin classAbstractTree- Parameters:
name- name of the child tree- Returns:
- child tree of this tree with the given
name
-
isRoot
public boolean isRoot()
- Specified by:
isRootin interfaceTree- Overrides:
isRootin classAbstractTree- Returns:
trueiff this is the root
-
getParentOrNull
@Nullable protected @Nullable AbstractTree getParentOrNull()
- Specified by:
getParentOrNullin classAbstractTree- Returns:
- the parent of this tree or
nullfor the root
-
getNodeBuilder
@NotNull protected @NotNull NodeBuilder getNodeBuilder()
- Specified by:
getNodeBuilderin classAbstractTree- Returns:
- The
NodeBuilderfor the underlying node state
-
isHidden
protected boolean isHidden(@NotNull @NotNull String name)Description copied from class:AbstractTreeDetermine whether an item should be hidden. I.e. not exposed through this tree.- Overrides:
isHiddenin classAbstractTree- Parameters:
name- name of an item- Returns:
trueif the item is hidden,falseotherwise.
-
getInternalNodeNames
@NotNull protected @NotNull String[] getInternalNodeNames()
- Overrides:
getInternalNodeNamesin classAbstractTree
-
getName
@NotNull public @NotNull String getName()
-
getPath
@NotNull public @NotNull String getPath()
- Specified by:
getPathin interfaceTree- Overrides:
getPathin classAbstractTree- Returns:
- the absolute path of this
Treeinstance from itsRoot.
-
getChild
@NotNull public @NotNull ImmutableTree getChild(@NotNull @NotNull String name) throws IllegalArgumentException
Description copied from interface:TreeGet a possibly non existing child of thisTree.- Specified by:
getChildin interfaceTree- Overrides:
getChildin classAbstractTree- Parameters:
name- The name of the child to retrieve.- Returns:
- The child with the given
name. - Throws:
IllegalArgumentException- if the given name is invalid
-
remove
public boolean remove()
Description copied from interface:TreeRemove this tree instance. This operation never succeeds for the root tree.
-
addChild
@NotNull public @NotNull Tree addChild(@NotNull @NotNull String name)
Description copied from interface:TreeAdd a child with the givenname. Does nothing if such a child already exists.
-
setOrderableChildren
public void setOrderableChildren(boolean enable)
Description copied from interface:TreeChanges the nature of this tree such that the order of the children is kept stable. The expected behavior is as follows:- Calling
setOrderableChildren(true)on a tree the first time will stabilize the order of existing children. Any subsequentTree.addChild(String)call is guaranteed to insert the new tree and the end of the child list. - Calling
setOrderableChildren(true)on a tree that already has its children ordered has no effect. - Calling
setOrderableChildren(false)on a tree that doesn't have ordered children has not effect - Calling
setOrderableChildren(false)on a tree with ordered children will remove the necessity to keep the child list stable. The order of children uponTree.getChildren()is subsequently undefined.
Calling
Tree.orderBefore(String)on a tree, implicitly enables orderable children on the parent tree.- Specified by:
setOrderableChildrenin interfaceTree- Parameters:
enable- Enable (or disable) orderable children for this tree.
- Calling
-
orderBefore
public boolean orderBefore(@Nullable @Nullable String name)Description copied from interface:TreeOrders thisTreebefore the sibling tree with the givenname. Calling this method for the first time on thisTreeor any of its siblings will persist the current order of siblings and maintain it from this point on.- Specified by:
orderBeforein interfaceTree- Parameters:
name- the name of the sibling node where this tree is ordered before. This tree will become the last sibling ifnameisnull.- Returns:
falseif there is no sibling with the givennameor no reordering was performed;trueotherwise.
-
setProperty
public void setProperty(@NotNull @NotNull PropertyState property)Description copied from interface:TreeSet a property state- Specified by:
setPropertyin interfaceTree- Parameters:
property- The property state to set
-
setProperty
public <T> void setProperty(@NotNull @NotNull String name, @NotNull T value)Description copied from interface:TreeSet a property state- Specified by:
setPropertyin interfaceTree- Type Parameters:
T- The type of this property. Must be one ofString, Blob, byte[], Long, Integer, Double, Boolean, BigDecimal- Parameters:
name- The name of this property. A valid name does not start with a colon, is not empty and does not contain a forward slash.value- The value of this property
-
setProperty
public <T> void setProperty(@NotNull @NotNull String name, @NotNull T value, @NotNull @NotNull Type<T> type)Description copied from interface:TreeSet a property state- Specified by:
setPropertyin interfaceTree- Type Parameters:
T- The type of this property.- Parameters:
name- The name of this property. A valid name does not start with a colon, is not empty and does not contain a forward slash.value- The value of this propertytype- The type of this property.
-
removeProperty
public void removeProperty(@NotNull @NotNull String name)Description copied from interface:TreeRemove the property with the given name. This method has no effect if a property of the givennamedoes not exist.- Specified by:
removePropertyin interfaceTree- Parameters:
name- The name of the property
-
-