|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
E
- a restriction on the types of elements that may be included in the
collectionpublic interface Collection<E>
Provides protocol for manipulating and operating on a collection of objects, called elements, either individually or as a whole. A collection can be fixed or variable-sized, ordered or unordered, and its elements may or may not be accessible by external keys.
Some implementations of collections may choose to use the hash values of either the elements of the collection or the keys by which those elements are accessed (if there are any). If the hash values of such objects are modified, the behavior of any message sent to such a collection is undefined until the collection is rehashed in order to restore its consistency.
Method Summary | ||
---|---|---|
boolean |
allSatisfy(UnaryCondition<? super E> discriminator)
Answers true if the given discriminator answers true for every
element of this collection, or if this collection is empty; otherwise answers false . |
|
boolean |
anySatisfy(UnaryCondition<? super E> discriminator)
Answers true if the given discriminator answers true for any
element of this collection; answers false otherwise, or if this
collection is empty. |
|
|
collect(UnaryFunctor<? super E,? extends R> transformer)
Evaluates the given transformer for each element of this collection, with the element as the parameter, and answers a new collection containing the results of these evaluations. |
|
E |
detect(UnaryCondition<? super E> discriminator)
Answers the first element of this collection for which the given discriminator answers true when given that element as an argument. |
|
void |
forEachDo(UnaryFunctor<? super E,?> operation)
For each element of this collection, evaluates the given operation with the element as the parameter. |
|
boolean |
includes(E target)
Answers true if an element of this collection is equivalent to the
given one; answers false otherwise. |
|
|
inject(R initialValue,
BinaryFunctor<? super R,? super E,? extends R> operation)
Answers the final result of evaluating the given operation using each element of this collection and the previous evaluation result as the parameters. |
|
boolean |
isEmpty()
Answers true iff this collection's size is zero;
otherwise answers false . |
|
int |
occurrencesOf(E target)
Answers the number of elements of this collection which are equivalent to the given target. |
|
void |
rehash()
Re-establishes any hash invariants of this collection. |
|
Collection<E> |
reject(UnaryCondition<? super E> discriminator)
Answers a new collection which contains only the elements in this collection which cause the given discriminator to answer false . |
|
Collection<E> |
select(UnaryCondition<? super E> discriminator)
Answers a new collection which contains only the elements in this collection which cause the given discriminator to answer true . |
|
int |
size()
Answers the number of elements in this collection. |
|
Object[] |
toArray()
Answers an array with the same elements as this collection, with the same size as this collection, and a component class of Object . |
|
Object[] |
toArray(Class<? super E> componentClass)
Answers an array with the same elements as this collection, with the same size as this collection, and a component type of the given class. |
|
Bag<E> |
toBag()
Answers a bag with the same elements as this collection. |
|
IdentityBag<E> |
toIdentityBag()
Answers an identity bag with the same elements as this collection. |
|
IdentitySet<E> |
toIdentitySet()
Answers an identity set with the same elements as this collection. |
|
OrderedCollection<E> |
toOrderedCollection()
Answers an ordered collection with the same elements as this collection. |
|
Set<E> |
toSet()
Answers a set with the same elements as this collection. |
|
SortedCollection<E> |
toSortedCollection()
Answers a sorted collection with the same elements as this collection. |
|
SortedCollection<E> |
toSortedCollection(Comparator<? super E> comparator)
Answers a sorted collection with the same elements as this collection, using the given comparator to order the elements. |
Method Detail |
---|
boolean allSatisfy(UnaryCondition<? super E> discriminator)
true
if the given discriminator answers true
for every
element of this collection, or if this collection is empty; otherwise answers false
.
It is unspecified whether discriminator
will be evaluated with every
element of this collection.
discriminator
- the discriminator to evaluate
discriminator
is true
for every element
NullPointerException
- if discriminator
is null
boolean anySatisfy(UnaryCondition<? super E> discriminator)
true
if the given discriminator answers true
for any
element of this collection; answers false
otherwise, or if this
collection is empty.
It is unspecified whether discriminator
will be evaluated with every
element of this collection.
discriminator
- the discriminator to evaluate
discriminator
is true
for any element
NullPointerException
- if the discriminator
is null
Object[] toArray()
Object
. This means that objects of any class may be inserted into
the result.
If this collection maintains an ordering for its elements, the order of those
elements will be preserved in the result.
toArray(Class)
,
Collections.toArray(Collection,Class)
Object[] toArray(Class<? super E> componentClass)
Object[]
. With Java
generics, it is not possible to express the return type as an array of the
component class without sacrificing the flexibility of providing a
componentClass
that is a supertype of the generic parameter's actual
argument. Therefore, the caller should downcast to the desired type, or risk
raising ArrayStoreException
when inserting via a reference of type
Object[]
.
If this collection maintains an ordering for its elements, the order of those
elements will be preserved in the result.
componentClass
- the desired type of the result array's components
NullPointerException
- if componentClass
is null
Collections.toArray(Collection,Class)
Bag<E> toBag()
IdentityBag<E> toIdentityBag()
IdentitySet<E> toIdentitySet()
OrderedCollection<E> toOrderedCollection()
Set<E> toSet()
SortedCollection<E> toSortedCollection()
SortedCollection<E> toSortedCollection(Comparator<? super E> comparator)
comparator
- a comparator
<R> Collection<R> collect(UnaryFunctor<? super E,? extends R> transformer)
forEachDo
for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection.
R
- return type of the transformertransformer
- the transformer to evaluate
NullPointerException
- if transformer
is null
E detect(UnaryCondition<? super E> discriminator)
true
when given that element as an argument.
discriminator
will only be evaluated until such an object is found or
until all of the elements of the collection have been used as arguments.
That is, there may be elements of this collection that are never used as
arguments to discriminator
.
The elements are traversed in the order specified by forEachDo
for this collection.
discriminator
- the discriminator to evaluate
discriminator
NoSuchElementException
- if no element of this collection
satisfies discriminator
NullPointerException
- if discriminator
is null
void forEachDo(UnaryFunctor<? super E,?> operation)
operation
- the operation to perform
NullPointerException
- if operation
is null
boolean includes(E target)
true
if an element of this collection is equivalent to the
given one; answers false
otherwise.
target
- the object to compare against
<R> R inject(R initialValue, BinaryFunctor<? super R,? super E,? extends R> operation)
operation
is performed with the given initial
value as the first parameter, and the first element of this collection as the
second parameter. Subsequent evaluations are done with the result of the
previous evaluation as the first parameter, and the next element as the second
parameter. The result of the last evaluation is answered.
If this collection is empty, answers the initial value.
The elements are traversed in the order specified by forEachDo
for this collection.
R
- return type and type of first argument of the operationinitialValue
- first parameter for the first evaluationoperation
- the operation to evaluate
NullPointerException
- if operation
is null
boolean isEmpty()
true
iff this collection's size is zero;
otherwise answers false
.
int occurrencesOf(E target)
target
- the object to compare against
void rehash()
Collection<E> reject(UnaryCondition<? super E> discriminator)
false
.
For each element of this collection, discriminator
is evaluated with the
element as the parameter. Each element which causes discriminator
to
answer false
is included in the new collection.
The elements are traversed in the order specified by forEachDo
for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection. If both this collection
and the result maintain an ordering of their elements, the elements of the
result will be in the same relative order as the elements of this collection.
discriminator
- the discriminator to evaluate
NullPointerException
- if discriminator
is null
Collection<E> select(UnaryCondition<? super E> discriminator)
true
.
For each element of this collection, discriminator
is evaluated with the
element as the parameter. Each element which causes discriminator
to
answer true
is included in the new collection.
The elements are traversed in order specified by forEachDo
for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection. If both this collection
and the result maintain an ordering of their elements, the elements of the
result will be in the same relative order as the elements of this collection.
discriminator
- the discriminator to evaluate
NullPointerException
- if discriminator
is null
int size()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |