|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjpaul.DataStructs.NonIterableSet<T>
public class NonIterableSet<T>
NonIterableSet is a very simple set that CANNOT be
traversed. As such, it avoids the non-determinism problems of the
HashSets, without the cost of building a linked list
(as LinkedHashSet does). The idea of having such a
class occured to me while trying to find which
HashSets do not affect the externally-visible
determinism of a piece of code. Clearly, all sets that are used
only for membership testing (without ever being iterated upon) can
be left to be HashSet. One can use a
NonIterableSet instead, and get the type system check
the lack of iterations.
| Constructor Summary | |
|---|---|
NonIterableSet()
Creates a NonIterableSet backed by a private
HashSet with the default initial capacity. |
|
NonIterableSet(int initialCapacity)
Creates a NonIterableSet backed by a private
HashSet of a certain initial capacity. |
|
| Method Summary | |
|---|---|
boolean |
add(T elem)
Adds element elem to this set. |
boolean |
addAll(java.util.Collection<T> coll)
Adds all elements of collection coll to
this set. |
void |
clear()
Removes all elements from this set. |
boolean |
contains(T elem)
Checks whether the element elem belongs to
this set. |
boolean |
isEmpty()
Checks whether this set is empty. |
boolean |
remove(T elem)
Removes the element elem from this
set. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public NonIterableSet()
NonIterableSet backed by a private
HashSet with the default initial capacity.
public NonIterableSet(int initialCapacity)
NonIterableSet backed by a private
HashSet of a certain initial capacity.
| Method Detail |
|---|
public boolean add(T elem)
elem to this set.
Returns true iff elem is a new
element (i.e., it was not in the set before the call to this
method).
public boolean addAll(java.util.Collection<T> coll)
coll to
this set. Returns true iff we added
at least one new element to this non-iterable set.
public boolean contains(T elem)
elem belongs to
this set.
public boolean remove(T elem)
elem from this
set. Returns true if the set contained
elem.
public boolean isEmpty()
this set is empty.
public void clear()
this set.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||