public class ArrayForest extends Object implements Forest
Forest
class.
ArrayForest
is a data structure that implements Forest
.
Any modifications to the ArrayForest
are only applied to that instance in memory.
When a specific position in the forest needs to be defined for mutating operations such as move or insert, under-after
coordinates are used. (If operation addresses a specific row, the row ID is used instead.)
Under-after
coordinates contain under
value, which identifies the parent row of the
specified position (the depth and the subtree). If under
is 0
, the position is at the
top (root row).
The other parameter, after
coordinate, defines the location of the inserted row amongst siblings -
the rows at the same depth under the same parent. If after
is 0
, it means that the position
should be the first under the specified parent.
Note: moving a row after itself, i.e. when the under
coordinate is equal to the row's parent row
and the after
coordinate is equal to the row itself, is allowed and does not change the position of the row.
Methods from this class don't not modify the forest stored in the database for a structure.
To make modifications of the structure's forest, apply forest changes with ForestSource.apply(ForestAction)
.
This class in not thread-safe.
ForestSource
Constructor and Description |
---|
ArrayForest() |
ArrayForest(Forest copyFrom) |
ArrayForest(long row)
Creates a singular tree.
|
ArrayForest(LongList rows,
IntList depths) |
ArrayForest(WritableLongList rows,
WritableIntList depths,
boolean reuseLists)
Constructs a forest based on the given rows and depths.
|
Modifier and Type | Method and Description |
---|---|
void |
addForest(long under,
long after,
Forest forest) |
void |
addForestMutuallyExclusive(Forest forest,
long under,
long after)
Adds a forest to this forest.
|
boolean |
addRow(long row,
long under,
long after)
Adds a single row at the specified position.
|
void |
append(Forest forest) |
void |
clear() |
ArrayForest |
clone() |
boolean |
containsRow(long row)
Can be used to check if the forest contains a specific row.
|
ArrayForest |
copy()
Creates an exact copy of this forest.
|
ArrayForest |
copySubforest(long row) |
ArrayForest |
copySubforestAtIndex(int k) |
static Forest |
ensureImmutability(Forest forest) |
boolean |
equals(Object o) |
ArrayForest |
filter(La<Long,?> filter)
Filters this forest by hiding rows that do not pass the
filter condition. |
ArrayForest |
filterHardest(La<Long,?> filter)
Filters this forest by excluding rows that do not pass the
filter condition. |
ArrayForest |
filterSoft(La<Long,?> filter)
Filters this forest by excluding rows that do not pass the
filter condition. |
<T,C> C |
foldUpwards(ForestParentChildrenClosure<T,C> closure)
This is a more generic version of
Forest.visitParentChildrenUpwards(com.almworks.jira.structure.api.forest.raw.ForestParentChildrenVisitor) that allows you to effectively
process the forest bottom-up, probably saving on memory allocation and search speed. |
LongArray |
getChildren(long row)
Creates an array with all direct sub-rows of the specified row.
|
LongArray |
getChildrenAtIndex(int index)
Creates an array with all direct sub-rows of the row at the specified index.
|
IntIterator |
getChildrenIndicesIterator(int index)
Returns an iterator over indices of all direct sub-rows of the row at the specified index.
|
int |
getDepth(int index)
Gets the depth of the row at the specified position in the forest.
|
IntList |
getDepths()
Returns a non-modifiable list of depths, in the order the rows appear in the forest.
|
String |
getDiagnostics() |
static String |
getDiagnostics(Forest f)
Checks whether RowTree invariants hold.
|
long |
getLastChild(long parent)
Gets the last direct sub-row of the specified parent row.
|
long |
getLastChildByIndex(int parentIndex)
Gets the last direct sub-row of the specified parent row.
|
long |
getNextSibling(long row)
Gets the row that immediately follows the specified row in the
list of children of the specified row's parent.
|
long |
getNextSiblingForIndex(int index)
Gets the row that immediately follows the one with the given index in the
list of children of its parent.
|
int |
getNextSiblingIndex(int index)
Gets the index of the row that immediately follows the row at the given index in the
list of children of its parent.
|
long |
getParent(long row)
Gets the parent row of the specified row.
|
int |
getParentIndex(int index)
Searches the forest for the index of a "parent row".
|
LongArray |
getParentPathForIndex(int index)
Returns the path to the specified row without the row itself.
|
LongArray |
getPath(long row)
Returns the path to the specified row - a sequence of rows that starts with a
root row, ends with the specified row, and where
element[i] is
the parent row of element[i+1] . |
LongArray |
getPathForIndex(int idx)
Similar to
Forest.getPath(long) , returns the path to the row specified by index. |
int |
getPathIndexAtDepth(int index,
int depth)
Given row at the specified index, traverses its "path" upwards - that is, looks for all
parent rows up to the topmost root parent, and returns an index of the parent that has the
specified depth.
|
long |
getPrecedingSibling(long row)
Gets the row that immediately precedes the specified row in the
list of children of the specified row's parent.
|
long |
getPrecedingSiblingForIndex(int index)
Gets the row that immediately precedes the one with the given index in the
list of children of its parent.
|
int |
getPrecedingSiblingIndex(int index)
Gets the index of the row that immediately precedes the row at the given index in the
list of children of its parent.
|
LongArray |
getPrecedingSiblings(long row)
Returns the array of all rows that come before the given row in the list of children of its parent,
in the same order as they appear in the forest.
|
LongArray |
getPrecedingSiblingsForIndex(int index)
Returns the array of all rows that come before the given row in the list of children of its parent,
in the same order as they appear in the forest.
|
LongArray |
getRoots()
Returns an array of all root rows in the forest (those that have depth of
0 ). |
long |
getRow(int index)
Gets the ID of the row at the specified position in the forest.
|
LongList |
getRows()
Returns a non-modifiable list of rows, in the order they appear in the forest.
|
int |
getSubtreeEnd(int index)
The method looks for the end of a subtree rooted at the specified index.
|
int |
hashCode() |
int |
indexOf(long row)
Searches for the position of a specific row in the forest.
|
boolean |
isEmpty()
Used to check if the forest does not contain any rows.
|
boolean |
isImmutable()
Returns true if the forest is immutable.
|
LongIntIterator |
iterator() |
ArrayForest |
makeImmutable()
Makes this instance non-modifiable
|
void |
mergeForest(Forest forest,
long under,
long after)
Convenience method to call
mergeForest(Forest, long, long, ForestChangeEventHandler) without event handler. |
void |
mergeForest(Forest forest,
long under,
long after,
ForestChangeEventHandler eventHandler)
Merges another forest into this forest.
|
boolean |
moveSubtree(long row,
long under,
long after)
Convenience method to call
moveSubtree(long, long, long, ForestChangeEventHandler) without event handler. |
boolean |
moveSubtree(long row,
long under,
long after,
ForestChangeEventHandler eventHandler)
Moves sub-tree rooted at the specified row to a position specified by
(under, after) coordinates. |
int |
moveSubtreeAtIndex(int index,
long under,
long after,
ForestChangeEventHandler eventHandler)
Moves sub-tree rooted at the specified index to a position specified by
(under, after) coordinates. |
Forest |
removeSubtree(long row)
Convenience method to call
removeSubtree(long, ForestChangeEventHandler) without event handler. |
Forest |
removeSubtree(long row,
ForestChangeEventHandler eventHandler)
Removes a subtree from this forest.
|
Forest |
removeSubtreeAtIndex(int index,
ForestChangeEventHandler eventHandler)
Removes a sub-tree with rooted at the specified index from this forest.
|
void |
reorder(long parent,
LongList children) |
void |
replaceSubtrees(long rowId,
Forest forest)
Removes everything from under given row and inserts forest as sub-forest of rowId.
|
void |
replaceSubtreesMutuallyExclusive(long rowId,
Forest forest) |
void |
replaceSubtreesMutuallyExclusiveAtIndex(int index,
Forest forest)
Removes everything from under row with given index and inserts forest as sub-forest of the same row
|
void |
scanDownwards(ForestScanner scanner)
Iterates through each row from top to the bottom.
|
Forest |
set(LongList rows,
IntList depths)
Replaces the contents of this forest with the values passed in the parameters.
|
Forest |
set(WritableLongList rows,
WritableIntList depths,
boolean reuseLists)
Replaces the contents of this forest with the values passed in the parameters.
|
int |
size()
Gets the number of rows in this tree.
|
Forest |
subtree(long row)
Creates a forest that contains the specified row and all its sub-rows from this forest.
|
Forest |
subtreeAtIndex(int index)
Creates a forest that contains the specified row and all its sub-rows from this forest.
|
String |
toFullString()
Utility method for debugging - returns full string representation of the forest, that contains all the information,
unlike
toString() method, which may be truncated to some character number limit. |
String |
toString() |
void |
visitParentChildrenUpwards(ForestParentChildrenVisitor visitor)
This method is used to efficiently traverse all pairs (parent, children) from the end of the forest upwards.
|
forEach, spliterator
public ArrayForest()
public ArrayForest(long row)
row
- row ID of the rootpublic ArrayForest(WritableLongList rows, WritableIntList depths, boolean reuseLists)
rows
- list of row IDsdepths
- list of corresponding depthsreuseLists
- if true, passed instances of List can be used by this RowTree (otherwise a copy is made)public ArrayForest(LongList rows, IntList depths)
public ArrayForest(Forest copyFrom)
public final Forest set(WritableLongList rows, WritableIntList depths, boolean reuseLists)
Replaces the contents of this forest with the values passed in the parameters.
The passed lists must satisfy the invariant conditions listed in Forest
, otherwise the results
are undefined.
rows
- new row listdepths
- new depths listreuseLists
- if true, the passed arrays may be used by the forest without copying the data. In that case, the calling code must not use these lists after this method call.public Forest set(LongList rows, IntList depths)
Replaces the contents of this forest with the values passed in the parameters.
The passed lists must satisfy the invariant conditions listed in Forest
, otherwise the results
are undefined.
rows
- new row listdepths
- new depths listpublic String getDiagnostics()
public static String getDiagnostics(Forest f)
public boolean containsRow(long row)
Forest
Can be used to check if the forest contains a specific row.
Execution of this method may take O(size())
time.
containsRow
in interface Forest
row
- the row ID to search forpublic void mergeForest(Forest forest, long under, long after) throws StructureException
mergeForest(Forest, long, long, ForestChangeEventHandler)
without event handler.forest
- the merged forestunder
- the parent of the merged forest, or 0 if the forest rows should be placed at the root levelafter
- the preceding sibling of the merged forest, or 0 to place forest as the first childStructureException
- if the operation cannot be completed because it requires an invalid movepublic void addForest(long under, long after, Forest forest)
public void clear()
public void mergeForest(Forest forest, long under, long after, @Nullable ForestChangeEventHandler eventHandler) throws StructureException
Merges another forest into this forest. After the method has executed, this forest will contain all rows
from forest
in the same topology under the specified positions: the root rows from forest
will be positioned as defined by under-after
coordinates (see Forest
for the explanation
of under-after coordinates), and non-root rows from forest
will have the same parent rows as
in forest
.
This forest and the merged forest
may have the same rows. In that case the rows are moved
within this forest and placed at the position required by this operation.
When StructureException
is thrown from this method, the state of this forest is unknown - due to the
fact that merge splits into several atomic updates and the exception may be thrown after some of the updates
have taken place.
forest
- the merged forestunder
- the parent of the merged forest, or 0 if the forest rows should be placed at the root levelafter
- the preceding sibling of the merged forest, or 0 to place forest as the first childeventHandler
- an optional event handler to get notifications about changes being applied - may be called several times
because merge could be split into series of moves and additions.StructureException
- if the operation cannot be completed because it requires an invalid movepublic boolean addRow(long row, long under, long after) throws StructureException
Adds a single row at the specified position.
If the row is already in the structure, this method moves it to the specified position.
row
- row to be addedunder
- the parent of the row, or 0 if the row should be placed at the forest root levelafter
- the preceding sibling of the row, or 0 to place row as the first childStructureException
- if under
is not in the forest or if a similar problem happenspublic void addForestMutuallyExclusive(Forest forest, long under, long after) throws StructureException
addForest(long, long, Forest)
and
mergeForest(Forest, long, long)
when the added forest is guaranteed to be mutually exclusive
with this forest, i.e. when it contains only row IDs not present in this forest.
If this is not the case, the result of the operation is undefined.forest
- the forest to addunder
- the parent of the added forest, or 0 if the forest rows should be placed at the root levelafter
- the preceding sibling of the added forest, or 0 to place forest as the first childStructureException
- if under
is not in the forest or if a similar problem happens@NotNull public Forest removeSubtree(long row, ForestChangeEventHandler eventHandler)
row
- row ID of the root of the subtree to be removed@NotNull public Forest removeSubtreeAtIndex(int index, @Nullable ForestChangeEventHandler eventHandler)
Removes a sub-tree with rooted at the specified index from this forest.
index
- the index of the root of the sub-tree to be removedeventHandler
- optional handler of the forest eventsindex
is negative@NotNull public Forest subtree(long row)
Forest
@NotNull public Forest subtreeAtIndex(int index)
Forest
subtreeAtIndex
in interface Forest
index
- index of the root of the sub-treeindex
,
or an empty forest if the index is negativepublic int getSubtreeEnd(int index)
Forest
The method looks for the end of a subtree rooted at the specified index.
A subtree rooted at index k
is a sub-sequence in the forest starting at position k
and containing all following elements that have depth d > depth[k]
.
The result of this method is the next index after the last element of this subsequence.
More specifically, the result is the first element after [k]
that has depth d <= depth[k]
.
When the subtree ends with the whole forest, the return value is equal to Forest.size()
.
If index
is a negative number, the returned value is 0
. If index
is greater or equal than
size()
, the returned value is equal to size()
.
getSubtreeEnd
in interface Forest
index
- the index of the root row of the subtree@Nullable public ArrayForest copySubforest(long row)
copySubforest
in interface Forest
@Nullable public ArrayForest copySubforestAtIndex(int k)
copySubforestAtIndex
in interface Forest
@NotNull public LongList getRows()
Forest
Forest.size()
.@NotNull public IntList getDepths()
Forest
Forest.size()
and the i
-th element
of this list corresponds to the row ID at the i
-th position in the list returned
by Forest.getRows()
.public long getRow(int index)
Forest
public int getDepth(int index)
Forest
public long getParent(long row)
Forest
public int getParentIndex(int index)
Forest
Searches the forest for the index of a "parent row". If the row at the specified index is a root row (has depth of 0
),
returns -1.
If index
is negative, returns -1.
getParentIndex
in interface Forest
index
- index of a child rowindex
is a root row, or index k
of the parent row, such as
that k = MAX(k in [0, index-1] that has depth[k] == depth[index] - 1)
public int getPathIndexAtDepth(int index, int depth)
Forest
Given row at the specified index, traverses its "path" upwards - that is, looks for all parent rows up to the topmost root parent, and returns an index of the parent that has the specified depth.
If the required depth is equal to the depth of the row at the specified index, returns index
.
If index
is a negative value, returns -1. If row at the specified index has less depth than the required value, returns -1
.
getPathIndexAtDepth
in interface Forest
index
- index of the rowdepth
- required depth of the [grand-] parent row-1
if not foundpublic int getPrecedingSiblingIndex(int index)
Forest
getPrecedingSiblingIndex
in interface Forest
index
- row indexindex
is not found in the forest or is the first root or the first child of its parent rowpublic long getPrecedingSiblingForIndex(int index)
Forest
getPrecedingSiblingForIndex
in interface Forest
index
- row indexpublic long getPrecedingSibling(long row)
Forest
getPrecedingSibling
in interface Forest
row
- a rowrow
is not found in the forest or is the first root or the first child of its parent row@NotNull public LongArray getPrecedingSiblings(long row)
Forest
getPrecedingSiblings
in interface Forest
row
- a rowrow
has none or is not in the forest@NotNull public LongArray getPrecedingSiblingsForIndex(int index)
Forest
getPrecedingSiblingsForIndex
in interface Forest
index
- row indexindex
has none or index
is negativepublic int getNextSiblingIndex(int index)
Forest
getNextSiblingIndex
in interface Forest
index
- row indexindex
is not found in the forest or is the last root or the last child of its parent rowpublic long getNextSiblingForIndex(int index)
Forest
getNextSiblingForIndex
in interface Forest
index
- row indexpublic long getNextSibling(long row)
Forest
getNextSibling
in interface Forest
row
- a rowrow
is not found in the forest or is the last root or the last child of its parent row@NotNull public LongArray getChildren(long row)
Forest
Creates an array with all direct sub-rows of the specified row.
The returned array is writable and owned by the calling code.
If row is not in the forest or does not have children, empty array is returned.
getChildren
in interface Forest
row
- the parent row, you can pass 0 to get the roots.@NotNull public LongArray getChildrenAtIndex(int index)
Forest
Creates an array with all direct sub-rows of the row at the specified index.
The returned array is writable and owned by the calling code.
If the specified row does not have children, or if the index is negative, empty array is returned.
getChildrenAtIndex
in interface Forest
index
- the index of the parent row@NotNull public IntIterator getChildrenIndicesIterator(int index)
Forest
Returns an iterator over indices of all direct sub-rows of the row at the specified index.
This method is a lazy variant of Forest.getChildrenAtIndex(int)
: the underlying data structure is scanned
as you advance the returned iterator. This allows to save on an extra scan, and on copying to the result array.
Another difference is that this method returns indices, not the rows themselves.
getChildrenIndicesIterator
in interface Forest
index
- the index of the parent row, in the interval [-1; forest.size()); if -1, will iterate over roots@NotNull public LongArray getRoots()
Forest
0
).@NotNull public ArrayForest filter(La<Long,?> filter)
Forest
Filters this forest by hiding rows that do not pass the filter
condition. The
resulting forest contains only the rows that pass the condition (all of them).
The topology of the resulting forest may differ from the original forest - that is, a row may
have a different parent in the resulting forest. This happens when a row that has sub-rows is filtered
out - in that case, its sub-tree is substituted instead of the parent row.
This is different from Forest.filterSoft(com.almworks.jira.structure.api.util.La<java.lang.Long, ?>)
method, which preserves the topology.
This forest is not modified by this method. If all rows pass the condition, then this forest is returned as the result. If filtering has taken place, a new forest is returned.
The filter method is called once for every row in the forest, and a truthy result
(as defined in La.accepts(T)
) indicates that the row passes the filter.
filter
in interface Forest
filter
- filter that returns a truthy value if the row with given ID is allowed to be present in the resulting forest.
Null means "no filtering" - this forest is returnedForest.filterSoft(com.almworks.jira.structure.api.util.La<java.lang.Long, ?>)
@NotNull public ArrayForest filterSoft(La<Long,?> filter)
Forest
Filters this forest by excluding rows that do not pass the filter
condition. All rows
that contain sub-rows that have passed the filter are also preserved. The
resulting forest contains sub-sequence of the original forest with rows having the same parents and depths.
Unlike Forest.filter(com.almworks.jira.structure.api.util.La<java.lang.Long, ?>)
method, this method preserves the topology of the original forest -
all rows in the resulting forest have the same root path as they do in the original forest.
This forest is not modified by this method. If all rows pass the condition, then this forest is returned as the result. If filtering has taken place, a new forest is returned.
The filter method is called once for every row in the forest, and a truthy result
(as defined in La.accepts(T)
) indicates that the row passes the filter.
Note: if you need to filter by hierarchy-based or JQL constraints, see StructureQuery
.
filterSoft
in interface Forest
filter
- filter that returns a truthy value if a row with given ID should be present in the resulting forest
Null means "no filtering" - this forest is returned@NotNull public ArrayForest filterHardest(La<Long,?> filter)
Forest
Filters this forest by excluding rows that do not pass the filter
condition.
All sub-rows of rows that have not passed the filter are also removed.
The resulting forest contains only rows that pass the condition, but possibly not all of them.
Unlike Forest.filter(com.almworks.jira.structure.api.util.La<java.lang.Long, ?>)
method, this method preserves the topology of the original forest -
all rows in the resulting forest have the same root path as they do in the original forest.
However, unlike Forest.filterSoft(com.almworks.jira.structure.api.util.La<java.lang.Long, ?>)
it achieves that by not including those matching rows
that would change the hierarchy.
This forest is not modified by this method. If all rows pass the condition, then this forest is returned as the result. If filtering has taken place, a new forest is returned.
The filter method is called once for every row in the forest, and a truthy result
(as defined in La.accepts(T)
) indicates that the row passes the filter.
filterHardest
in interface Forest
filter
- filter that returns a truthy value if a row with given ID should be present in the resulting forest
Null means "no filtering" - this forest is returned@NotNull public ArrayForest makeImmutable()
public boolean isImmutable()
Forest
isImmutable
in interface Forest
makeImmutable()
public int size()
size
in interface Forest
getRows()
and getDepths()
@NotNull public ArrayForest copy()
Forest
public boolean moveSubtree(long row, long under, long after) throws StructureException
moveSubtree(long, long, long, ForestChangeEventHandler)
without event handler.row
- the root row of the sub-tree being movedunder
- the new parent of the sub-tree, or 0 if the sub-tree should be placed at the forest root levelafter
- the preceding sibling of the new location for the sub-tree, or 0 to place sub-tree as the first childStructureException
- if the move is not possible - for example, under
is not in the forest or if you attempt to move a sub-tree under itselfpublic boolean moveSubtree(long row, long under, long after, @Nullable ForestChangeEventHandler eventHandler) throws StructureException
Moves sub-tree rooted at the specified row to a position specified by (under, after)
coordinates.
This method modifies the forest by removing the sub-tree with the specified row as the root and adding it
at the position specified by under-after
coordinates. See Forest
for the explanation
of under-after coordinates.
row
- the root row of the sub-tree being movedunder
- the new parent of the sub-tree, or 0 if the sub-tree should be placed at the forest root levelafter
- the preceding sibling of the new location for the sub-tree, or 0 to place sub-tree as the first childeventHandler
- optional handler of the move eventsStructureException
- if the move is not possible - for example, under
is not in the forest or if you attempt to move a sub-tree under itselfpublic int moveSubtreeAtIndex(int index, long under, long after, @Nullable ForestChangeEventHandler eventHandler) throws StructureException
Moves sub-tree rooted at the specified index to a position specified by (under, after)
coordinates.
This method modifies the forest by removing the sub-tree with the specified row as the root and adding it
at the position specified by under-after
coordinates. See Forest
for the explanation
of under-after coordinates.
index
- the index of the root row of the sub-tree being movedunder
- the new parent of the sub-tree, or 0 if the sub-tree should be placed at the forest root levelafter
- the preceding sibling of the new location for the sub-tree, or 0 to place sub-tree as the first childeventHandler
- optional handler of the move eventsStructureException
- if the move is not possible - for example, under
is not in the forest or if you attempt to move a sub-tree under itselfpublic int indexOf(long row)
Forest
Searches for the position of a specific row in the forest.
Execution of this method may take O(size())
time, however it may be
optimized if the implementation maintains an index. It's better to use this method rather
than using forest.getRows().indexOf(row)
because of the possible optimizations.
public boolean isEmpty()
Forest
@NotNull public String toFullString()
Forest
toString()
method, which may be truncated to some character number limit.toFullString
in interface Forest
public ArrayForest clone()
public long getLastChild(long parent)
Forest
Gets the last direct sub-row of the specified parent row.
Special case: when parent
is 0
,
returns the last root row in the forest.
If the parent row is not in the forest, or if it does not have child rows, the return value is 0
.
getLastChild
in interface Forest
parent
- parent rowpublic long getLastChildByIndex(int parentIndex)
Forest
Gets the last direct sub-row of the specified parent row.
Special case: when parentIndex
is less than zero,
returns the last root row in the forest.
If the parent row does not have child rows, the return value is 0
.
getLastChildByIndex
in interface Forest
parentIndex
- the index of the parent rowpublic <T,C> C foldUpwards(ForestParentChildrenClosure<T,C> closure)
Forest
This is a more generic version of Forest.visitParentChildrenUpwards(com.almworks.jira.structure.api.forest.raw.ForestParentChildrenVisitor)
that allows you to effectively
process the forest bottom-up, probably saving on memory allocation and search speed.
The method goes over the forest in the backwards direction and calls closure
methods for each
row:
ForestParentChildrenClosure.visitRow(com.almworks.jira.structure.api.forest.raw.ForestIterationControl, long, com.almworks.integers.LongList, C)
is called for every row (in the same way Forest.visitParentChildrenUpwards(com.almworks.jira.structure.api.forest.raw.ForestParentChildrenVisitor)
)
works;visitRow()
can return a result of the processing;ForestParentChildrenClosure.combine(com.almworks.jira.structure.api.forest.raw.ForestIterationControl, T, C)
is called after each call to visitRow()
to aggregate the results
of children under the same parent.foldUpwards
in interface Forest
T
- the type of the result of processing one rowC
- the type of the result of processing a number of sub-rows under the same parentclosure
- the closureForest.visitParentChildrenUpwards(com.almworks.jira.structure.api.forest.raw.ForestParentChildrenVisitor)
,
ForestParentChildrenClosure
public void scanDownwards(ForestScanner scanner)
Forest
ForestScanner
receives
ForestScanControl
, which can be used to cancel the scan, access parents, or skip subtrees.scanDownwards
in interface Forest
scanner
- the iterateepublic void visitParentChildrenUpwards(ForestParentChildrenVisitor visitor)
Forest
This method is used to efficiently traverse all pairs (parent, children) from the end of the forest upwards.
This method goes over the forest in the backwards direction and reports to the visitor pairs of (parent, direct children).
Invariants:
If the forest is modified during iteration, the results are undefined.
visitParentChildrenUpwards
in interface Forest
visitor
- the visitor to receive pairs of (parent, children)@NotNull public LongArray getPath(long row)
Forest
Returns the path to the specified row - a sequence of rows that starts with a
root row, ends with the specified row, and where element[i]
is
the parent row of element[i+1]
.
If row
is not in the forest, returns empty array.
The array is modifiable and owned by the calling code.
@NotNull public LongArray getPathForIndex(int idx)
Forest
Forest.getPath(long)
, returns the path to the row specified by index.getPathForIndex
in interface Forest
idx
- the index of the row to get the path to@NotNull public LongArray getParentPathForIndex(int index)
Forest
Returns the path to the specified row without the row itself. In other words, this is the path to the parent of the specified row, if there is one.
getParentPathForIndex
in interface Forest
index
- row indexForest.getPath(long)
@NotNull public Forest removeSubtree(long row)
removeSubtree(long, ForestChangeEventHandler)
without event handler.row
- the root of the sub-tree to be removedrow
is not in this forest.public void reorder(long parent, LongList children)
public void append(Forest forest)
@NotNull public LongIntIterator iterator()
public void replaceSubtrees(long rowId, Forest forest)
rowId
- parent rowId, or 0 if the whole forest should be replacedforest
- the content to insert in place of the removed sub-forest under rowIdpublic void replaceSubtreesMutuallyExclusive(long rowId, Forest forest)
public void replaceSubtreesMutuallyExclusiveAtIndex(int index, Forest forest)
index
- parent row index, should be in [-1, forest.size()) range, -1 means replace the whole forestforest
- the content to insert in place of the removed sub-forest underCopyright © 2024 Tempo Software. All Rights Reserved.