jaggregate
Class Set<E>

java.lang.Object
  extended by jaggregate.AbstractCollection<E>
      extended by jaggregate.AbstractExtensibleCollection<E>
          extended by jaggregate.AbstractSet<E>
              extended by jaggregate.Set<E>
Type Parameters:
E - a restriction on the types of elements that may be included in the set
All Implemented Interfaces:
Collection<E>, ExtensibleCollection<E>, Serializable

public class Set<E>
extends AbstractSet<E>
implements Serializable

A set for which equivalence is defined by equals.

Version:
$Id: Set.java,v 1.4 2008/05/07 06:00:49 pholser Exp $
Author:
Paul Holser
See Also:
Serialized Form

Constructor Summary
Set()
          Creates an empty set.
Set(Collection<? extends E> elements)
          Creates a set containing the elements in the given collection.
Set(E... elements)
          Creates a set containing the elements in the given array.
Set(Iterable<? extends E> elements)
          Creates a set containing the elements in the given iterable object.
 
Method Summary
<R> Set<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.

static
<T> Set<T>
emptySet()
          Creates an empty set.
 Set<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.

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

static
<T> Set<T>
setFrom(Collection<? extends T> elements)
          Creates a set containing the elements in the given collection.
static
<T> Set<T>
setFrom(Iterable<? extends T> elements)
          Creates a set containing the elements given by an iterable object.
static
<T> Set<T>
setFrom(T[] elements)
          Creates a set containing the elements in the given array.
static
<T> Set<T>
setWith(T newElement, T... restOfNewElements)
          Creates a set containing the given elements.
 Set<E> toSet()
          Answers a set with the same elements as this collection. Since sets do not store duplicate elements, the result may have fewer elements than this collection.

Answers self.

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

Constructor Detail

Set

public Set()
Creates an empty set.


Set

public Set(Collection<? extends E> elements)
Creates a set containing the elements in the given collection.

Parameters:
elements - elements to add to the new set
Throws:
NullPointerException - if elements is null

Set

public Set(E... elements)
Creates a set containing the elements in the given array.

Parameters:
elements - elements to add to the new set
Throws:
NullPointerException - if elements is null

Set

public Set(Iterable<? extends E> elements)
Creates a set containing the elements in the given iterable object.

Parameters:
elements - elements to add to the new set
Throws:
NullPointerException - if elements is null
Method Detail

emptySet

public static <T> Set<T> emptySet()
Creates an empty set.

Type Parameters:
T - the type of elements allowed in the new set
Returns:
a new empty set

setFrom

public static <T> Set<T> setFrom(Collection<? extends T> elements)
Creates a set containing the elements in the given collection.

Type Parameters:
T - the type of elements allowed in the new set
Parameters:
elements - elements to add to the new set
Returns:
the new set
Throws:
NullPointerException - if elements is null

setFrom

public static <T> Set<T> setFrom(T[] elements)
Creates a set containing the elements in the given array.

Type Parameters:
T - the type of elements allowed in the new set
Parameters:
elements - elements to add to the new set
Returns:
the new set
Throws:
NullPointerException - if elements is null

setWith

public static <T> Set<T> setWith(T newElement,
                                 T... restOfNewElements)
Creates a set containing the given elements.

Type Parameters:
T - the type of elements allowed in the new set
Parameters:
newElement - first new element to add
restOfNewElements - remainder of the elements to add
Returns:
the new set
Throws:
NullPointerException - if restOfNewElements is null
IllegalArgumentException - if any of the new elements is found to violate restrictions on the characteristics of valid elements
See Also:
AbstractExtensibleCollection.addAll(Collection)

setFrom

public static <T> Set<T> setFrom(Iterable<? extends T> elements)
Creates a set containing the elements given by an iterable object.

Type Parameters:
T - the type of elements allowed in the new set
Parameters:
elements - elements to add to the new set
Returns:
the new set
Throws:
NullPointerException - if elements is null

toSet

public Set<E> toSet()
Answers a set with the same elements as this collection. Since sets do not store duplicate elements, the result may have fewer elements than this collection.

Answers self.

Specified by:
toSet in interface Collection<E>
Overrides:
toSet in class AbstractCollection<E>
Returns:
a set of this collection's elements

collect

public <R> Set<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 AbstractSet<E>
Type Parameters:
R - return type of the transformer
Parameters:
transformer - the transformer to evaluate
Returns:
a set of results

reject

public Set<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 AbstractSet<E>
Parameters:
discriminator - the discriminator to evaluate
Returns:
a set of rejects

select

public Set<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 AbstractSet<E>
Parameters:
discriminator - the discriminator to evaluate
Returns:
a set of selections


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