org.pf.util
Class NamedValueList

java.lang.Object
  extended by org.pf.util.AssociationList
      extended by org.pf.util.NamedValueList
Direct Known Subclasses:
NamedTextList, TextContainerList

public class NamedValueList
extends AssociationList

A container that holds a collection of NamedValue objects.

Version:
1.4
Author:
Manfred Duchrow

Field Summary
static NamedValue[] EMPTY_NAMED_VALUE_ARRAY
           
 
Fields inherited from class org.pf.util.AssociationList
EMPTY_ASSOCIATION_ARRAY
 
Constructor Summary
NamedValueList()
          Initialize the new instance with default values.
NamedValueList(java.util.Map map)
          Initialize the new instance with values from the given map.
 
Method Summary
 void add(Association association)
          Adds the specified association only if it is an instance of NamedValue.
 void add(NamedValue namedValue)
          Adds the specified named value.
 void add(java.lang.Object key, java.lang.Object value)
          Adds the specified key and value as new association.
 void add(java.lang.String name, java.lang.Object value)
          Adds the specified name and value as new NamedValue.
 void addAll(NamedValue[] namedValues)
          Adds all named value elements of the given array to the list.
 boolean containsName(java.lang.String name)
          Returns true if this list contains an entry with the given name (case-sensitive)
 NamedValue findNamedValue(java.lang.String name)
          Returns the first named value with the specified name or null if none can be found.
 java.lang.String nameAt(int index)
          Returns the name (key) of the named value at the specified index.
 NamedValue[] namedValueArray()
          Returns all named values as an array
 NamedValue[] namedValueArray(IObjectFilter filter)
          Returns an array of all those elements contained in this list that match the given filter.
 NamedValue namedValueAt(int index)
          Returns the named value at the specified index.
 java.util.List names()
          Returns all names in this list
 NamedValue remove(java.lang.String name)
          Remove the NamedValue identified by the given name.
 void setNamedValueAt(int index, NamedValue namedValue)
          Puts the given named value at the specified index.
 void sort()
          Sorts the elments in this list by name in ascending order.
 void sort(boolean ascending)
          Sorts the elments in this list by name.
 java.lang.Object valueAt(java.lang.String name)
          Returns the value associated with the specified name or null if the name cannot be found.
 
Methods inherited from class org.pf.util.AssociationList
addAll, addAll, addAllToMap, asHashMap, asHashtable, asList, associationArray, associationArray, associationAt, clear, containsKey, findAssociation, indexOf, isEmpty, keyAt, keys, processEach, put, put, putAll, putAll, remove, remove, removeAll, removeKey, setAssociationAt, size, valueAt, valueAt, values
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_NAMED_VALUE_ARRAY

public static final NamedValue[] EMPTY_NAMED_VALUE_ARRAY
Constructor Detail

NamedValueList

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


NamedValueList

public NamedValueList(java.util.Map map)
Initialize the new instance with values from the given map. All entries where the key is not a String will be skipped.

Method Detail

add

public void add(NamedValue namedValue)
Adds the specified named value.

Parameters:
namedValue - The named value to add (must not be null!)

add

public void add(Association association)
Adds the specified association only if it is an instance of NamedValue.

Overrides:
add in class AssociationList
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.

Overrides:
add in class AssociationList
Parameters:
key - The key of the association to add
value - The value of the association to add

add

public void add(java.lang.String name,
                java.lang.Object value)
Adds the specified name and value as new NamedValue.

Parameters:
name - The name of the named value to add
value - The value of the named value to add

addAll

public void addAll(NamedValue[] namedValues)
Adds all named value elements of the given array to the list.

Parameters:
namedValues - The values to add

namedValueArray

public NamedValue[] namedValueArray()
Returns all named values as an array


namedValueArray

public NamedValue[] namedValueArray(IObjectFilter filter)
Returns an array of all those elements contained in this list that match the given filter. Each NamedValue 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

namedValueAt

public NamedValue namedValueAt(int index)
Returns the named value at the specified index.

Parameters:
index - The index of the NamedValue

setNamedValueAt

public void setNamedValueAt(int index,
                            NamedValue namedValue)
Puts the given named value at the specified index.

Parameters:
index - The index where to put the namedValue
namedValue - The named value object to be put at the given index
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range

nameAt

public java.lang.String nameAt(int index)
Returns the name (key) of the named value at the specified index.

Parameters:
index - The index of the NamedValue

findNamedValue

public NamedValue findNamedValue(java.lang.String name)
Returns the first named value with the specified name or null if none can be found.

Parameters:
name - The name of the named value to look for

containsName

public boolean containsName(java.lang.String name)
Returns true if this list contains an entry with the given name (case-sensitive)


sort

public void sort()
Sorts the elments in this list by name in ascending order.


sort

public void sort(boolean ascending)
Sorts the elments in this list by name.

Parameters:
ascending - If true, elements will be sorted in ascending order. Otherwise in descending order.

valueAt

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

Parameters:
name - The identifier for the desired value

remove

public NamedValue remove(java.lang.String name)
Remove the NamedValue identified by the given name.


names

public java.util.List names()
Returns all names in this list