jaggregate
Class IdentityDictionary<K,V>

java.lang.Object
  extended by jaggregate.AbstractCollection<E>
      extended by jaggregate.AbstractExtensibleCollection<Pair<K,V>>
          extended by jaggregate.AbstractDictionaryImpl<K,V>
              extended by jaggregate.IdentityDictionary<K,V>
Type Parameters:
K - a restriction on the types of the keys that may be contained in the dictionary
V - a restriction on the types of the values that may be contained in the dictionary
All Implemented Interfaces:
AbstractDictionary<K,V>, Collection<Pair<K,V>>, ExtensibleCollection<Pair<K,V>>, Serializable

public class IdentityDictionary<K,V>
extends AbstractDictionaryImpl<K,V>
implements Serializable

Represents an unordered collection whose elements can be accessed using an explicitly assigned external key. Key equivalence is defined by ==.

Version:
$Id: IdentityDictionary.java,v 1.5 2008/10/03 19:01:23 pholser Exp $
Author:
Paul Holser
See Also:
Serialized Form

Constructor Summary
IdentityDictionary()
          Creates an empty dictionary.
IdentityDictionary(AbstractDictionary<? extends K,? extends V> associations)
          Creates a dictionary that contains the given associations.
IdentityDictionary(Pair<? extends K,? extends V>... associations)
          Creates a dictionary that contains the given associations.
 
