org.apache.pivot.collections
Class Sequence.Tree<T>

java.lang.Object
  extended by org.apache.pivot.collections.Sequence.Tree<T>
Type Parameters:
T - note that in Tree the type parameter currently it's not used
Enclosing interface:
Sequence<T>

public static class Sequence.Tree<T>
extends Object

Collection of static utility methods providing path access to nested sequence data.


Nested Class Summary
static class Sequence.Tree.ImmutablePath
          Class representing an immutable path.
static interface Sequence.Tree.ItemIterator<T>
          Nested sequence item iterator interface.
static class Sequence.Tree.Path
          An object representing a path to a nested node in nested sequence data.
 
Constructor Summary
Sequence.Tree()
           
 
Method Summary
static
<T> int
add(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> T
get(Sequence<T> sequence, Sequence.Tree.Path path)
          Retrieves an item from a nested sequence.
static
<T> void
insert(Sequence<T> sequence, T item, Sequence.Tree.Path path, int index)
          Inserts an item into a nested sequence.
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.
static
<T> Sequence.Tree.Path
pathOf(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 an item from a nested sequence.
static
<T> Sequence.Tree.Path
remove(Sequence<T> sequence, T item)
          Removes the first occurrence of an item from a nested sequence.
static
<T> T
update(Sequence<T> sequence, Sequence.Tree.Path path, T item)
          Updates an item in a nested sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sequence.Tree

public Sequence.Tree()
Method Detail

add

public static <T> int add(Sequence<T> sequence,
                          T item,
                          Sequence.Tree.Path path)
Adds an item to a nested 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.

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.

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.

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 an item from a nested sequence.

Parameters:
sequence - The root sequence.
path - The path of the item to remove.

get

public static <T> T get(Sequence<T> sequence,
                        Sequence.Tree.Path path)
Retrieves an item from a nested sequence.

Parameters:
sequence - The root sequence.
path - The path of the item to retrieve.
Returns:
The item at the given path, or null if 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.

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; null, otherwise.

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.


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.