Class LinkedListSet

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractSet
          extended byLinkedListSet
All Implemented Interfaces:
java.util.Collection, java.util.Set
Direct Known Subclasses:
VariableValueSet

public class LinkedListSet
extends java.util.AbstractSet
implements java.util.Set

LinkedListSet implements the Set interface using a LinkedList to store the elements of the set. This will/should/might have less overhead than a HashSet for small sets.
Implementation Note: Extending AbstractSet allows us to get by with specifying the minimal number of additional methods (namely size(), iterator(), and add()). It might be faster to implement some of the other operations, but the default implementations are likely to be just as good for this set backed by a LinkedList (e.g., contains() is almost certainly implemented by using the iterator() to look for the element, which is essentially equivalent to our calling contains() on the backing LinkedList.


Field Summary
(package private)  java.util.LinkedList elements
          LinkedList holding the elements in this set.
 
Constructor Summary
LinkedListSet()
          Creates a new empty LinkedListSet.
LinkedListSet(java.util.Collection c)
          Creates a new LinkedListSet with the same contents as the given Collection.
 
Method Summary
 boolean add(java.lang.Object o)
          Ensures that this collection contains the specified element Returns true if the set changed as a result of the call.
 java.util.Iterator iterator()
          Returns an iterator over the elements contained in this set.
 int size()
          Returns the number of elements in this set.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, contains, containsAll, isEmpty, remove, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

elements

java.util.LinkedList elements
LinkedList holding the elements in this set.

Constructor Detail

LinkedListSet

public LinkedListSet()
Creates a new empty LinkedListSet. This constructor is required by the conventions of the Collection interface.


LinkedListSet

public LinkedListSet(java.util.Collection c)
Creates a new LinkedListSet with the same contents as the given Collection. This constructor is required by the conventions of the Collection interface.

Method Detail

size

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

Specified by:
size in interface java.util.Set

iterator

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

Specified by:
iterator in interface java.util.Set

add

public boolean add(java.lang.Object o)
Ensures that this collection contains the specified element Returns true if the set changed as a result of the call. Returns false if the set already contains the specified element.

Specified by:
add in interface java.util.Set