gumbo.util
Class AbstractSetList

java.lang.Object
  |
  +--gumbo.util.AbstractSetList
All Implemented Interfaces:
java.util.Collection, java.util.List, java.io.Serializable, SetList

public class AbstractSetList
extends java.lang.Object
implements SetList, java.io.Serializable

A full implementation of the SetList interface that wraps a target list store. Identity (equals(), hashCode()) is that of the list store.

Note that SetList cannot be used with Collections.sort() because sort needs to add a duplicate object to the list. Instead, use the sort() methods of this wrapper.

Version:
$Revision: 1.2 $
Author:
Jon Barrilleaux (jonb@jmbaai.com) of JMB and Associates Inc.
See Also:
Serialized Form

Constructor Summary
AbstractSetList()
          Constructs an instance backed by an ArrayList.
AbstractSetList(java.util.List list)
          Constructs an instance backed by the specified target list.
 
Method Summary
 void add(int index, java.lang.Object element)
          Adds an element at a given position in this list.
 boolean add(java.lang.Object element)
          Adds an element to the end of this list.
 boolean addAll(java.util.Collection c)
           
 boolean addAll(int index, java.util.Collection c)
           
 java.util.Set asSet()
          Gets a mutable view of this setlist as a set, with a list iterator order.
 void clear()
           
 boolean contains(java.lang.Object elem)
           
 boolean containsAll(java.util.Collection c)
           
 boolean equals(java.lang.Object obj)
           
 java.lang.Object get(int index)
           
 SetList getSetList()
          Returns an immutable view of this setlist.
 int hashCode()
           
 int indexOf(java.lang.Object o)
           
 boolean isEmpty()
           
 java.util.Iterator iterator()
           
 int lastIndexOf(java.lang.Object o)
           
 java.util.ListIterator listIterator()
           
 java.util.ListIterator listIterator(int index)
           
 java.lang.Object remove(int index)
           
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection c)
           
 boolean retainAll(java.util.Collection c)
           
 java.lang.Object set(int index, java.lang.Object element)
           
 int size()
           
 void sort()
          Sorts this list into ascending order, according to the natural ordering of its elements.
 void sort(java.util.Comparator c)
          Sorts this list according to the order induced by the specified comparator.
 java.util.List subList(int fromIndex, int toIndex)
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] a)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractSetList

public AbstractSetList()
Constructs an instance backed by an ArrayList.


AbstractSetList

public AbstractSetList(java.util.List list)
Constructs an instance backed by the specified target list. This setlist will also be initialized from the contents of the list, with duplicates being eliminated. Once wrapped, the target list should not be modified directly, otherwise inconsistent behavior will result.

Method Detail

getSetList

public SetList getSetList()
Returns an immutable view of this setlist.

Returns:
A set view. Never null.

sort

public void sort(java.util.Comparator c)
Sorts this list according to the order induced by the specified comparator. (See Collections.sort().)

Specified by:
sort in interface SetList

sort

public void sort()
Sorts this list into ascending order, according to the natural ordering of its elements. (See Collections.sort().)

Specified by:
sort in interface SetList

asSet

public java.util.Set asSet()
Description copied from interface: SetList
Gets a mutable view of this setlist as a set, with a list iterator order.

Specified by:
asSet in interface SetList
Returns:
The view (Object). Never null.

add

public void add(int index,
                java.lang.Object element)
Adds an element at a given position in this list.

Specified by:
add in interface java.util.List
Throws:
java.lang.IllegalArgumentException - Element is already in this list.

add

public boolean add(java.lang.Object element)
Adds an element to the end of this list. If the element is already in the list, does nothing and returns false.

Specified by:
add in interface java.util.List

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.List

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Specified by:
addAll in interface java.util.List

clear

public void clear()
Specified by:
clear in interface java.util.List

contains

public boolean contains(java.lang.Object elem)
Specified by:
contains in interface java.util.List

containsAll

public boolean containsAll(java.util.Collection c)
Specified by:
containsAll in interface java.util.List

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.util.List

listIterator

public java.util.ListIterator listIterator()
Specified by:
listIterator in interface java.util.List
Throws:
java.lang.IllegalArgumentException - Element is already in this set.

listIterator

public java.util.ListIterator listIterator(int index)
Specified by:
listIterator in interface java.util.List
Throws:
java.lang.IllegalArgumentException - Element is already in this set.

remove

public java.lang.Object remove(int index)
Specified by:
remove in interface java.util.List

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.List

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.List

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.List

set

public java.lang.Object set(int index,
                            java.lang.Object element)
Specified by:
set in interface java.util.List
Throws:
java.lang.IllegalArgumentException - Element is already in this list.

subList

public java.util.List subList(int fromIndex,
                              int toIndex)
Specified by:
subList in interface java.util.List

get

public java.lang.Object get(int index)
Specified by:
get in interface java.util.List

indexOf

public int indexOf(java.lang.Object o)
Specified by:
indexOf in interface java.util.List

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.List

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Specified by:
lastIndexOf in interface java.util.List

size

public int size()
Specified by:
size in interface java.util.List

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.List

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Specified by:
toArray in interface java.util.List

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Specified by:
equals in interface java.util.List
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.List
Overrides:
hashCode in class java.lang.Object