|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectat.spardat.xma.mdl.util.KeyedList
This class realizes a ordered collection consisting of entries (key, value). The keys are Strings. The collection has set semantics, i.e., at most one entry with a particular key is allowed. Nevertheless, the collection is ordered. The order is controlled via positional insertion operations (method add providing an index).
You may view this class as a mix of HashMap and ArrayList, gaining the fast access by key of the HashMap and retaining the order and the ease of indexed access of the ArrayList.
| Constructor Summary | |
KeyedList()
|
|
| Method Summary | |
boolean |
add(int index,
java.lang.String key,
java.lang.Object value)
Inserts the specified element at the specified position in this list. |
boolean |
add(java.lang.String key,
java.lang.Object value)
Appends the specified element to the end of this list. |
void |
clear()
Removes all of the elements from this list. |
java.lang.Object |
clone()
Clones shallow. |
boolean |
containsKey(java.lang.String key)
Returns true if this list contains a element with the specified key. |
java.lang.String |
getKey(int index)
Returns the key for the entry at the provided index. |
java.lang.Object |
getValue(int index)
Returns the value of the entry at the provided index. |
java.lang.Object |
getValue(java.lang.String key)
Returns the value for the provided key or null if this list does not contain an entry with the specified key. |
int |
indexOf(java.lang.String key)
Returns the index of the entry whose key equals the one provided. |
java.lang.String |
remove(int index)
Removes the element at the specified position in this list. |
boolean |
remove(java.lang.String key)
Removes the entry with the provided key. |
boolean |
replace(java.lang.String key,
java.lang.Object value)
Replaces the old value associated with the provided key with a new one. |
int |
size()
Returns the size of this list. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public KeyedList()
| Method Detail |
public boolean add(java.lang.String key,
java.lang.Object value)
key - the key of the element; must not be nullvalue - the value associated with the key
public boolean add(int index,
java.lang.String key,
java.lang.Object value)
index - index at which the specified element is to be inserted.key - the key of the element; must not be nullvalue - the value associated with the key
java.lang.ArrayIndexOutOfBoundsException - if index is out of range
(index < 0 || index > size()).public java.lang.String getKey(int index)
index - index at which to return the key.
java.lang.ArrayIndexOutOfBoundsException - if index out of range.public java.lang.Object getValue(int index)
index - index at which to return the value.
java.lang.IndexOutOfBoundsException - if index out of range.public java.lang.Object getValue(java.lang.String key)
key - the key whose value is to be found.
public int indexOf(java.lang.String key)
This is a time consuming operation of O(n).
key - the key of the entry whose index is wanted.
public void clear()
public boolean containsKey(java.lang.String key)
key - the key to check for existencepublic boolean remove(java.lang.String key)
Removing is a time consuming operation and requires O(n).
key - identifies the entry to be removed
public java.lang.String remove(int index)
Removing is a time consuming operation requiring O(n). Removing from the end of the list requires O(1).
index - the index of the element to removed.
java.lang.IndexOutOfBoundsException - if index out of range (index
< 0 || index >= size()).
public boolean replace(java.lang.String key,
java.lang.Object value)
key - the key whose value is to be replacedvalue - the new value
public int size()
public java.lang.Object clone()
Object.clone()public java.lang.String toString()
Object.toString()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||