jaggregate
Class Dictionary<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.Dictionary<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 Dictionary<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 equals.

Version:
$Id: Dictionary.java,v 1.5 2008/05/09 03:12:56 pholser Exp $
Author:
Paul Holser
See Also:
Serialized Form

Constructor Summary
Dictionary()
          Creates an empty dictionary.
Dictionary(AbstractDictionary<? extends K,? extends V> associations)
          Creates a dictionary that contains the given associations.
Dictionary(Pair<? extends K,? extends V>... associations)
          Creates a dictionary that contains the given associations.
 
Method Summary
<R> Bag<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> Dictionary<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> Dictionary<T,U>
dictionaryFrom(AbstractDictionary<? extends T,? extends U> associations)
          Creates a dictionary that contains the given associations.
static
<T,U> Dictionary<T,U>
dictionaryFrom(Pair<? extends T,? extends U>[] associations)
          Creates a dictionary that contains the given associations.
static
<T,U> Dictionary<T,U>
dictionaryWith(Pair<? extends T,? extends U> firstAssociation, Pair<? extends T,? extends U>... restOfAssociations)
          Creates a dictionary that contains the given associations.
static
<T,U> Dictionary<T,U>
emptyDictionary()
          Creates an empty dictionary.
 Dictionary<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.

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

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

 Dictionary<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, 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, retainAll, retainIf
 
Methods inherited from interface jaggregate.Collection
allSatisfy, anySatisfy, detect, inject, isEmpty, toArray, toArray, toBag, toIdentityBag, toIdentitySet, toOrderedCollection, toSet, toSortedCollection, toSortedCollection
 

Constructor Detail

Dictionary

public Dictionary()
Creates an empty dictionary.


Dictionary

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

Dictionary

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

emptyDictionary

public static <T,U> Dictionary<T,U> emptyDictionary()
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

dictionaryFrom

public static <T,U> Dictionary<T,U> dictionaryFrom(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

dictionaryFrom

public static <T,U> Dictionary<T,U> dictionaryFrom(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

dictionaryWith

public static <T,U> Dictionary<T,U> dictionaryWith(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> Bag<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> Dictionary<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 Dictionary<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 Dictionary<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 Dictionary<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 Dictionary<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


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