|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection
java.util.AbstractSet
LinkedListSet
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 |
java.util.LinkedList elements
Constructor Detail |
public LinkedListSet()
public LinkedListSet(java.util.Collection c)
Method Detail |
public int size()
size
in interface java.util.Set
public java.util.Iterator iterator()
iterator
in interface java.util.Set
public boolean add(java.lang.Object o)
add
in interface java.util.Set
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |