NASA World Wind

gov.nasa.worldwind.util
Class BoundedHashMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap<K,V>
              extended by gov.nasa.worldwind.util.BoundedHashMap<K,V>
Type Parameters:
K - The map key type.
V - The map value type.
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>

public class BoundedHashMap<K,V>
extends LinkedHashMap<K,V>

BoundedHashMap is a map with a fixed capacity. When the map's size exceeds its capacity, it automatically removes elements until its size is equal to its capacity.

BoundedHashMap can operate in two ordering modes: insertion order and access order. The mode specified which entries are automatically removed when the map is over capacity. In insertion order mode the map removes the eldest entry (the first entry added). In access order mode, the map automatically removes the least recently used entry.

See Also:
Serialized Form

Field Summary
protected static int DEFAULT_CAPACITY
           
protected static float DEFAULT_LOAD_FACTOR
           
 
Constructor Summary
BoundedHashMap()
          Creates a BoundedHashMap with a capacity of 16, in insertion order mode.
BoundedHashMap(int capacity)
          Creates a BoundedHashMap with a specified maximum capacity, in insertion order mode.
BoundedHashMap(int capacity, boolean accessOrder)
          Creates a BoundedHashMap with a specified maximum capacity and ordering mode.
 
Method Summary
 int getCapacity()
          Returns the maximum number of entries in the map.
protected static int getInitialCapacity(int capacity, float loadFactor)
           
protected  boolean removeEldestEntry(Map.Entry<K,V> eldest)
           
protected  void removeOverCapacityEntries()
          Removes the first n entries in the map, where n is the number of entries in the map beyond its capacity.
 void setCapacity(int capacity)
          Sets the maximum number of entries in the map.
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, get
 
Methods inherited from class java.util.HashMap
clone, containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values
 
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 java.util.Map
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Field Detail

DEFAULT_CAPACITY

protected static final int DEFAULT_CAPACITY
See Also:
Constant Field Values

DEFAULT_LOAD_FACTOR

protected static final float DEFAULT_LOAD_FACTOR
See Also:
Constant Field Values
Constructor Detail

BoundedHashMap

public BoundedHashMap()
Creates a BoundedHashMap with a capacity of 16, in insertion order mode.


BoundedHashMap

public BoundedHashMap(int capacity)
Creates a BoundedHashMap with a specified maximum capacity, in insertion order mode.

Parameters:
capacity - the maximum number of entries in the map.

BoundedHashMap

public BoundedHashMap(int capacity,
                      boolean accessOrder)
Creates a BoundedHashMap with a specified maximum capacity and ordering mode.

Parameters:
capacity - the maximum number of entries in the map.
accessOrder - the ordering mode: true specifies access order, false specifies insertion order.
Method Detail

getCapacity

public int getCapacity()
Returns the maximum number of entries in the map.

Returns:
maximum number of entries in the map.

getInitialCapacity

protected static int getInitialCapacity(int capacity,
                                        float loadFactor)

removeEldestEntry

protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
Overrides:
removeEldestEntry in class LinkedHashMap<K,V>

removeOverCapacityEntries

protected void removeOverCapacityEntries()
Removes the first n entries in the map, where n is the number of entries in the map beyond its capacity. Note that the entry set and the corresponding iterator are backed by the map itself, so changes to an entry iterator correspond to changes in the map. We use the iterator's remove() method because we're removing elements from the entry set as we iterate over them.


setCapacity

public void setCapacity(int capacity)
Sets the maximum number of entries in the map. If the new capacity is less than the map's current size, this automatically removes entries until the map's size is equal to its capacity.

Parameters:
capacity - maximum number of enties in the map.

NASA World Wind

Hosted by docs.bugaco.com