jaggregate
Class AbstractExtensibleCollection<E>

java.lang.Object
  extended by jaggregate.AbstractCollection<E>
      extended by jaggregate.AbstractExtensibleCollection<E>
Type Parameters:
E - a restriction on the types of elements that may be included in the collection
All Implemented Interfaces:
Collection<E>, ExtensibleCollection<E>
Direct Known Subclasses:
AbstractBag, AbstractDictionaryImpl, AbstractSet, OrderedCollection, SortedCollection

public abstract class AbstractExtensibleCollection<E>
extends AbstractCollection<E>
implements ExtensibleCollection<E>

Implementation of the extensible collection concept that should be common for most concrete implementations.

Version:
$Id: AbstractExtensibleCollection.java,v 1.7 2008/10/03 19:01:23 pholser Exp $
Author:
Paul Holser

Method Summary
 void addAll(Collection<? extends E> newElements)
          Adds each element of the given collection to this collection.
 void addAll(E[] newElements)
          
 void addAll(E newElement, E... restOfNewElements)
          
 void addAll(Iterable<? extends E> newElements)
          
<R> ExtensibleCollection<R>
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.

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.

 ExtensibleCollection<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.

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.

 boolean removeAll(Collection<? extends E> oldElements)
          For each element in the given collection, removes the first element from this collection which is equivalent to this element.
 boolean removeAll(E[] oldElements)
          
 boolean removeAll(E oldElement, E... restOfOldElements)
          
 boolean removeAll(Iterable<? extends E> oldElements)
          
 boolean removeIf(UnaryCondition<? super E> discriminator)
          Removes each element of this collection which causes the given discriminator to answer true.
 boolean retainAll(Collection<? extends E> keepers)
          Removes each element of this collection that is not contained in the given collection.
 boolean retainAll(E[] keepers)
          
 boolean retainAll(E keeper, E... restOfKeepers)
          
 boolean retainAll(Iterable<? extends E> keepers)
          
 boolean retainIf(UnaryCondition<? super E> discriminator)
          Removes each element of this collection which causes the given discriminator to answer false.
 ExtensibleCollection<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.

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.

 
Methods inherited from class jaggregate.AbstractCollection
allSatisfy, anySatisfy, detect, includes, inject, isEmpty, occurrencesOf, rehash, toArray, toArray, toBag, toIdentityBag, toIdentitySet, toOrderedCollection, toSet, toSortedCollection, toSortedCollection
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jaggregate.ExtensibleCollection
add, remove
 
Methods inherited from interface jaggregate.Collection
allSatisfy, anySatisfy, detect, forEachDo, includes, inject, isEmpty, occurrencesOf, rehash, size, toArray, toArray, toBag, toIdentityBag, toIdentitySet, toOrderedCollection, toSet, toSortedCollection, toSortedCollection
 

Method Detail

collect

public <R> ExtensibleCollection<R> 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.

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.

Specified by:
collect in interface Collection<E>
Specified by:
collect in interface ExtensibleCollection<E>
Overrides:
collect in class AbstractCollection<E>
Type Parameters:
R - return type of the transformer
Parameters:
transformer - the transformer to evaluate
Returns:
a collection of the transformations

reject

public ExtensibleCollection<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.

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.

Specified by:
reject in interface Collection<E>
Specified by:
reject in interface ExtensibleCollection<E>
Overrides:
reject in class AbstractCollection<E>
Parameters:
discriminator - the discriminator to evaluate
Returns:
a collection of the rejected elements of this collection

select

public ExtensibleCollection<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.

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.

Specified by:
select in interface Collection<E>
Specified by:
select in interface ExtensibleCollection<E>
Overrides:
select in class AbstractCollection<E>
Parameters:
discriminator - the discriminator to evaluate
Returns:
a collection of the selected elements of this collection

addAll

public void addAll(Collection<? extends E> newElements)
Adds each element of the given collection to this collection.

The operation is equivalent to adding each element of newElements to this collection using add with the element as the parameter. The newElements are traversed in the order specified by forEachDo for newElements.

Specified by:
addAll in interface ExtensibleCollection<E>
Parameters:
newElements - the elements to add

