org.apache.pivot.collections
Interface Sequence<T>

All Known Subinterfaces:
List<T>
All Known Implementing Classes:
ArrayAdapter, ArrayList, Element, Element.AttributeSequence, EnumList, FileList, ImmutableList, LinkedList, ListAdapter, ResultList, Sequence.Tree.ImmutablePath, Sequence.Tree.Path, SynchronizedList, TaskSequence

public interface Sequence<T>

Interface representing an ordered sequence of items.


Nested Class Summary
static class Sequence.Tree<T>
          Collection of static utility methods providing path access to nested sequence data.
 
Method Summary
 int add(T item)
          Adds an item to the sequence.
 T get(int index)
          Retrieves the item at the given index.
 int getLength()
          Returns the length of the sequence.
 int indexOf(T item)
          Returns the index of an item in the sequence.
 void insert(T item, int index)
          Inserts an item into the sequence at a specific index.
 Sequence<T> remove(int index, int count)
          Removes one or more items from the sequence.
 int remove(T item)
          Removes the first occurrence of the given item from the sequence.
 T update(int index, T item)
          Updates the item at the given index.
 

Method Detail

add

int add(T item)
Adds an item to the sequence.

Parameters:
item - The item to be added to the sequence.
Returns:
The index at which the item was added, or -1 if the item was not added to the sequence.

insert

void insert(T item,
            int index)
Inserts an item into the sequence at a specific index.

Parameters:
item - The item to be added to the sequence.
index - The index at which the item should be inserted. Must be a value between 0 and getLength().

update

T update(int index,
         T item)
Updates the item at the given index.

Parameters:
index - The index of the item to update.
item - The item that will replace any existing value at the given index.
Returns:
The item that was previously stored at the given index.

remove

int remove(T item)
Removes the first occurrence of the given item from the sequence.

Parameters:
item - The item to remove.
Returns:
The index of the item that was removed, or -1 if the item could not be found.
See Also:
remove(int, int)

remove

Sequence<T> remove(int index,
                   int count)
Removes one or more items from the sequence.

Parameters:
index - The starting index to remove.
count - The number of items to remove, beginning with index.
Returns:
A sequence containing the items that were removed.

get

T get(int index)
Retrieves the item at the given index.

Parameters:
index - The index of the item to retrieve.

indexOf

int indexOf(T item)
Returns the index of an item in the sequence.

Parameters:
item - The item to locate.
Returns:
The index of first occurrence of the item if it exists in the sequence; -1, otherwise.

getLength

int getLength()
Returns the length of the sequence.

Returns:
The number of items in the sequence.