|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Dictionary | +--java.util.Hashtable | +--org.apache.turbine.util.SequencedHashtable
A Hashtable
whose keys are sequenced. The
sequencing of the keys allow easy access to the values in the order
which they were added in. This class is thread safe.
Implementing the List interface is not possible due to a instance method name clash between the Collection and the List interface:
Collections | boolean remove(Object o) |
Lists | Object remove(Object o) |
A slightly more complex implementation and interface could involve
the use of a list of Map.Entry
objects.
Inner classes inherited from class java.util.Map |
java.util.Map.Entry |
Field Summary | |
private java.util.LinkedList |
keySequence
The sequence used to keep track of the hash keys. |
private static int |
UNKNOWN_INDEX
Indicator for an unknown index. |
Fields inherited from class java.util.Hashtable |
count, emptyEnumerator, emptyIterator, ENTRIES, entrySet, KEYS, keySet, loadFactor, modCount, serialVersionUID, table, threshold, values, VALUES |
Constructor Summary | |
SequencedHashtable()
Creates a new instance with default storage. |
|
SequencedHashtable(int size)
Creates a new instance with the specified storage. |
Method Summary | |
void |
clear()
Clears all elements. |
java.lang.Object |
clone()
Creates a shallow copy of this object, preserving the internal structure by copying only references. |
protected void |
freshenSequence(java.lang.Object key,
java.lang.Object value)
Freshens the sequence of the element value if
value is not null . |
java.lang.Object |
get(int index)
Returns the key at the specified index. |
java.lang.Object |
getValue(int index)
Returns the value at the specified index. |
int |
indexOf(java.lang.Object key)
Returns the index of the specified key. |
java.util.Iterator |
iterator()
Returns a key iterator. |
int |
lastIndexOf(java.lang.Object key)
Returns the last index of the specified key. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Stores the provided key/value pair. |
void |
putAll(java.util.Map t)
Stores the provided key/value pairs. |
java.lang.Object |
remove(int index)
Removes the element at the specified index. |
private java.lang.Object |
remove(int index,
java.lang.Object key)
Removes the element with the specified key or index. |
java.lang.Object |
remove(java.lang.Object key)
Removes the element with the specified key. |
java.util.List |
sequence()
Returns the ordered sequence of keys. |
java.util.Collection |
values()
Slightly cheaper implementation of values() method. |
Methods inherited from class java.util.Hashtable |
|
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait |
Field Detail |
private static final int UNKNOWN_INDEX
private java.util.LinkedList keySequence
Constructor Detail |
public SequencedHashtable()
public SequencedHashtable(int size)
size
- The storage to allocate up front.Method Detail |
public void clear()
clear
in class java.util.Hashtable
public java.lang.Object clone()
clone()
'd.clone
in class java.util.Hashtable
public java.lang.Object get(int index)
public java.lang.Object getValue(int index)
public int indexOf(java.lang.Object key)
public java.util.Iterator iterator()
public int lastIndexOf(java.lang.Object key)
public java.util.List sequence()
## $table contains a sequenced hashtable #foreach ($key in $table.sequence()) <TR> <TD>Key: $key</TD> </TD>Value: $table.get($key)</TD> </TR> #end
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in class java.util.Hashtable
key
- The key to the provided value.value
- The value to store.null
if none.protected void freshenSequence(java.lang.Object key, java.lang.Object value)
value
if
value
is not null
.key
- The key whose sequence to freshen.value
- The value whose existance to check before removing the old
key sequence.public void putAll(java.util.Map t)
putAll
in class java.util.Hashtable
t
- The key/value pairs to store.public java.lang.Object remove(int index)
index
- The index of the object to remove.key
, or
null
if none existed.public java.lang.Object remove(java.lang.Object key)
remove
in class java.util.Hashtable
key
- The Map
key of the object to remove.key
, or
null
if none existed.private final java.lang.Object remove(int index, java.lang.Object key)
index
- The index of the object to remove, or
UNKNOWN_INDEX
if not known.key
- The Map
key of the object to remove.key
, or
null
if none existed.public java.util.Collection values()
values()
method.values
in class java.util.Hashtable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |