org.pf.util
Class AssociationList

java.lang.Object
  extended byorg.pf.util.AssociationList
Direct Known Subclasses:
NamedValueList

public class AssociationList
extends java.lang.Object

A container that holds a collection of Association objects. No null values are allowed. Neither for association keys nor for association values.

Version:
1.5
Author:
Manfred Duchrow

Field Summary
static Association[] EMPTY_ASSOCIATION_ARRAY
           
 
Constructor Summary
AssociationList()
          Initialize the new instance with default values.
AssociationList(java.util.Map map)
          Initialize the new instance with values from the given map.
 
Method Summary
 void add(Association association)
          Adds the specified association.
 void add(java.lang.Object key, java.lang.Object value)
          Adds the specified key and value as new association.
 void addAll(Association[] associations)
          Adds all association elements of the given array to the list.
 void addAll(java.util.Map map)
          Add all entries of the specified map as associations
 java.util.Map addAllToMap(java.util.Map map)
          Returns the given map object with all associations added to it.
 java.util.HashMap asHashMap()
          Returns all associations transformed to a HashMap where the association keys became the map keys and the association values became the map values.
 java.util.Hashtable asHashtable()
          Returns all associations transformed to a Hashtable where the association keys became the map keys and the association values became the map values.
 java.util.List asList()
          Returns all associations as list
 Association[] associationArray()
          Returns all associations as an array
 Association[] associationArray(IObjectFilter filter)
          Returns an array of all those elements contained in this list that match the given filter.
 Association associationAt(int index)
          Returns the association at the specified index.
 void clear()
          Removes all association from the list.
 boolean containsKey(java.lang.Object key)
          Returns true if the given key is in the list
 Association findAssociation(java.lang.Object key)
          Returns the association with the given key or null if the key can't be found.
 int indexOf(java.lang.Object key)
          Returns the index of the given key or -1 if the key can't be found.
 boolean isEmpty()
          Returns true if this list has no elements
 java.lang.Object keyAt(int index)
          Returns the key of the association at the specified index.
 java.util.List keys()
          Returns all values that are currently stored (might contain duplicates)
 void processEach(IObjectProcessor associationProcessor)
          Calls the given associationProcessor once for each association in this list.
 void put(Association association)
          Adds the specified association.
 void put(java.lang.Object key, java.lang.Object value)
          Puts the given value under the specified key.
 void putAll(Association[] associations)
          Adds all association elements of the given array to the list.
 void putAll(java.util.Map map)
          Puts all key-value pairs of the given map to the list.
 boolean remove(Association association)
          Removes the given association from this list.
 Association remove(int index)
          Removes the association at the given index.
 void removeAll(java.util.Collection assocCollection)
          Removes all association that are contained in the given collection.
 Association removeKey(java.lang.Object key)
          Removes the association with the given key.
 void setAssociationAt(int index, Association associaction)
          Puts the given association at the specified index.
 int size()
          Returns the number of associations in this list
 java.lang.Object valueAt(int index)
          Returns the value of the association at the specified index.
 java.lang.Object valueAt(java.lang.Object key)
          Returns the value associated with the specified key or null if the key cannot be found.
 java.util.List values()
          Returns all values that are currently stored (might contain dublicates)
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ASSOCIATION_ARRAY

public static final Association[] EMPTY_ASSOCIATION_ARRAY
Constructor Detail

AssociationList

public AssociationList()
Initialize the new instance with default values.


AssociationList

public AssociationList(java.util.Map map)
Initialize the new instance with values from the given map.

Method Detail

clear

public void clear()
Removes all association from the list.


size

public int size()
Returns the number of associations in this list


isEmpty

public boolean isEmpty()
Returns true if this list has no elements


add

public void add(Association association)
Adds the specified association.

Parameters:
association - The association to add (must not be null!)

add

public void add(java.lang.Object key,
                java.lang.Object value)
Adds the specified key and value as new association.

Parameters:
key - The key of the association to add
value - The value of the association to add

addAll

public void addAll(java.util.Map map)
Add all entries of the specified map as associations

Parameters:
map - The map that contains all the key/value pairs to add

addAll

public void addAll(Association[] associations)
Adds all association elements of the given array to the list.

Parameters:
associations - The associations to add

associationArray

public Association[] associationArray()
Returns all associations as an array


associationArray

public Association[] associationArray(IObjectFilter filter)
Returns an array of all those elements contained in this list that match the given filter. Each Association element of this list gets passed to the matches() method of the filter. If the filter is null, all elements will be returned.

Parameters:
filter - The filter that determines which elements to return in the result array
Returns:
Always an array, never null

asList

public java.util.List asList()
Returns all associations as list

Returns:
List

asHashtable

public java.util.Hashtable asHashtable()
Returns all associations transformed to a Hashtable where the association keys became the map keys and the association values became the map values.


asHashMap

public java.util.HashMap asHashMap()
Returns all associations transformed to a HashMap where the association keys became the map keys and the association values became the map values.


addAllToMap

public java.util.Map addAllToMap(java.util.Map map)
Returns the given map object with all associations added to it.

Parameters:
map - A valid map object

processEach

public void processEach(IObjectProcessor associationProcessor)
Calls the given associationProcessor once for each association in this list. Each object that gets passed to processObject() is of type Association.

Parameters:
associationProcessor - The processor to be called for each association

associationAt

public Association associationAt(int index)
Returns the association at the specified index.

Parameters:
index - The index of the Association

setAssociationAt

public void setAssociationAt(int index,
                             Association associaction)
Puts the given association at the specified index.

Parameters:
index - The index of the association to set
associaction - The association to put at the given index
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range

keyAt

public java.lang.Object keyAt(int index)
Returns the key of the association at the specified index.

Parameters:
index - The index of the Association

valueAt

public java.lang.Object valueAt(int index)
Returns the value of the association at the specified index.

Parameters:
index - The index of the Association

valueAt

public java.lang.Object valueAt(java.lang.Object key)
Returns the value associated with the specified key or null if the key cannot be found.

Parameters:
key - The identifier for the desired value

findAssociation

public Association findAssociation(java.lang.Object key)
Returns the association with the given key or null if the key can't be found.

Parameters:
key - The key to identify the association

remove

public boolean remove(Association association)
Removes the given association from this list. Returns true, if the association was found in the list and now removed from it.


remove

public Association remove(int index)
Removes the association at the given index. Returns the removed association.


removeKey

public Association removeKey(java.lang.Object key)
Removes the association with the given key. Returns the removed association or null if not found.


removeAll

public void removeAll(java.util.Collection assocCollection)
Removes all association that are contained in the given collection.


values

public java.util.List values()
Returns all values that are currently stored (might contain dublicates)


keys

public java.util.List keys()
Returns all values that are currently stored (might contain duplicates)


containsKey

public boolean containsKey(java.lang.Object key)
Returns true if the given key is in the list

Parameters:
key - The key to look for

put

public void put(java.lang.Object key,
                java.lang.Object value)
Puts the given value under the specified key. If the key already exists, its associated value will be replaced. Otherwise the new key/value pair will be added at the end of the list.


put

public void put(Association association)
Adds the specified association.

Parameters:
association - The association to add (must not be null!)

putAll

public void putAll(Association[] associations)
Adds all association elements of the given array to the list.

Parameters:
associations - The associations to add

putAll

public void putAll(java.util.Map map)
Puts all key-value pairs of the given map to the list. If elements with the same key already exist then their value will be replaced.

Parameters:
map - The associations to add

indexOf

public int indexOf(java.lang.Object key)
Returns the index of the given key or -1 if the key can't be found.

Parameters:
key - The key to look for