|
|||||||||
| 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<T>
jpaul.DataStructs.ArraySet<T>
public class ArraySet<T>
ArraySet is an immutable, array-backed set. It
consumes minimal memory; very good for small sets.
| Constructor Summary | |
|---|---|
ArraySet(java.util.Collection<T> coll)
Creates an ArraySet containing the distinct
elements from the colection coll. |
|
ArraySet(java.util.Collection<T> coll,
boolean collHasDistinctElements)
Powerful and unsafe constructor: creates an ArraySet containing the distinct elements present
in the colection coll. |
|
ArraySet(java.util.Set<T> set)
Creates an ArraySet containing the elements
present in the set set. |
|
ArraySet(T... ts)
Creates an ArraySet with the elements given as a
variable-length list of arguments (instead of a collection). |
|
| Method Summary | |
|---|---|
boolean |
contains(java.lang.Object o)
|
java.util.Iterator<T> |
iterator()
|
int |
size()
|
| Methods inherited from class java.util.AbstractSet |
|---|
equals, hashCode, removeAll |
| Methods inherited from class java.util.AbstractCollection |
|---|
add, addAll, clear, 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 |
|---|
add, addAll, clear, containsAll, isEmpty, remove, retainAll, toArray, toArray |
| Constructor Detail |
|---|
public ArraySet(java.util.Set<T> set)
ArraySet containing the elements
present in the set set. The created
ArraySet contains the elements of
set at the point this constructor is invoked;
future changes to set are not reflected by the
ArraySet.
public ArraySet(java.util.Collection<T> coll)
ArraySet containing the distinct
elements from the colection coll.
coll may contain duplicates, but only distinct
elements will appear in the created ArraySet.
Future changes to coll are not reflected by this
ArraySet.
Note: This constructor is more general
than ArraySet(Set), which may lead to a little bit of
confusion: a set is also a collection, so both constructors
apply in certain cases. Semantically, whether you invoke one
constructor or the other, it is the same thing. Still, the
constructor that takes a set knows that the elements of the
set are unique (by the contract of a set); the constructor
that takes a collection has no such guarantee, so it needs to
avoid inserting equal elements to the constructed
ArraySet. So, the constructor that takes a set
is faster; it's a classic example of using the type system to
speed-up the program execution.
public ArraySet(T... ts)
ArraySet with the elements given as a
variable-length list of arguments (instead of a collection).
E.g., new ArraySet<T>(e1, e2, e3, e4) is
equivalent to new ArraySet<T>(Arrays.asList(e1,
e2, e3, e4)).
public ArraySet(java.util.Collection<T> coll,
boolean collHasDistinctElements)
ArraySet containing the distinct elements present
in the colection coll. If the second parameter
collHasDistinctElements is true,
then this constructor assumes that coll contains
only distinct elements and skips the costly step of
determining the unique elements from
coll. This feature is unsafe and should
be used with maximal care!.
The created ArraySet contains the elements of
coll at the point this constructor is invoked;
future changes to coll are not reflected by the
ArraySet.
| Method Detail |
|---|
public boolean contains(java.lang.Object o)
contains in interface java.util.Collection<T>contains in interface java.util.Set<T>contains in class java.util.AbstractCollection<T>public java.util.Iterator<T> iterator()
iterator in interface java.lang.Iterable<T>iterator in interface java.util.Collection<T>iterator in interface java.util.Set<T>iterator in class java.util.AbstractCollection<T>public int size()
size in interface java.util.Collection<T>size in interface java.util.Set<T>size in class java.util.AbstractCollection<T>
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||