Method Summary
<R> IdentityBag<R>
collect(UnaryFunctor<? super Pair<K,V>,? 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.

<R> IdentityDictionary<K,R>
collectValues(UnaryFunctor<? super V,? extends R> transformer)
          Answers a new dictionary whose keys are this dictionary's keys, and whose corresponding elements are the results of evaluating the given transformer with each corresponding element of this dictionary. For each of this dictionary's keys, a new element is obtained by evaluating transformer with the corresponding element of this dictionary as a parameter.

The elements are traversed in the order specified by forEachDo for this dictionary.

static
<T,U> IdentityDictionary<T,U>
emptyIdentityDictionary()
          Creates an empty dictionary.
static
<T,U> IdentityDictionary<T,U>
identityDictionaryFrom(AbstractDictionary<? extends T,? extends U> associations)
          Creates a dictionary that contains the given associations.
static
<T,U> IdentityDictionary<T,U>
identityDictionaryFrom(Pair<? extends T,? extends U>[] associations)
          Creates a dictionary that contains the given associations.
static
<T,U> IdentityDictionary<T,U>
identityDictionaryWith(Pair<? extends T,? extends U> firstAssociation, Pair<? extends T,? extends U>... restOfAssociations)
          Creates a dictionary that contains the given associations.
 IdentityDictionary<K,V> reject(UnaryCondition<? super Pair<K,V>> 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.

 IdentityDictionary<K,V> rejectValues(UnaryCondition<? super V> discriminator)
          Answers a new dictionary which excludes the elements in this dictionary that cause the given discriminator to answer true.

For each of this dictionary's keys, discriminator is evaluated with the corresponding element as the argument. If the element causes discriminator to answer false, the key is added to the answer with the element as its corresponding value.

 boolean retainAll(Collection<? extends Pair<K,V>> 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.

 IdentityDictionary<K,V> select(UnaryCondition<? super Pair<K,V>> 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.

 IdentityDictionary<K,V> selectValues(UnaryCondition<? super V> discriminator)
          Answers a new dictionary which contains the elements in this dictionary whose keys cause the given discriminator to answer true.

For each of this dictionary's keys, discriminator is evaluated with the corresponding element as the argument. If the element causes discriminator to answer true, the key is added to the answer with the element as its corresponding value.

 
Methods inherited from class jaggregate.AbstractDictionaryImpl
add, at, equals, forEachDo, hashCode, includes, includesKey, keyAt, keys, keysAndValuesDo, keysDo, occurrencesOf, putAll, putAt, rehash, remove, removeAllKeys, removeAllKeys, removeAllKeys, removeAllKeys, removeIfKey, removeIfValue, removeKey, retainAllKeys, retainAllKeys, retainAllKeys, retainAllKeys, retainIfKey, retainIfValue, size, toString, values
 
Methods inherited from class jaggregate.AbstractExtensibleCollection
addAll, addAll, addAll, addAll, removeAll, removeAll, removeAll, removeAll, removeIf, retainAll, retainAll, retainAll, retainIf
 
Methods inherited from class jaggregate.AbstractCollection
allSatisfy, anySatisfy, detect, inject, isEmpty, toArray, toArray, toBag, toIdentityBag, toIdentitySet, toOrderedCollection, toSet, toSortedCollection, toSortedCollection
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jaggregate.ExtensibleCollection
addAll, addAll, addAll, addAll, removeAll, removeAll, removeAll, removeAll, removeIf, retainAll, retainAll, retainAll, retainIf
 
Methods inherited from interface jaggregate.Collection
allSatisfy, anySatisfy, detect, inject, isEmpty, toArray, toArray, toBag, toIdentityBag, toIdentitySet, toOrderedCollection, toSet, toSortedCollection, toSortedCollection
 

Constructor Detail

IdentityDictionary

public IdentityDictionary()
Creates an empty dictionary.


IdentityDictionary

public IdentityDictionary(AbstractDictionary<? extends K,? extends V> associations)
Creates a dictionary that contains the given associations.

Parameters:
associations - the associations to add to the new dictionary
Throws:
NullPointerException - if associations is null

IdentityDictionary

public IdentityDictionary(Pair<? extends K,? extends V>... associations)
Creates a dictionary that contains the given associations.

Parameters:
associations - the associations to add to the new dictionary
Throws:
NullPointerException - if associations is null, or if any of the elements of associations is null
Method Detail

emptyIdentityDictionary

public static <T,U> IdentityDictionary<T,U> emptyIdentityDictionary()
Creates an empty dictionary.

Type Parameters:
T - the type of keys allowed in the new dictionary
U - the type of values allowed in the new dictionary
Returns:
a new empty dictionary

identityDictionaryFrom

public static <T,U> IdentityDictionary<T,U> identityDictionaryFrom(AbstractDictionary<? extends T,? extends U> associations)
Creates a dictionary that contains the given associations.

Type Parameters:
T - the type of keys allowed in the new dictionary
U - the type of values allowed in the new dictionary
Parameters:
associations - the associations to add to the new dictionary
Returns:
the new dictionary
Throws:
NullPointerException - if associations is null

identityDictionaryFrom

public static <T,U> IdentityDictionary<T,U> identityDictionaryFrom(Pair<? extends T,? extends U>[] associations)
Creates a dictionary that contains the given associations.

Type Parameters:
T - the type of keys allowed in the new dictionary
U - the type of values allowed in the new dictionary
Parameters:
associations - the associations to add to the new dictionary
Returns:
the new dictionary
Throws:
NullPointerException - if associations is null, or if any of the elements of associations is null

identityDictionaryWith

public static <T,U> IdentityDictionary<T,U> identityDictionaryWith(Pair<? extends T,? extends U> firstAssociation,
                                                                   Pair<? extends T,? extends U>... restOfAssociations)
Creates a dictionary that contains the given associations.

Type Parameters:
T - the type of keys allowed in the new dictionary
U - the type of values allowed in the new dictionary
Parameters:
firstAssociation - an association to add to the new dictionary
restOfAssociations - other associations to add to the new dictionary
Returns:
the new dictionary
Throws:
NullPointerException - if firstAssociation is null, associations is null, or if any of the elements of associations is null

collect

public <R> IdentityBag<R> collect(UnaryFunctor<? super Pair<K,V>,? 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 AbstractDictionary<K,V>
Specified by:
collect in interface Collection<Pair<K,V>>
Specified by:
collect in interface ExtensibleCollection<Pair<K,V>>
Overrides:
collect in class AbstractDictionaryImpl<K,V>
Type Parameters:
R - return type of the transformer
Parameters:
transformer - the transformer to evaluate
Returns:
a collection of the transformations

collectValues

public <R> IdentityDictionary<K,R> collectValues(UnaryFunctor<? super V,? extends R> transformer)
Answers a new dictionary whose keys are this dictionary's keys, and whose corresponding elements are the results of evaluating the given transformer with each corresponding element of this dictionary. For each of this dictionary's keys, a new element is obtained by evaluating transformer with the corresponding element of this dictionary as a parameter.

The elements are traversed in the order specified by forEachDo for this dictionary.

Specified by:
collectValues in interface AbstractDictionary<K,V>
Overrides:
collectValues in class AbstractDictionaryImpl<K,V>
Type Parameters:
R - return type of the transformer
Parameters:
transformer - the transformer to evaluate
Returns:
the results of evaluating transformer with the elements of this dictionary

reject

public IdentityDictionary<K,V> reject(UnaryCondition<? super Pair<K,V>> 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 AbstractDictionary<K,V>
Specified by:
reject in interface Collection<Pair<K,V>>
Specified by:
reject in interface ExtensibleCollection<Pair<K,V>>
Overrides:
reject in class AbstractDictionaryImpl<K,V>
Parameters:
discriminator - the discriminator to evaluate
Returns:
a collection of the rejected elements of this collection

rejectValues

public IdentityDictionary<K,V> rejectValues(UnaryCondition<? super V> discriminator)
Answers a new dictionary which excludes the elements in this dictionary that cause the given discriminator to answer true.

For each of this dictionary's keys, discriminator is evaluated with the corresponding element as the argument. If the element causes discriminator to answer false, the key is added to the answer with the element as its corresponding value.

Specified by:
rejectValues in interface AbstractDictionary<K,V>
Overrides:
rejectValues in class AbstractDictionaryImpl<K,V>
Parameters:
discriminator - the discriminator to evaluate
Returns:
a dictionary of rejects

select

public IdentityDictionary<K,V> select(UnaryCondition<? super Pair<K,V>> 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 AbstractDictionary<K,V>
Specified by:
select in interface Collection<Pair<K,V>>
Specified by:
select in interface ExtensibleCollection<Pair<K,V>>
Overrides:
select in class AbstractDictionaryImpl<K,V>
Parameters:
discriminator - the discriminator to evaluate
Returns:
a collection of the selected elements of this collection

selectValues

public IdentityDictionary<K,V> selectValues(UnaryCondition<? super V> discriminator)
Answers a new dictionary which contains the elements in this dictionary whose keys cause the given discriminator to answer true.

For each of this dictionary's keys, discriminator is evaluated with the corresponding element as the argument. If the element causes discriminator to answer true, the key is added to the answer with the element as its corresponding value.

Specified by:
selectValues in interface AbstractDictionary<K,V>
Overrides:
selectValues in class AbstractDictionaryImpl<K,V>
Parameters:
discriminator - the discriminator to evaluate
Returns:
a dictionary of matches

retainAll

public boolean retainAll(Collection<? extends Pair<K,V>> 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<Pair<K,V>>
Overrides:
retainAll in class AbstractExtensibleCollection<Pair<K,V>>
Parameters:
keepers - the elements to retain
Returns:
true if any removal occurred
Throws:
UnsupportedOperationException - since it makes no sense -- identities of pairs?


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