Package nom.tam.util
Class HashedList<VALUE extends CursorValue<java.lang.String>>
- java.lang.Object
-
- nom.tam.util.HashedList<VALUE>
-
- Type Parameters:
VALUE- value of the map
- All Implemented Interfaces:
java.lang.Iterable<VALUE>,java.util.Collection<VALUE>
public class HashedList<VALUE extends CursorValue<java.lang.String>> extends java.lang.Object implements java.util.Collection<VALUE>a ordered hash map implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classHashedList.EntryComparator<VALUE extends CursorValue<java.lang.String>>private classHashedList.HashedListIterator
-
Constructor Summary
Constructors Constructor Description HashedList()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidadd(int pos, VALUE reference)Add an element to the list at a specified position.booleanadd(VALUE e)booleanaddAll(java.util.Collection<? extends VALUE> c)voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)booleancontainsKey(java.lang.Object key)VALUEget(int n)VALUEget(java.lang.Object key)(package private) intindexOf(VALUE entry)private booleaninternalRemove(int index, VALUE entry)booleanisEmpty()HashedList.HashedListIteratoriterator()Cursor<java.lang.String,VALUE>iterator(int n)HashedList.HashedListIteratoriterator(java.lang.String key)booleanremove(int index)Remove an object from the list giving the object index..booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanremoveKey(java.lang.Object key)Remove a keyed object from the list.booleanreplaceKey(java.lang.String oldKey, java.lang.String newKey)Replace the key of a given element.booleanretainAll(java.util.Collection<?> c)intsize()voidsort(java.util.Comparator<java.lang.String> comp)Sort the keys into some desired order.java.lang.Object[]toArray()<T> T[]toArray(T[] o)java.lang.StringtoString()private static booleanunkeyedKey(java.lang.String key)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
ordered
private final java.util.ArrayList<VALUE extends CursorValue<java.lang.String>> ordered
An ordered list of the keys
-
keyed
private final java.util.HashMap<java.lang.String,VALUE extends CursorValue<java.lang.String>> keyed
The key value pairs
-
-
Method Detail
-
add
private void add(int pos, VALUE reference)Add an element to the list at a specified position. If that element was already in the list, it is first removed from the list then added again - if it was removed from a position before the position where it was to be added, that position is decremented by one.- Parameters:
pos- The position at which the specified element is to be added. If pos is bigger than the size of the list the element is put at the end of the list.reference- The element to add to the list.
-
unkeyedKey
private static boolean unkeyedKey(java.lang.String key)
-
add
public boolean add(VALUE e)
- Specified by:
addin interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
addAll
public boolean addAll(java.util.Collection<? extends VALUE> c)
- Specified by:
addAllin interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAllin interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
containsKey
public boolean containsKey(java.lang.Object key)
- Parameters:
key- the key to search- Returns:
trueif the key is included in the list.
-
get
public VALUE get(int n)
- Parameters:
n- the index to get- Returns:
- the n'th entry from the beginning.
-
get
public VALUE get(java.lang.Object key)
- Parameters:
key- the key to search for- Returns:
- the value of a keyed entry. Non-keyed entries may be returned by requesting an iterator.
-
indexOf
int indexOf(VALUE entry)
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
iterator
public HashedList.HashedListIterator iterator()
- Specified by:
iteratorin interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>- Specified by:
iteratorin interfacejava.lang.Iterable<VALUE extends CursorValue<java.lang.String>>- Returns:
- a HashedListIterator over the entire list.
-
iterator
public Cursor<java.lang.String,VALUE> iterator(int n)
- Parameters:
n- the index to start the iterator- Returns:
- an iterator starting with the n'th entry.
-
iterator
public HashedList.HashedListIterator iterator(java.lang.String key)
- Parameters:
key- the key to use as a start point- Returns:
- an iterator over the list starting with the entry with a given key.
-
remove
public boolean remove(int index)
Remove an object from the list giving the object index..- Parameters:
index- the index to remove- Returns:
- true if the index was in range
-
internalRemove
private boolean internalRemove(int index, VALUE entry)
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
removein interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAllin interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
removeKey
public boolean removeKey(java.lang.Object key)
Remove a keyed object from the list. Unkeyed objects can be removed from the list using a HashedListIterator or using the remove(Object) method.- Parameters:
key- the key to remove- Returns:
trueif the key was removed
-
replaceKey
public boolean replaceKey(java.lang.String oldKey, java.lang.String newKey)Replace the key of a given element.- Parameters:
oldKey- The previous key. This key must be present in the hash.newKey- The new key. This key must not be present in the hash.- Returns:
- if the replacement was successful.
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAllin interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
sort
public void sort(java.util.Comparator<java.lang.String> comp)
Sort the keys into some desired order.- Parameters:
comp- the comparator to use for the sorting
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
toArray
public <T> T[] toArray(T[] o)
- Specified by:
toArrayin interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-