javax.baja.nre.util
Class OrderedHashMap

java.lang.Object
  extended byjavax.baja.nre.util.OrderedHashMap
All Implemented Interfaces:
java.util.Map

public class OrderedHashMap
extends java.lang.Object
implements java.util.Map

OrderedHashMap is a replacement for java.util.LinkedHashMap. See the documentation for LinkedHashMap for a detailed explanation of how OrderedHashMap works.

OrderedHashMap has exactly the same semantics as LinkedHashMap, with the following exceptions:

  1. The collections returned from keySet(), values(), and entrySet() are unmodifiable.
  2. The mappings returned from entrySet() are of class OrderedHashMap.Entry, not Map.Entry.


Nested Class Summary
static interface OrderedHashMap.Entry
          A map entry (key-value pair).
 
Constructor Summary
OrderedHashMap()
          Constructs an empty insertion-ordered map.
OrderedHashMap(boolean accessOrder)
          Constructs an empty map with the specified ordering mode.
OrderedHashMap(int initialCapacity, float loadFactor, boolean accessOrder)
          Constructs an empty OrderedHashMap instance with the specified initial capacity, load factor and ordering mode.
OrderedHashMap(java.util.Map m)
          Constructs an insertion-ordered OrderedHashMap instance with the same mappings as the specified map.
 
Method Summary
 void clear()
          Removes all mappings from this map.
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set entrySet()
           
 java.lang.Object get(java.lang.Object key)
           
 OrderedHashMap.Entry getEldestEntry()
          Get the eldest entry.
 OrderedHashMap.Entry getNewestEntry()
          Get the newest entry.
 boolean isEmpty()
           
 java.util.Set keySet()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the specified value with the specified key in this map.
 void putAll(java.util.Map t)
          Copies all of the mappings from the specified map to this map.
 java.lang.Object remove(java.lang.Object key)
          Removes the mapping for this key from this map if it is present.
protected  boolean removeEldestEntry()
           
 int size()
           
 java.lang.String toString()
           
 java.util.Collection values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

OrderedHashMap

public OrderedHashMap()
Constructs an empty insertion-ordered map.


OrderedHashMap

public OrderedHashMap(boolean accessOrder)
Constructs an empty map with the specified ordering mode.

Parameters:
accessOrder - the ordering mode - true for access-order, false for insertion-order.

OrderedHashMap

public OrderedHashMap(int initialCapacity,
                      float loadFactor,
                      boolean accessOrder)
Constructs an empty OrderedHashMap instance with the specified initial capacity, load factor and ordering mode.

Parameters:
initialCapacity - the initial capacity.
loadFactor - the load factor.
accessOrder - the ordering mode - true for access-order, false for insertion-order.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is negative or the load factor is nonpositive.

OrderedHashMap

public OrderedHashMap(java.util.Map m)
Constructs an insertion-ordered OrderedHashMap instance with the same mappings as the specified map.

Parameters:
m - the map whose mappings are to be placed in this map.
Throws:
java.lang.NullPointerException - if the specified map is null.
Method Detail

size

public int size()
Specified by:
size in interface java.util.Map
Returns:
the number of key-value mappings in this map.

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map
Returns:
true if this map contains no key-value mappings.

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map
Returns:
true if this map contains a mapping for the specified key.

putAll

public void putAll(java.util.Map t)
Copies all of the mappings from the specified map to this map.

Specified by:
putAll in interface java.util.Map

getEldestEntry

public OrderedHashMap.Entry getEldestEntry()
Get the eldest entry.

Throws:
java.util.NoSuchElementException - if the map is empty.

getNewestEntry

public OrderedHashMap.Entry getNewestEntry()
Get the newest entry.

Throws:
java.util.NoSuchElementException - if the map is empty.

removeEldestEntry

protected boolean removeEldestEntry()
Returns:
true if this map should remove its eldest entry.

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map
Returns:
the value to which this map maps the specified key.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Associates the specified value with the specified key in this map.

Specified by:
put in interface java.util.Map
Returns:
previous value associated with specified key, or null if there was no mapping for key.

remove

public java.lang.Object remove(java.lang.Object key)
Removes the mapping for this key from this map if it is present.

Specified by:
remove in interface java.util.Map
Returns:
previous value associated with specified key, or null if there was no mapping for key.

clear

public void clear()
Removes all mappings from this map.

Specified by:
clear in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map
Returns:
true if this map maps one or more keys to the specified value.

keySet

public java.util.Set keySet()
Specified by:
keySet in interface java.util.Map
Returns:
an unmodifiable set view of the keys contained in this map.

values

public java.util.Collection values()
Specified by:
values in interface java.util.Map
Returns:
an unmodifiable collection view of the values contained in this map.

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map
Returns:
an unmodifiable collection view of the mappings contained in this map. The mappings returned are of class OrderedHashMap.Entry.

toString

public java.lang.String toString()
Returns:
a string representation of this map.