public class NamedValueList<V> extends AssociationList<java.lang.String,V> implements IReadOnlyNamedValues<V>
Modifier and Type | Field and Description |
---|---|
static NamedValue[] |
EMPTY_NAMED_VALUE_ARRAY |
EMPTY_ASSOCIATION_ARRAY
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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)
|
protected java.lang.Class<? extends NamedValue> |
elementClass()
Returns the class all contained elements must be an instance of
Subclasses usually must override this method.
|
NamedValue<V> |
findNamedValue(java.lang.String name)
Returns the first named value with the specified name or null if none
can be found.
|
java.util.Collection<java.lang.String> |
getNames()
Returns all names (maybe empty but never null).
|
V |
getValue(java.lang.String name)
Returns the value associated with the specified name or null if the name
cannot be found.
|
protected java.lang.Class<java.lang.String> |
keyClass()
Returns the class all contained keys must be an instance of.
|
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<NamedValue<V>> 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
|
protected Association<java.lang.String,V> |
newElement(java.lang.String key,
V value) |
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.
|
addAll, addAll, addAll, addAllToMap, addOrPutAll, asHashMap, asHashtable, asList, associationArray, associationArray, associationAt, basicAdd, clear, collectElements, collUtil, containsKey, findAssociation, findValue, getList, indexOf, isCorrectElementType, isCorrectKeyType, isCorrectValueType, isEmpty, isValidAssociation, keyAt, keys, processEach, put, put, putAll, putAll, remove, remove, removeAll, removeKey, setAssociationAt, setList, size, valueAt, valueClass, values
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isEmpty
public static final NamedValue[] EMPTY_NAMED_VALUE_ARRAY
public NamedValueList()
public NamedValueList(java.util.Map<java.lang.String,V> map)
public void add(NamedValue<V> namedValue)
namedValue
- The named value to add (must not be null!)public void add(Association<java.lang.String,V> association)
add
in class AssociationList<java.lang.String,V>
association
- The association to add (must not be null!)public void add(java.lang.String name, V value)
add
in class AssociationList<java.lang.String,V>
name
- The name of the named value to addvalue
- The value of the named value to addpublic void addAll(NamedValue<V>... namedValues)
namedValues
- The values to addpublic NamedValue<V>[] namedValueArray()
public NamedValue<V>[] namedValueArray(IObjectFilter<NamedValue<V>> filter)
filter
- The filter that determines which elements to return in the result array (may be null).public NamedValue<V> namedValueAt(int index)
index
- The index of the NamedValuepublic void setNamedValueAt(int index, NamedValue<V> namedValue)
index
- The index where to put the namedValuenamedValue
- The named value object to be put at the given indexjava.lang.IndexOutOfBoundsException
- if the index is out of rangepublic java.lang.String nameAt(int index)
index
- The index of the NamedValuepublic NamedValue<V> findNamedValue(java.lang.String name)
name
- The name of the named value to look forpublic boolean containsName(java.lang.String name)
public void sort()
public void sort(boolean ascending)
ascending
- If true, elements will be sorted in ascending order. Otherwise in descending order.public V getValue(java.lang.String name)
getValue
in interface IReadOnlyNamedValues<V>
name
- The identifier for the desired value.public V valueAt(java.lang.String name)
valueAt
in class AssociationList<java.lang.String,V>
name
- The identifier for the desired valuepublic NamedValue<V> remove(java.lang.String name)
public java.util.List<java.lang.String> names()
public java.util.Collection<java.lang.String> getNames()
IReadOnlyNamedValues
getNames
in interface IReadOnlyNamedValues<V>
protected Association<java.lang.String,V> newElement(java.lang.String key, V value)
newElement
in class AssociationList<java.lang.String,V>
protected java.lang.Class<? extends NamedValue> elementClass()
elementClass
in class AssociationList<java.lang.String,V>
protected java.lang.Class<java.lang.String> keyClass()
keyClass
in class AssociationList<java.lang.String,V>