jaggregate
Class IdentitySet<E>

java.lang.Object
  extended by jaggregate.AbstractCollection<E>
      extended by jaggregate.AbstractExtensibleCollection<E>
          extended by jaggregate.AbstractSet<E>
              extended by jaggregate.IdentitySet<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 IdentitySet<E>
extends AbstractSet<E>
implements Serializable

A set for which equivalence is defined by ==.

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

Constructor Summary
IdentitySet()
          Creates an empty set.
IdentitySet(Collection<? extends E> elements)
          Creates a set containing the elements in the given collection.
IdentitySet(E... elements)
          Creates a set containing the elements in the given array.
IdentitySet(Iterable<? extends E> elements)
          Creates a set containing the elements in the given iterable object.
 
Method Summary
<R> IdentitySet<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> IdentitySet<T>
emptyIdentitySet()
          Creates an empty set.
static
<T> IdentitySet<T>
identitySetFrom(Collection<? extends T> elements)
          Creates a set containing the elements in the given collection.
static
<T> IdentitySet<T>
identitySetFrom(Iterable<? extends T> elements)
          Creates a set containing the elements given by an iterable object.
static
<T> IdentitySet<T>
identitySetFrom(T[] elements)
          Creates a set containing the elements in the given array.
static
<T> IdentitySet<T>
identitySetWith(T newElement, T... restOfNewElements)
          Creates a set containing the given elements.
 IdentitySet<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.

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

 IdentitySet<E> toIdentitySet()
          Answers an identity 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, toOrderedCollection, toSet, 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, toOrderedCollection, toSet, toSortedCollection, toSortedCollection
 

Constructor Detail

IdentitySet

public IdentitySet()
Creates an empty set.


IdentitySet

public IdentitySet(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

IdentitySet

public IdentitySet(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

IdentitySet

public IdentitySet(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

emptyIdentitySet

public static <T> IdentitySet<T> emptyIdentitySet()
Creates an empty set.

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

identitySetFrom

public static <T> IdentitySet<T> identitySetFrom(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

identitySetFrom

public static <T> IdentitySet<T> identitySetFrom(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

identitySetWith

public static <T> IdentitySet<T> identitySetWith(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)

identitySetFrom

public static <T> IdentitySet<T> identitySetFrom(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

toIdentitySet

public IdentitySet<E> toIdentitySet()
Answers an identity 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:
toIdentitySet in interface Collection<E>
Overrides:
toIdentitySet in class AbstractCollection<E>
Returns:
a set of this collection's elements

collect

public <R> IdentitySet<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 IdentitySet<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 IdentitySet<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