addAll

public void addAll(E[] newElements)

Specified by:
addAll in interface ExtensibleCollection<E>
Parameters:
newElements - the elements to add
See Also:
ExtensibleCollection.addAll(Collection)

addAll

public void addAll(E newElement,
                   E... restOfNewElements)

Specified by:
addAll in interface ExtensibleCollection<E>
Parameters:
newElement - first new element to add
restOfNewElements - remainder of the elements to add
See Also:
ExtensibleCollection.addAll(Collection)

addAll

public void addAll(Iterable<? extends E> newElements)

Specified by:
addAll in interface ExtensibleCollection<E>
Parameters:
newElements - the elements to add
See Also:
ExtensibleCollection.addAll(Collection)

removeAll

public boolean removeAll(Collection<? extends E> oldElements)
For each element in the given collection, removes the first element from this collection which is equivalent to this element.

The operation is defined to be equivalent to removing each element of oldElements from this collection using remove with the element as the parameter.

Specified by:
removeAll in interface ExtensibleCollection<E>
Parameters:
oldElements - the elements to remove
Returns:
true if any removal occurred

removeAll

public boolean removeAll(E[] oldElements)

Specified by:
removeAll in interface ExtensibleCollection<E>
Parameters:
oldElements - the elements to remove
Returns:
true if any removal occurred
See Also:
ExtensibleCollection.removeAll(Collection)

removeAll

public boolean removeAll(E oldElement,
                         E... restOfOldElements)

Specified by:
removeAll in interface ExtensibleCollection<E>
Parameters:
oldElement - first element to remove
restOfOldElements - remainder of the elements to remove
Returns:
true if any removal occurred
See Also:
ExtensibleCollection.removeAll(Collection)

removeAll

public boolean removeAll(Iterable<? extends E> oldElements)

Specified by:
removeAll in interface ExtensibleCollection<E>
Parameters:
oldElements - the elements to remove
Returns:
true if any removal occurred
See Also:
ExtensibleCollection.removeAll(Collection)

removeIf

public boolean removeIf(UnaryCondition<? super E> discriminator)
Removes each element of this collection which causes the given discriminator to answer true.

The elements are tested in the same order in which they would be enumerated by forEachDo for this collection.

Specified by:
removeIf in interface ExtensibleCollection<E>
Parameters:
discriminator - the discriminator to evaluate
Returns:
true if any removal occurred

retainAll

public boolean retainAll(Collection<? extends E> keepers)
Removes each element of this collection that is not contained in the given collection.

Note that if the given collection is empty, this method has the effect of "clearing" this collection.

Specified by:
retainAll in interface ExtensibleCollection<E>
Parameters:
keepers - the elements to retain
Returns:
true if any removal occurred

retainAll

public boolean retainAll(E[] keepers)

Specified by:
retainAll in interface ExtensibleCollection<E>
Parameters:
keepers - the elements to retain
Returns:
true if any removal occurred
See Also:
ExtensibleCollection.retainAll(Collection)

retainAll

public boolean retainAll(E keeper,
                         E... restOfKeepers)

Specified by:
retainAll in interface ExtensibleCollection<E>
Parameters:
keeper - first element to retain
restOfKeepers - remainder of the elements to retain
Returns:
true if any removal occurred
See Also:
ExtensibleCollection.retainAll(Collection)

retainAll

public boolean retainAll(Iterable<? extends E> keepers)

Specified by:
retainAll in interface ExtensibleCollection<E>
Parameters:
keepers - the elements to retain
Returns:
true if any removal occurred
See Also:
ExtensibleCollection.retainAll(Collection)

retainIf

public boolean retainIf(UnaryCondition<? super E> discriminator)
Removes each element of this collection which causes the given discriminator to answer false.

The elements are tested in the same order in which they would be enumerated by forEachDo for this collection.

Specified by:
retainIf in interface ExtensibleCollection<E>
Parameters:
discriminator - the discriminator to evaluate
Returns:
true if any removal occurred


© Copyright 2004-2008 Paul R. Holser, Jr. All rights reserved. Licensed under the Academic Free License version 3.0. pholser@alumni.rice.edu