|
|||||||||
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(java.util.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. |
java.lang.Object |
clone()
Returns a shallow copy of this IdentityHashSet instance:
the elements themselves are not cloned. |
boolean |
contains(java.lang.Object o)
Returns true if this set contains the specified element. |
boolean |
isEmpty()
Returns true if this set contains no elements. |
java.util.Iterator<E> |
iterator()
Returns an iterator over the elements in this set. |
static void |
main(java.lang.String[] args)
Just for testing. |
boolean |
remove(java.lang.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(java.util.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 java.util.Collection<E>
add
in interface java.util.Set<E>
add
in class java.util.AbstractCollection<E>
o
- element to add to this set
public void clear()
clear
in interface java.util.Collection<E>
clear
in interface java.util.Set<E>
clear
in class java.util.AbstractCollection<E>
public java.lang.Object clone()
IdentityHashSet
instance:
the elements themselves are not cloned.
clone
in class java.lang.Object
public boolean contains(java.lang.Object o)
equals()
) to test whether an element is present in the
set.
contains
in interface java.util.Collection<E>
contains
in interface java.util.Set<E>
contains
in class java.util.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 java.util.Collection<E>
isEmpty
in interface java.util.Set<E>
isEmpty
in class java.util.AbstractCollection<E>
true
if this set contains no elements.public java.util.Iterator<E> iterator()
iterator
in interface java.lang.Iterable<E>
iterator
in interface java.util.Collection<E>
iterator
in interface java.util.Set<E>
iterator
in class java.util.AbstractCollection<E>
Iterator
over the elements in this set.public boolean remove(java.lang.Object o)
equals()
) to test whether an element is present in the
set.
remove
in interface java.util.Collection<E>
remove
in interface java.util.Set<E>
remove
in class java.util.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 java.util.Collection<E>
size
in interface java.util.Set<E>
size
in class java.util.AbstractCollection<E>
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |