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

All Superinterfaces:
Collection<T>, Iterable<T>, Sequence<T>
All Known Implementing Classes:
ArrayList, Element, EnumList, FileList, ImmutableList, LinkedList, ListAdapter, ResultList, SynchronizedList

public interface List<T>
extends Sequence<T>, Collection<T>

Collection interface representing an ordered sequence of items.


Nested Class Summary
static interface List.ItemIterator<T>
          Optional item iterator interface.
static class List.ListListenerList<T>
          List listener list.
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Sequence
Sequence.Tree<T>
 
Method Summary
 int add(T item)
          Adds an item to the list.
 void clear()
          Removes all elements from the collection.
 int getLength()
          Returns the length of the list.
 ListenerList<ListListener<T>> getListListeners()
          Returns the list listener list.
 void insert(T item, int index)
          Inserts an item into the list.
 Sequence<T> remove(int index, int count)
          Removes one or more items from the sequence.
 void setComparator(Comparator<T> comparator)
          Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.
 T update(int index, T item)
          Updates the item at the given index.
 
Methods inherited from interface org.apache.pivot.collections.Sequence
get, indexOf, remove
 
Methods inherited from interface org.apache.pivot.collections.Collection
getComparator, isEmpty
 
Methods inherited from interface java.lang.Iterable
iterator
 

Method Detail

add

int add(T item)
Adds an item to the list. If the list is unsorted, the item is appended to the end of the list. Otherwise, it is inserted at the appropriate index.

Specified by:
add in interface Sequence<T>
Parameters:
item - The item to be added to the sequence.
Returns:
The index at which the item was added.
See Also:
ListListener.itemInserted(List, int)

insert

void insert(T item,
            int index)
Inserts an item into the list.

Specified by:
insert in interface Sequence<T>
Parameters:
item - The item to be added to the list.
index - The index at which the item should be inserted. Must be a value between 0 and getLength().
Throws:
IllegalArgumentException - If the list is sorted and the insertion point of the item does not match the given index.
See Also:
ListListener.itemInserted(List, int)

update

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

Specified by:
update in interface Sequence<T>
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.
Throws:
IllegalArgumentException - If the list is sorted and the index of the updated item would be different than its current index.
See Also:
ListListener.itemUpdated(List, int, Object)

remove

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

Specified by:
remove in interface Sequence<T>
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.
See Also:
ListListener.itemsRemoved(List, int, Sequence)

clear

void clear()
Description copied from interface: Collection
Removes all elements from the collection.

Specified by:
clear in interface Collection<T>
See Also:
ListListener.itemsRemoved(List, int, Sequence)

getLength

int getLength()
Returns the length of the list.

Specified by:
getLength in interface Sequence<T>
Returns:
The number of items in the list, or -1 if the list's length is not known. In this case, the iterator must be used to retrieve the contents of the list.

setComparator

void setComparator(Comparator<T> comparator)
Description copied from interface: Collection
Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.

Calling this method more than once with the same comparator will re-sort the collection.

Specified by:
setComparator in interface Collection<T>
Parameters:
comparator - The comparator used to order elements in the collection, or null if the collection is unsorted.
See Also:
ListListener.comparatorChanged(List, Comparator)

getListListeners

ListenerList<ListListener<T>> getListListeners()
Returns the list listener list.