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 class
HashedList.EntryComparator<VALUE extends CursorValue<java.lang.String>>
private class
HashedList.HashedListIterator
-
Constructor Summary
Constructors Constructor Description HashedList()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
add(int pos, VALUE reference)
Add an element to the list at a specified position.boolean
add(VALUE e)
boolean
addAll(java.util.Collection<? extends VALUE> c)
void
clear()
boolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection<?> c)
boolean
containsKey(java.lang.Object key)
VALUE
get(int n)
VALUE
get(java.lang.Object key)
(package private) int
indexOf(VALUE entry)
private boolean
internalRemove(int index, VALUE entry)
boolean
isEmpty()
HashedList.HashedListIterator
iterator()
Cursor<java.lang.String,VALUE>
iterator(int n)
HashedList.HashedListIterator
iterator(java.lang.String key)
boolean
remove(int index)
Remove an object from the list giving the object index..boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
boolean
removeKey(java.lang.Object key)
Remove a keyed object from the list.boolean
replaceKey(java.lang.String oldKey, java.lang.String newKey)
Replace the key of a given element.boolean
retainAll(java.util.Collection<?> c)
int
size()
void
sort(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.String
toString()
private static boolean
unkeyedKey(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:
add
in interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
addAll
public boolean addAll(java.util.Collection<? extends VALUE> c)
- Specified by:
addAll
in interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
contains
in interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAll
in interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
containsKey
public boolean containsKey(java.lang.Object key)
- Parameters:
key
- the key to search- Returns:
true
if 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:
isEmpty
in interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
iterator
public HashedList.HashedListIterator iterator()
- Specified by:
iterator
in interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
- Specified by:
iterator
in 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:
remove
in interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAll
in 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:
true
if 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:
retainAll
in interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
size
public int size()
- Specified by:
size
in 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:
toArray
in interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
toArray
public <T> T[] toArray(T[] o)
- Specified by:
toArray
in interfacejava.util.Collection<VALUE extends CursorValue<java.lang.String>>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-