|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractSet<E>
edu.stanford.nlp.util.IdentityHashSet<E>
public class IdentityHashSet<E>
This class provides a IdentityHashMap-backed
implementation of the Set interface. This means that
whether an object is an element of the set depends on whether it is ==
(rather than equals()) to an element of the set. This is
different from a normal HashSet, where set membership
depends on equals(), rather than ==.
Each element in the set is a key in the backing IdentityHashMap; each key
maps to a static token, denoting that the key does, in fact, exist.
Most operations are O(1), assuming no hash collisions. In the worst
case (where all hashes collide), operations are O(n).
| Constructor Summary | |
|---|---|
IdentityHashSet()
Construct a new, empty IdentityHashSet whose backing IdentityHashMap has the default expected maximum size (21); |
|
IdentityHashSet(Collection<? extends E> c)
Construct a new IdentityHashSet with the same elements as the supplied Collection (eliminating any duplicates, of course); the backing IdentityHashMap will have the default expected maximum size (21). |
|
IdentityHashSet(int expectedMaxSize)
Construct a new, empty IdentityHashSet whose backing IdentityHashMap has the specified expected maximum size. |
|
| Method Summary | |
|---|---|
boolean |
add(E o)
Adds the specified element to this set if it is not already present. |
void |
clear()
Removes all of the elements from this set. |
Object |
clone()
Returns a shallow copy of this IdentityHashSet instance:
the elements themselves are not cloned. |
boolean |
contains(Object o)
Returns true if this set contains the specified element. |
boolean |
isEmpty()
Returns true if this set contains no elements. |
Iterator<E> |
iterator()
Returns an iterator over the elements in this set. |
static void |
main(String[] args)
Just for testing. |
boolean |
remove(Object o)
Removes the specified element from this set if it is present. |
int |
size()
Returns the number of elements in this set (its cardinality). |
| Methods inherited from class java.util.AbstractSet |
|---|
equals, hashCode, removeAll |
| Methods inherited from class java.util.AbstractCollection |
|---|
addAll, containsAll, retainAll, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Set |
|---|
addAll, containsAll, retainAll, toArray, toArray |
| Constructor Detail |
|---|
public IdentityHashSet()
public IdentityHashSet(int expectedMaxSize)
expectedMaxSize - the expected maximum size of the set.public IdentityHashSet(Collection<? extends E> c)
c - a Collection containing the elements with which this set will
be initialized.| Method Detail |
|---|
public boolean add(E o)
equals()) to test whether an element is present in the
set.
add in interface Collection<E>add in interface Set<E>add in class AbstractCollection<E>o - element to add to this set
public void clear()
clear in interface Collection<E>clear in interface Set<E>clear in class AbstractCollection<E>public Object clone()
IdentityHashSet instance:
the elements themselves are not cloned.
clone in class Objectpublic boolean contains(Object o)
equals()) to test whether an element is present in the
set.
contains in interface Collection<E>contains in interface Set<E>contains in class AbstractCollection<E>o - Element whose presence in this set is to be
tested.
true if this set contains the specified element.public boolean isEmpty()
true if this set contains no elements.
isEmpty in interface Collection<E>isEmpty in interface Set<E>isEmpty in class AbstractCollection<E>true if this set contains no elements.public Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in interface Set<E>iterator in class AbstractCollection<E>Iterator over the elements in this set.public boolean remove(Object o)
equals()) to test whether an element is present in the
set.
remove in interface Collection<E>remove in interface Set<E>remove in class AbstractCollection<E>o - Object to be removed from this set, if present.
true if the set contained the specified element.public int size()
size in interface Collection<E>size in interface Set<E>size in class AbstractCollection<E>public static void main(String[] args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||