org.jaffa.util
Class ListSet

java.lang.Object
  extended byorg.jaffa.util.ListSet
All Implemented Interfaces:
Cloneable, Collection, Serializable, Set

public class ListSet
extends Object
implements Set, Cloneable, Serializable

This class is backed by an ArrayList. Features are 1) Ensure the Set functionality of unique elements(including a null) in this data structure 2) Iterate through the list in the order in which the entries were made

See Also:
Serialized Form

Constructor Summary
ListSet()
          Creates new ListSet
ListSet(Collection c)
          Creates new ListSet from an existing Collection.
ListSet(int initialCapacity)
          Creates new ListSet specifying the initial capacity.
 
Method Summary
 void add(int index, Object o)
          Adds the specified element to this set if it is not already present, at the specified index.
 boolean add(Object o)
          Adds the specified element to this set if it is not already present.
 boolean addAll(Collection c)
          Adds all of the elements in the specified collection to this set if they're not already present.
 void clear()
          Removes all of the elements from this set.
 Object clone()
          Returns a clone of the Set.
 boolean contains(Object o)
          Returns true if this set contains the specified element.
 boolean containsAll(Collection c)
          Returns true if this set contains all of the elements of the specified collection.
 boolean equals(Object o)
          Compares the specified object with this set for equality.
 Object get(int index)
          Returns the element from the specified position.
 int hashCode()
          Returns the hash code value for this set.
 int indexOf(Object o)
          Returns the index of the element in this set.
 boolean isEmpty()
          Returns true if this set contains no elements.
 Iterator iterator()
          Returns an iterator over the elements in this set.
 Object remove(int index)
          Remove the element from the specified position.
 boolean remove(Object o)
          Removes the specified element from this set if it is present.
 boolean removeAll(Collection c)
          Removes from this set all of its elements that are contained in the specified collection.
 boolean retainAll(Collection c)
          Retains only the elements in this set that are contained in the specified collection.
 int size()
          Returns the number of elements in this set.
 Object[] toArray()
          Returns an array containing all of the elements in this set.
 Object[] toArray(Object[] a)
          Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListSet

public ListSet()
Creates new ListSet


ListSet

public ListSet(int initialCapacity)
Creates new ListSet specifying the initial capacity.

Parameters:
initialCapacity - The initial capacity.

ListSet

public ListSet(Collection c)
Creates new ListSet from an existing Collection.

Parameters:
c - An existing collection.
Method Detail

retainAll

public boolean retainAll(Collection c)
Retains only the elements in this set that are contained in the specified collection.

Specified by:
retainAll in interface Set
Parameters:
c - collection that defines which elements this set will retain.
Returns:
true if this collection changed as a result of the call.

contains

public boolean contains(Object o)
Returns true if this set contains the specified element.

Specified by:
contains in interface Set
Parameters:
o - element whose presence in this set is to be tested.
Returns:
true if this set contains the specified element.

toArray

public Object[] toArray()
Returns an array containing all of the elements in this set.

Specified by:
toArray in interface Set
Returns:
an array containing all of the elements in this set.

toArray

public Object[] toArray(Object[] a)
Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

Specified by:
toArray in interface Set
Parameters:
a - the array into which the elements of this set are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array

iterator

public Iterator iterator()
Returns an iterator over the elements in this set.

Specified by:
iterator in interface Set
Returns:
an iterator over the elements in this set.

removeAll

public boolean removeAll(Collection c)
Removes from this set all of its elements that are contained in the specified collection.

Specified by:
removeAll in interface Set
Parameters:
c - collection that defines which elements will be removed from this set.
Returns:
true if this set changed as a result of the call.

remove

public boolean remove(Object o)
Removes the specified element from this set if it is present.

Specified by:
remove in interface Set
Parameters:
o - object to be removed from this set, if present.
Returns:
true if the set contained the specified element.

clear

public void clear()
Removes all of the elements from this set.

Specified by:
clear in interface Set

hashCode

public int hashCode()
Returns the hash code value for this set.

Specified by:
hashCode in interface Set
Returns:
the hash code value for this set.

addAll

public boolean addAll(Collection c)
Adds all of the elements in the specified collection to this set if they're not already present.

Specified by:
addAll in interface Set
Parameters:
c - collection whose elements are to be added to this set.
Returns:
true if this set changed as a result of the call.

size

public int size()
Returns the number of elements in this set.

Specified by:
size in interface Set
Returns:
the number of elements in this set.

containsAll

public boolean containsAll(Collection c)
Returns true if this set contains all of the elements of the specified collection.

Specified by:
containsAll in interface Set
Parameters:
c - collection to be checked for containment in this set.
Returns:
true if this set contains all of the elements of the specified collection.

add

public boolean add(Object o)
Adds the specified element to this set if it is not already present.

Specified by:
add in interface Set
Parameters:
o - element to be added to this set.
Returns:
true if this set did not already contain the specified element.

equals

public boolean equals(Object o)
Compares the specified object with this set for equality.

Specified by:
equals in interface Set
Parameters:
o - Object to be compared for equality with this set.
Returns:
true if the specified Object is equal to this set.

isEmpty

public boolean isEmpty()
Returns true if this set contains no elements.

Specified by:
isEmpty in interface Set
Returns:
true if this set contains no elements.

add

public void add(int index,
                Object o)
Adds the specified element to this set if it is not already present, at the specified index.

Parameters:
index - The position at which the element is to be added.
o - element to be added to this set.

get

public Object get(int index)
Returns the element from the specified position.

Parameters:
index - The position from which the element is to be retrieved.
Returns:
the element from the specified position.

remove

public Object remove(int index)
Remove the element from the specified position.

Parameters:
index - The position from which the element is to be removed.
Returns:
the element being removed.

indexOf

public int indexOf(Object o)
Returns the index of the element in this set.

Parameters:
o - The element whose index is to be found.
Returns:
the index of the element in this set.

clone

public Object clone()
             throws CloneNotSupportedException
Returns a clone of the Set.

Returns:
a clone of the Set.
Throws:
CloneNotSupportedException - if cloning is not supported. Should never happen.


Copyright © 2002-2004 JAFFA Project.