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:
java.io.Serializable, java.lang.Cloneable, java.util.Map<K,V>, java.util.RandomAccess, RandomAccessMap<K,V>
Direct Known Subclasses:
RandomOrderHashMap

public class FixedSizeArrayHashMap<K,V>
extends java.util.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
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
FixedSizeArrayHashMap(int maxCapacity)
          Creates a FixedSizeArrayHashMap with the specified maximum capacity.
FixedSizeArrayHashMap(int maxCapacity, int initialCapacity)
           
FixedSizeArrayHashMap(int maxCapacity, int initialCapacity, float loadFactor)
           
FixedSizeArrayHashMap(int maxCapacity, java.util.Map<? extends K,? extends V> m)
          Creates a new FixedSizeArrayHashMap with the provided maximum capacity and adds elements from the specified Map.
FixedSizeArrayHashMap(java.util.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()
           
 java.lang.Object clone()
           
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
           
 java.util.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.
 java.util.Set<K> keySet()
          Returns a Set view of the keys contained in this map.
protected  java.util.Iterator<java.util.Map.Entry<K,V>> newEntryIterator()
           
 V put(K key, V value)
           
 V remove(java.lang.Object key)
           
 java.util.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 maximum capacity.


FixedSizeArrayHashMap

public FixedSizeArrayHashMap(int maxCapacity,
                             java.util.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(java.util.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 java.lang.Object clone()
Overrides:
clone in class java.util.HashMap<K,V>

clear

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

entrySet

public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface java.util.Map<K,V>
Overrides:
entrySet in class java.util.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 java.util.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 java.util.Map<K,V>
Overrides:
put in class java.util.HashMap<K,V>

remove

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

newEntryIterator

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

keySet

public java.util.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 java.util.Map<K,V>
Overrides:
keySet in class java.util.HashMap<K,V>
Returns:
a Set view of the keys contained in this map.

values

public java.util.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 java.util.Map<K,V>
Overrides:
values in class java.util.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.