gov.nasa.worldwind.util
Class BoundedHashMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
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
|
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. |
| Methods inherited from interface java.util.Map |
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
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
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.
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.
|
|