LimeWire Collection Component API

org.limewire.collection
Class FixedSizeArrayHashMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by org.limewire.collection.FixedSizeArrayHashMap<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>, RandomAccess, RandomAccessMap<K,V>
Direct Known Subclasses:
RandomOrderHashMap

public class FixedSizeArrayHashMap<K,V>
extends HashMap<K,V>
implements RandomAccessMap<K,V>

A fixed size HashMap that provides indexed access. The replacement policy is FIFO and the iteration order is from newest to oldest. Adding an already existing element will postpone the ejection of that element. It does not support the null element.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
FixedSizeArrayHashMap(int maxCapacity)
          Creates a FixedSizeArrayHashMap with the specified maxmium capacity.
FixedSizeArrayHashMap(int maxCapacity, int initialCapacity)
           
FixedSizeArrayHashMap(int maxCapacity, int initialCapacity, float loadFactor)
           
FixedSizeArrayHashMap(int maxCapacity, Map<? extends K,? extends V> m)
          Creates a new FixedSizeArrayHashMap with the provided maximum capacity and adds elements from the specified Map.
FixedSizeArrayHashMap(Map<? extends K,? extends V> m)
          Creates a new FixedSizeArrayHashMap with the maximum capacity of the size of the provided Map and adds all the elements of that Map.
 
Method Summary
 void clear()
           
 Object clone()
           
 Set<Map.Entry<K,V>> entrySet()
           
 Map.Entry<K,V> getEntryAt(int i)
          Retrieves the entry at index i.
 K getKeyAt(int i)
          Retrieves the key at index i.
 V getValueAt(int i)
          Retrieves the value at index i.
 Set<K> keySet()
          Returns a Set view of the keys contained in this map.
protected  Iterator<Map.Entry<K,V>> newEntryIterator()
           
 V put(K key, V value)
           
 V remove(Object key)
           
 Collection<V> values()
          Returns a collection view of the values contained in this map.
 
Methods inherited from class java.util.HashMap
containsKey, containsValue, get, isEmpty, putAll, size
 
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, containsValue, equals, get, hashCode, isEmpty, putAll, size
 

Constructor Detail

FixedSizeArrayHashMap

public FixedSizeArrayHashMap(int maxCapacity)
Creates a FixedSizeArrayHashMap with the specified maxmium capacity.


FixedSizeArrayHashMap

public FixedSizeArrayHashMap(int maxCapacity,
                             Map<? extends K,? extends V> m)
Creates a new FixedSizeArrayHashMap with the provided maximum capacity and adds elements from the specified Map. If the capacity is less than the size of the Map, elements will get ejected with FIFO policy.


FixedSizeArrayHashMap

public FixedSizeArrayHashMap(Map<? extends K,? extends V> m)
Creates a new FixedSizeArrayHashMap with the maximum capacity of the size of the provided Map and adds all the elements of that Map.


FixedSizeArrayHashMap

public FixedSizeArrayHashMap(int maxCapacity,
                             int initialCapacity,
                             float loadFactor)

FixedSizeArrayHashMap

public FixedSizeArrayHashMap(int maxCapacity,
                             int initialCapacity)
Method Detail

clone

public Object clone()
Overrides:
clone in class HashMap<K,V>

clear

public void clear()
Specified by:
clear in interface Map<K,V>
Overrides:
clear in class HashMap<K,V>

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>
Overrides:
entrySet in class HashMap<K,V>

getValueAt

public V getValueAt(int i)
Description copied from interface: RandomAccessMap
Retrieves the value at index i.

Specified by:
getValueAt in interface RandomAccessMap<K,V>

getKeyAt

public K getKeyAt(int i)
Description copied from interface: RandomAccessMap
Retrieves the key at index i.

Specified by:
getKeyAt in interface RandomAccessMap<K,V>

getEntryAt

public Map.Entry<K,V> getEntryAt(int i)
Description copied from interface: RandomAccessMap
Retrieves the entry at index i.

Specified by:
getEntryAt in interface RandomAccessMap<K,V>

put

public V put(K key,
             V value)
Specified by:
put in interface Map<K,V>
Overrides:
put in class HashMap<K,V>

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>
Overrides:
remove in class HashMap<K,V>

newEntryIterator

protected Iterator<Map.Entry<K,V>> newEntryIterator()

keySet

public Set<K> keySet()
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. (If the map is modified while an iteration over the Set is in progress, the results of the iteration are undefined.) The Set supports element removal, which removes the corresponding entry from the map, via the Iterator.remove, Set.remove, removeAll retainAll, and clear operations. It does not support the add or addAll operations.

This implementation returns a Set that subclasses AbstractSet. The subclass's iterator method returns a "wrapper object" over this map's entrySet() iterator. The size method delegates to this map's size method and the contains method delegates to this map's containsKey method.

The Set is created the first time this method is called, and returned in response to all subsequent calls. No synchronization is performed, so there is a slight chance that multiple calls to this method will not all return the same Set.

Specified by:
keySet in interface Map<K,V>
Overrides:
keySet in class HashMap<K,V>
Returns:
a Set view of the keys contained in this map.

values

public Collection<V> values()
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. (If the map is modified while an iteration over the collection is in progress, the results of the iteration are undefined.) The collection supports element removal, which removes the corresponding entry from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

This implementation returns a collection that subclasses abstract collection. The subclass's iterator method returns a "wrapper object" over this map's entrySet() iterator. The size method delegates to this map's size method and the contains method delegates to this map's containsValue method.

The collection is created the first time this method is called, and returned in response to all subsequent calls. No synchronization is performed, so there is a slight chance that multiple calls to this method will not all return the same Collection.

Specified by:
values in interface Map<K,V>
Overrides:
values in class HashMap<K,V>
Returns:
a collection view of the values contained in this map.

LimeWire Collection Component API

Copyright © 2009 Lime Wire LLC. All Rights Reserved.