Package org.apache.pivot.collections
Class Sequence.Tree<T>
- java.lang.Object
-
- org.apache.pivot.collections.Sequence.Tree<T>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSequence.Tree.ImmutablePathClass representing an immutable path.static interfaceSequence.Tree.ItemIterator<T>Nested sequence item iterator interface.static classSequence.Tree.PathAn object representing a path to a nested node in nested sequence data.
-
Constructor Summary
Constructors Constructor Description Tree()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> intadd(Sequence<T> sequence, T item, Sequence.Tree.Path path)Adds an item to a nested sequence.static <T> Sequence.Tree.ItemIterator<T>depthFirstIterator(Sequence<T> sequence)Returns an iterator that will perform a depth-first traversal of the nested sequence.static <T> Tget(Sequence<T> sequence, Sequence.Tree.Path path)Retrieves an item from a nested sequence.static <T> voidinsert(Sequence<T> sequence, T item, Sequence.Tree.Path path, int index)Inserts an item into a nested sequence.static booleanisDescendant(Sequence.Tree.Path ancestorPath, Sequence.Tree.Path descendantPath)Determines whether the path represented by the second argument is a descendant of the path represented by the first argument.static <T> Sequence.Tree.PathpathOf(Sequence<T> sequence, T item)Returns the path to an item in a nested sequence.static <T> Sequence<T>remove(Sequence<T> sequence, Sequence.Tree.Path path, int count)Removes items from a nested sequence.static <T> Sequence.Tree.Pathremove(Sequence<T> sequence, T item)Removes the first occurrence of an item from a nested sequence.static <T> Tupdate(Sequence<T> sequence, Sequence.Tree.Path path, T item)Updates an item in a nested sequence.
-
-
-
Method Detail
-
add
public static <T> int add(Sequence<T> sequence, T item, Sequence.Tree.Path path)
Adds an item to a nested sequence.- Type Parameters:
T- Type of the items in this sequence.- Parameters:
sequence- The root sequence.item- The item to be added to the sequence.path- The path of the sequence to which the item should be added.- Returns:
- The index at which the item was inserted, relative to the parent sequence.
-
insert
public static <T> void insert(Sequence<T> sequence, T item, Sequence.Tree.Path path, int index)
Inserts an item into a nested sequence.- Type Parameters:
T- Type of items in this sequence.- Parameters:
sequence- The root sequence.item- The item to be inserted into the sequence.path- The path of the sequence into which the item should be inserted.index- The index at which the item should be inserted within the parent sequence.
-
update
public static <T> T update(Sequence<T> sequence, Sequence.Tree.Path path, T item)
Updates an item in a nested sequence.- Type Parameters:
T- The type of items in this sequence.- Parameters:
sequence- The root sequence.path- The path of the item to update.item- The item that will replace any existing value at the given path.- Returns:
- The item that was previously stored at the given path.
-
remove
public static <T> Sequence.Tree.Path remove(Sequence<T> sequence, T item)
Removes the first occurrence of an item from a nested sequence.- Type Parameters:
T- The type of items in this sequence.- Parameters:
sequence- The root sequence.item- The item to remove.- Returns:
- The path of the item that was removed.
-
remove
public static <T> Sequence<T> remove(Sequence<T> sequence, Sequence.Tree.Path path, int count)
Removes items from a nested sequence.- Type Parameters:
T- The type of items in this sequence.- Parameters:
sequence- The root sequence.path- The path of the item(s) to remove.count- The number of items to remove.- Returns:
- The sequence of items that were removed.
-
get
public static <T> T get(Sequence<T> sequence, Sequence.Tree.Path path)
Retrieves an item from a nested sequence.- Type Parameters:
T- The type of items in this sequence.- Parameters:
sequence- The root sequence.path- The path of the item to retrieve.- Returns:
- The item at the given path, or
nullif the path is empty.
-
pathOf
public static <T> Sequence.Tree.Path pathOf(Sequence<T> sequence, T item)
Returns the path to an item in a nested sequence.- Type Parameters:
T- The type of items in this sequence.- Parameters:
sequence- The root sequence.item- The item to locate.- Returns:
- The path of first occurrence of the item if it exists in the
sequence;
nullotherwise.
-
depthFirstIterator
public static <T> Sequence.Tree.ItemIterator<T> depthFirstIterator(Sequence<T> sequence)
Returns an iterator that will perform a depth-first traversal of the nested sequence.- Type Parameters:
T- The type of items in this sequence.- Parameters:
sequence- The sequence for which we are requesting an iterator.- Returns:
- The new iterator over the sequence (depth-first order).
-
isDescendant
public static boolean isDescendant(Sequence.Tree.Path ancestorPath, Sequence.Tree.Path descendantPath)
Determines whether the path represented by the second argument is a descendant of the path represented by the first argument.- Parameters:
ancestorPath- The ancestor path to test.descendantPath- The descendant path to test.- Returns:
trueif the second argument is a descendant of the first path argument,falseotherwise.
-
-