pivot.collections
Class Sequence.Tree

java.lang.Object
  extended by pivot.collections.Sequence.Tree
Enclosing interface:
Sequence<T>

public static class Sequence.Tree
extends java.lang.Object

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

Author:
gbrown

Constructor Summary
Sequence.Tree()
           
 
Method Summary
static
<T> int
add(Sequence<T> sequence, T item, Sequence<java.lang.Integer> path)
          Adds an item to a nested sequence.
static
<T> T
get(Sequence<T> sequence, Sequence<java.lang.Integer> path)
          Retrieves an item from a nested sequence.
static
<T> void
insert(Sequence<T> sequence, T item, Sequence<java.lang.Integer> path, int index)
          Inserts an item into a nested sequence.
static boolean isDescendant(Sequence<java.lang.Integer> ancestorPath, Sequence<java.lang.Integer> descendantPath)
          Determines whether the path represented by the second argument is a descendant of the path represented by the first argument.
static
<T> Sequence<java.lang.Integer>
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<java.lang.Integer> path, int count)
          Removes an item from a nested sequence.
static
<T> Sequence<java.lang.Integer>
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<java.lang.Integer> 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<java.lang.Integer> 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<java.lang.Integer> 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<java.lang.Integer> 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<java.lang.Integer> 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<java.lang.Integer> 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<java.lang.Integer> 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<java.lang.Integer> 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.

isDescendant

public static boolean isDescendant(Sequence<java.lang.Integer> ancestorPath,
                                   Sequence<java.lang.Integer> 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.