org.norther.tammi.acorn.util
Class OrderedHashMap

java.lang.Object
  extended by java.util.AbstractMap
      extended by org.norther.tammi.acorn.util.ConcurrentAbstractMap
          extended by org.norther.tammi.acorn.util.ConcurrentReadMap
              extended by org.norther.tammi.acorn.util.OrderedHashMap
All Implemented Interfaces:
Serializable, Cloneable, ConcurrentMap, Map, OrderedMap
Direct Known Subclasses:
Configuration

public class OrderedHashMap
extends ConcurrentReadMap
implements OrderedMap

Extends ConcurrentReadMap by implementing the OrderedMap interface. Ordered Sets, Collections and Lists and the corresponding Iterators returned by this implementation support removals but not additions. Values can also be set but not keys.

Author:
Ilkka Priha
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.norther.tammi.acorn.util.ConcurrentAbstractMap
ConcurrentAbstractMap.Entry
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class org.norther.tammi.acorn.util.ConcurrentReadMap
DEFAULT_CAPACITY, MAXIMUM_CAPACITY, MINIMUM_CAPACITY
 
Fields inherited from class org.norther.tammi.acorn.util.ConcurrentAbstractMap
DEFAULT_LOAD_FACTOR
 
Constructor Summary
OrderedHashMap()
          Constructs a new, empty map with a default capacity and load factor.
OrderedHashMap(int capacity)
          Constructs a new, empty map with the specified initial capacity and default load factor.
OrderedHashMap(int capacity, float factor)
          Constructs a new, empty map with the specified initial capacity and the specified load factor.
OrderedHashMap(Map map)
          Constructs a new map with the same mappings as the given map.
 
Method Summary
 boolean add(int index, Object key, Object value)
          Associates the specified value with the specified key to the specified index in this map if not already mapped.
 void clear()
           
 Object clone()
           
 List entryList()
          Returns an ordered list of mapped entries.
 Set entrySet()
          Returns a collection view of the mappings contained in this map.
 Object get(int index)
          Gets the indexed value in this map.
 Map.Entry getEntryAt(int index)
          Gets the indexed entry in this map.
 Object getKeyAt(int index)
          Gets the indexed key in this map.
 int indexOfKey(Object key)
          Returns the index of the specified key, or -1 if not found.
 boolean isModifiable()
          Checks whether this map is modifiable.
 List keyList()
          Returns an ordered list of mapped keys.
 Set keySet()
          Returns a set view of the keys contained in this map.
 Object put(int index, Object key, Object value)
          Associates the specified value with the specified key to the specified index in this map.
 void putAll(Map map)
           
 Object putIfAbsent(int index, Object key, Object value)
          Associates the specified value with the specified key to the specified index in this map if not already mapped.
protected  Object putInternal(int index, Object key, Object value, boolean r)
          Puts the internal value with the specified key to the specified index in this map.
protected  Object putInternal(Object key, Object value, boolean r)
          Puts the internal value mapped to the specified key.
 Object remove(int index)
          Removes the indexed element in this map.
protected  Object removeInternal(Object key, Object value)
          Removes the internal mapping with the optional value.
 Object replace(int index, Object value)
          Replaces the indexed element in this map.
 List valueList()
          Returns an ordered list of mapped values.
 Collection values()
          Returns a collection view of the values contained in this map.
 
Methods inherited from class org.norther.tammi.acorn.util.ConcurrentReadMap
capacity, containsKey, containsValue, getEntry, getInternal, getReadTable, getWriteTable, isEmpty, recordWrite, rehash, replaceInternal, setWriteTable, size
 
Methods inherited from class org.norther.tammi.acorn.util.ConcurrentAbstractMap
add, capacity, contains, elements, get, hash, keys, put, putIfAbsent, remove, remove, replace, replace
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.acorn.util.OrderedMap
add
 
Methods inherited from interface java.util.concurrent.ConcurrentMap
putIfAbsent, remove, replace, replace
 
Methods inherited from interface java.util.Map
containsKey, containsValue, equals, get, hashCode, isEmpty, put, remove, size
 

Constructor Detail

OrderedHashMap

public OrderedHashMap()
Constructs a new, empty map with a default capacity and load factor.


OrderedHashMap

public OrderedHashMap(int capacity)
Constructs a new, empty map with the specified initial capacity and default load factor.

Note that the initial capacity will be rounded to the nearest power of two.

Parameters:
capacity - the initial capacity.
Throws:
IllegalArgumentException - for negative values.

OrderedHashMap

public OrderedHashMap(int capacity,
                      float factor)
Constructs a new, empty map with the specified initial capacity and the specified load factor.

Note that the initial capacity will be rounded to the nearest power of two.

Parameters:
capacity - the initial capacity.
factor - the load factor of the map.
Throws:
IllegalArgumentException - for negative values.

OrderedHashMap

public OrderedHashMap(Map map)
Constructs a new map with the same mappings as the given map. The map is created with a capacity of twice the number of mappings in the given map or 16 (whichever is greater), and a default load factor.

Parameters:
map - the map to copy.
Method Detail

clone

public Object clone()
Overrides:
clone in class ConcurrentReadMap

isModifiable

public boolean isModifiable()
Description copied from interface: OrderedMap
Checks whether this map is modifiable.

