public class AssociationList<K,V>
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
static Association[] |
EMPTY_ASSOCIATION_ARRAY |
Constructor and Description |
---|
AssociationList()
Initialize the new instance with default values.
|
AssociationList(java.util.Map<K,V> map)
Initialize the new instance with values from the given map.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Association<K,V> association)
Adds the specified association.
|
void |
add(K key,
V value)
Adds the specified key and value as new association.
|
void |
addAll(Association<K,V>... associations)
Adds all association elements of the given array to the list.
|
void |
addAll(java.util.Map<K,V> map)
Add all entries of the specified map as associations
|
void |
addAll(java.util.Properties props)
Add all entries of the specified properties as associations
|
java.util.Map<K,V> |
addAllToMap(java.util.Map<K,V> map)
Returns the given map object with all associations added to it.
|
protected void |
addOrPutAll(java.util.Map<?,?> map,
boolean add) |
java.util.HashMap<K,V> |
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<K,V> |
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<Association<K,V>> |
asList()
Returns all associations as list
|
Association<K,V>[] |
associationArray()
Returns all associations as an array
|
Association<K,V>[] |
associationArray(IObjectFilter<Association<K,V>> filter)
Returns an array of all those elements contained in this list that match
the given filter.
|
Association<K,V> |
associationAt(int index)
Returns the association at the specified index.
|
protected void |
basicAdd(Association<K,V> association) |
void |
clear()
Removes all association from the list.
|
protected java.util.Collection<Association<K,V>> |
collectElements(IObjectFilter<Association<K,V>> filter)
Returns an array of all those elements contained in this list that match
the given filter.
|
protected CollectionUtil |
collUtil() |
boolean |
containsKey(K key)
Returns true if the given key is in the list
|
protected java.lang.Class<?> |
elementClass()
Returns the class all contained elements must be an instance of
Subclasses usually must override this method.
|
Association<K,V> |
findAssociation(K key)
Returns the association with the given key or null if the key can't be found.
|
protected V |
findValue(K key) |
protected java.util.List<Association<K,V>> |
getList() |
int |
indexOf(K key)
Returns the index of the given key or -1 if the key can't be found.
|
protected boolean |
isCorrectElementType(Association<K,V> association) |
protected boolean |
isCorrectKeyType(java.lang.Object key) |
protected boolean |
isCorrectValueType(java.lang.Object value) |
boolean |
isEmpty()
Returns true if this list has no elements
|
protected boolean |
isValidAssociation(Association<K,V> association) |
K |
keyAt(int index)
Returns the key of the association at the specified index.
|
protected java.lang.Class<K> |
keyClass()
Returns the class all contained keys must be an instance of
Subclasses usually must override this method.
|
java.util.List<K> |
keys()
Returns all keys that are currently stored (might contain duplicates).
|
protected Association<K,V> |
newElement(K key,
V value) |
void |
processEach(IObjectProcessor<Association<K,V>> associationProcessor)
Calls the given associationProcessor once for each association in this
list.
|
void |
put(Association<K,V> association)
Adds the specified association.
|
void |
put(K key,
V value)
Puts the given value under the specified key.
|
void |
putAll(Association<K,V>[] associations)
Adds all association elements of the given array to the list.
|
void |
putAll(java.util.Map<K,V> map)
Puts all key-value pairs of the given map to the list.
|
boolean |
remove(Association<K,V> association)
Removes the given association from this list.
|
Association<K,V> |
remove(int index)
Removes the association at the given index.
|
void |
removeAll(java.util.Collection<Association<K,V>> assocCollection)
Removes all association that are contained in the given collection.
|
Association<K,V> |
removeKey(K key)
Removes the association with the given key.
|
void |
setAssociationAt(int index,
Association<K,V> associaction)
Puts the given association at the specified index.
|
protected void |
setList(java.util.List<Association<K,V>> newValue) |
int |
size()
Returns the number of associations in this list
|
V |
valueAt(int index)
Returns the value of the association at the specified index.
|
V |
valueAt(K key)
Returns the value associated with the specified key or null if the key
cannot be found.
|
protected java.lang.Class<V> |
valueClass()
Returns the class all contained objects must be an instance of
Subclasses usually must override this method.
|
java.util.List<V> |
values()
Returns all values that are currently stored (might contain duplicates)
|
public static final Association[] EMPTY_ASSOCIATION_ARRAY
public AssociationList()
public void clear()
public int size()
public boolean isEmpty()
public void add(Association<K,V> association)
association
- The association to add (must not be null!)public void add(K key, V value)
key
- The key of the association to addvalue
- The value of the association to addpublic void addAll(java.util.Map<K,V> map)
map
- The map that contains all the key/value pairs to addpublic void addAll(java.util.Properties props)
props
- The map that contains all the key/value pairs to addpublic void addAll(Association<K,V>... associations)
associations
- The associations to addpublic Association<K,V>[] associationArray()
public Association<K,V>[] associationArray(IObjectFilter<Association<K,V>> filter)
filter
- The filter that determines which elements to return in the result arraypublic java.util.List<Association<K,V>> asList()
public java.util.Hashtable<K,V> asHashtable()
public java.util.HashMap<K,V> asHashMap()
public java.util.Map<K,V> addAllToMap(java.util.Map<K,V> map)
map
- A valid map objectpublic void processEach(IObjectProcessor<Association<K,V>> associationProcessor)
associationProcessor
- The processor to be called for each associationpublic Association<K,V> associationAt(int index)
index
- The index of the Associationpublic void setAssociationAt(int index, Association<K,V> associaction)
index
- The index of the association to setassociaction
- The association to put at the given indexjava.lang.IndexOutOfBoundsException
- if the index is out of rangepublic K keyAt(int index)
index
- The index of the Associationpublic V valueAt(int index)
index
- The index of the Associationpublic V valueAt(K key)
key
- The identifier for the desired valuepublic Association<K,V> findAssociation(K key)
key
- The key to identify the associationpublic boolean remove(Association<K,V> association)
public Association<K,V> remove(int index)
public Association<K,V> removeKey(K key)
public void removeAll(java.util.Collection<Association<K,V>> assocCollection)
public java.util.List<V> values()
public java.util.List<K> keys()
public boolean containsKey(K key)
key
- The key to look forpublic void put(K key, V value)
public void put(Association<K,V> association)
association
- The association to add (must not be null!)public void putAll(Association<K,V>[] associations)
associations
- The associations to addpublic void putAll(java.util.Map<K,V> map)
map
- The associations to addpublic int indexOf(K key)
key
- The key to look forprotected boolean isValidAssociation(Association<K,V> association)
protected void basicAdd(Association<K,V> association)
protected void addOrPutAll(java.util.Map<?,?> map, boolean add)
protected boolean isCorrectElementType(Association<K,V> association)
protected boolean isCorrectKeyType(java.lang.Object key)
protected boolean isCorrectValueType(java.lang.Object value)
protected Association<K,V> newElement(K key, V value)
protected java.lang.Class<?> elementClass()
protected java.lang.Class<K> keyClass()
protected java.lang.Class<V> valueClass()
protected java.util.Collection<Association<K,V>> collectElements(IObjectFilter<Association<K,V>> filter)
filter
- The filter that determines which elements to return in the result arrayprotected CollectionUtil collUtil()
protected java.util.List<Association<K,V>> getList()
protected void setList(java.util.List<Association<K,V>> newValue)