org.pf.util
Class NamedValueList<V>

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

public class NamedValueList<V>
extends AssociationList<java.lang.String,V>

A container that holds a collection of NamedValue objects.

Version:
2.0
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<java.lang.String,V> map)
          Initialize the new instance with values from the given map.
 
Method Summary
 void add(Association<java.lang.String,V> association)
          Adds the specified association only if it is an instance of NamedValue.
 void add(NamedValue<V> namedValue)
          Adds the specified named value.
 void add(java.lang.String name, V value)
          Adds the specified name and value as new NamedValue.
 void addAll(NamedValue<V>... 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<V> 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<V>[] namedValueArray()
          Returns all named values as an array
 NamedValue<V>[] namedValueArray(IObjectFilter filter)
          Returns an array of all those elements contained in this list that match the given filter.
 NamedValue<V> namedValueAt(int index)
          Returns the named value at the specified index.
 java.util.List<java.lang.String> names()
          Returns all names in this list
 NamedValue<V> remove(java.lang.String name)
          Remove the NamedValue identified by the given name.
 void setNamedValueAt(int index, NamedValue<V> namedValue)
          Puts the given named value at the specified index.
 void sort()
          Sorts the elements in this list by name in ascending order.
 void sort(boolean ascending)
          Sorts the elements in this list by name.
 V 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, 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, 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<java.lang.String,V> 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<V> namedValue)
Adds the specified named value.

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

add

public void add(Association<java.lang.String,V> association)
Adds the specified association only if it is an instance of NamedValue.

Overrides:
add in class AssociationList<java.lang.String,V>
Parameters:
association - The association to add (must not be null!)

add

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

Overrides:
add in class AssociationList<java.lang.String,V>
Parameters:
name - The name of the named value to add
value - The value of the named value to add

addAll

public void addAll(NamedValue<V>... namedValues)
Adds all named value elements of the given array to the list.

Parameters:
namedValues - The values to add

namedValueArray

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


namedValueArray

public NamedValue<V>[] 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<V> 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<V> 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<V> 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 elements in this list by name in ascending order.


sort

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

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

valueAt

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

Overrides:
valueAt in class AssociationList<java.lang.String,V>
Parameters:
name - The identifier for the desired value

remove

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


names

public java.util.List<java.lang.String> names()
Returns all names in this list