Specified by:
isModifiable in interface OrderedMap
Returns:
true for a modifiable map, false otherwise.

indexOfKey

public int indexOfKey(Object key)
Description copied from interface: OrderedMap
Returns the index of the specified key, or -1 if not found.

Specified by:
indexOfKey in interface OrderedMap
Parameters:
key - the key.
Returns:
the index of the key.

getKeyAt

public Object getKeyAt(int index)
Description copied from interface: OrderedMap
Gets the indexed key in this map.

Specified by:
getKeyAt in interface OrderedMap
Parameters:
index - the index.
Returns:
the indexed value.

get

public Object get(int index)
Description copied from interface: OrderedMap
Gets the indexed value in this map.

Specified by:
get in interface OrderedMap
Parameters:
index - the index.
Returns:
the indexed value.

getEntryAt

public Map.Entry getEntryAt(int index)
Description copied from interface: OrderedMap
Gets the indexed entry in this map.

Specified by:
getEntryAt in interface OrderedMap
Parameters:
index - the index.
Returns:
the indexed entry.

put

public Object put(int index,
                  Object key,
                  Object value)
Description copied from interface: OrderedMap
Associates the specified value with the specified key to the specified index in this map. Note that an existing key is not moved.

Specified by:
put in interface OrderedMap
Parameters:
index - the index.
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with the specified key.

putIfAbsent

public Object putIfAbsent(int index,
                          Object key,
                          Object value)
Description copied from interface: OrderedMap
Associates the specified value with the specified key to the specified index in this map if not already mapped.

Specified by:
putIfAbsent in interface OrderedMap
Parameters:
index - the index.
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with the specified key.

add

public boolean add(int index,
                   Object key,
                   Object value)
Description copied from interface: OrderedMap
Associates the specified value with the specified key to the specified index in this map if not already mapped.

Specified by:
add in interface OrderedMap
Parameters:
index - the index.
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
true if added, false otherwise.

replace

public Object replace(int index,
                      Object value)
Description copied from interface: OrderedMap
Replaces the indexed element in this map.

Specified by:
replace in interface OrderedMap
Parameters:
index - the index.
value - the new value.
Returns:
the replaced value.

remove

public Object remove(int index)
Description copied from interface: OrderedMap
Removes the indexed element in this map.

Specified by:
remove in interface OrderedMap
Parameters:
index - the index.
Returns:
the removed value.

keySet

public Set keySet()
Description copied from class: ConcurrentAbstractMap
Returns a set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set supports element removal, which removes the corresponding mapping from this map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Specified by:
keySet in interface Map
Specified by:
keySet in interface OrderedMap
Overrides:
keySet in class ConcurrentAbstractMap
Returns:
a set view of the keys contained in this map.

keyList

public List keyList()
Description copied from interface: OrderedMap
Returns an ordered list of mapped keys.

Specified by:
keyList in interface OrderedMap
Returns:
a list of keys.

values

public Collection values()
Description copied from class: ConcurrentAbstractMap
Returns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. The collection supports element removal, which removes the corresponding mapping from this map, via the Iterator.remove, Collection.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Specified by:
values in interface Map
Specified by:
values in interface OrderedMap
Overrides:
values in class ConcurrentAbstractMap
Returns:
a collection view of the values contained in this map.

valueList

public List valueList()
Description copied from interface: OrderedMap
Returns an ordered list of mapped values.

Specified by:
valueList in interface OrderedMap
Returns:
a list of values.

entrySet

public Set entrySet()
Description copied from class: ConcurrentAbstractMap
Returns a collection view of the mappings contained in this map. Each element in the returned collection is a Map.Entry. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Specified by:
entrySet in interface Map
Specified by:
entrySet in interface OrderedMap
Overrides:
entrySet in class ConcurrentAbstractMap
Returns:
a set view of the mappings contained in this map.

entryList

public List entryList()
Description copied from interface: OrderedMap
Returns an ordered list of mapped entries.

Specified by:
entryList in interface OrderedMap
Returns:
a list of entries.

putAll

public void putAll(Map map)
Specified by:
putAll in interface Map
Overrides:
putAll in class ConcurrentReadMap

clear

public void clear()
Specified by:
clear in interface Map
Overrides:
clear in class ConcurrentReadMap

putInternal

protected Object putInternal(Object key,
                             Object value,
                             boolean r)
Description copied from class: ConcurrentAbstractMap
Puts the internal value mapped to the specified key.

Overrides:
putInternal in class ConcurrentReadMap
Parameters:
key - the key.
value - the value.
r - if true, replace an existing mapping.
Returns:
the previous value or null if not found.

removeInternal

protected Object removeInternal(Object key,
                                Object value)
Description copied from class: ConcurrentAbstractMap
Removes the internal mapping with the optional value.

Overrides:
removeInternal in class ConcurrentReadMap
Parameters:
key - the key.
value - the value.
Returns:
the removed value or null if not found.

putInternal

protected Object putInternal(int index,
                             Object key,
                             Object value,
                             boolean r)
Puts the internal value with the specified key to the specified index in this map.

Parameters:
index - the index.
key - the key.
value - the value.
r - if true, replace an existing mapping.
Returns:
the previous value.
Throws:
IndexOutOfBoundsException - if the index is out of range.


Copyright © 2004 The Norther Organization. All rights reserved.