net.ontopia.utils
Class CompactHashMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by net.ontopia.utils.CompactHashMap<K,V>
All Implemented Interfaces:
Map<K,V>

public class CompactHashMap<K,V>
extends AbstractMap<K,V>


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>
 
Field Summary
protected static Object deletedObject
          When a key is deleted this object is put into the hashtable in its place, so that other entries with the same key (collisions) further down the hashtable are not lost after we delete an object in the collision chain.
protected  int elements
           
protected  int freecells
           
protected static int INITIAL_SIZE
           
protected  K[] keys
           
protected static double LOAD_FACTOR
           
protected  int modCount
           
protected static Object nullObject
          This object is used to represent null, should clients use that as a key.
protected  V[] values
           
 
Constructor Summary
CompactHashMap()
          Constructs a new, empty set.
CompactHashMap(int size)
          Constructs a new, empty set.
 
Method Summary
 void clear()
          Removes all key/value mappings in the map.
 boolean containsKey(Object k)
          Returns true if this map contains the specified key.
 boolean containsValue(Object v)
          Returns true if this map contains the specified value.
 Set<Map.Entry<K,V>> entrySet()
          Returns a read-only set view of the map's keys.
 V get(Object k)
          Returns the value for the key k, if there is one, and null if there is none.
 boolean isEmpty()
          Returns true if this map contains no mappings.
 Set<K> keySet()
          Returns a virtual read-only set of all the keys in the map.
 V put(K k, V v)
          Adds the specified mapping to this map, returning the old value for the mapping, if there was one.
protected  void rehash(int newCapacity)
          INTERNAL: Rehashes the hashmap to a bigger size.
 V remove(Object k)
          Removes the mapping with key k, if there is one, and returns its value, if there is one, and null if there is none.
 int size()
          Returns the number of key/value mappings in this map.
 Collection<V> values()
          Returns a virtual read-only collection containing all the values in the map.
 
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, putAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INITIAL_SIZE

protected static final int INITIAL_SIZE
See Also:
Constant Field Values

LOAD_FACTOR

protected static final double LOAD_FACTOR
See Also:
Constant Field Values

nullObject

protected static final Object nullObject
This object is used to represent null, should clients use that as a key.


deletedObject

protected static final Object deletedObject
When a key is deleted this object is put into the hashtable in its place, so that other entries with the same key (collisions) further down the hashtable are not lost after we delete an object in the collision chain.


elements

protected int elements

freecells

protected int freecells

keys

protected K[] keys

values

protected V[] values

modCount

protected int modCount
Constructor Detail

CompactHashMap

public CompactHashMap()
Constructs a new, empty set.


CompactHashMap

public CompactHashMap(int size)
Constructs a new, empty set.

Method Detail

size

public int size()
Returns the number of key/value mappings in this map.

Specified by:
size in interface Map<K,V>
Overrides:
size in class AbstractMap<K,V>

isEmpty

public boolean isEmpty()
Returns true if this map contains no mappings.

Specified by:
isEmpty in interface Map<K,V>
Overrides:
isEmpty in class AbstractMap<K,V>

clear

public void clear()
Removes all key/value mappings in the map.

Specified by:
clear in interface Map<K,V>
Overrides:
clear in class AbstractMap<K,V>

containsKey

public boolean containsKey(Object k)
Returns true if this map contains the specified key.

Specified by:
containsKey in interface Map<K,V>
Overrides:
containsKey in class AbstractMap<K,V>

containsValue

public boolean containsValue(Object v)
Returns true if this map contains the specified value.

Specified by:
containsValue in interface Map<K,V>
Overrides:
containsValue in class AbstractMap<K,V>

entrySet

public Set<Map.Entry<K,V>> entrySet()
Returns a read-only set view of the map's keys.

Specified by:
entrySet in interface Map<K,V>
Specified by:
entrySet in class AbstractMap<K,V>

remove

public V remove(Object k)
Removes the mapping with key k, if there is one, and returns its value, if there is one, and null if there is none.

Specified by:
remove in interface Map<K,V>
Overrides:
remove in class AbstractMap<K,V>

put

public V put(K k,
             V v)
Adds the specified mapping to this map, returning the old value for the mapping, if there was one.

Specified by:
put in interface Map<K,V>
Overrides:
put in class AbstractMap<K,V>

rehash

protected void rehash(int newCapacity)
INTERNAL: Rehashes the hashmap to a bigger size.


get

public V get(Object k)
Returns the value for the key k, if there is one, and null if there is none.

Specified by:
get in interface Map<K,V>
Overrides:
get in class AbstractMap<K,V>

values

public Collection<V> values()
Returns a virtual read-only collection containing all the values in the map.

Specified by:
values in interface Map<K,V>
Overrides:
values in class AbstractMap<K,V>

keySet

public Set<K> keySet()
Returns a virtual read-only set of all the keys in the map.

Specified by:
keySet in interface Map<K,V>
Overrides:
keySet in class AbstractMap<K,V>


Copyright © 2000-2012 Ontopia.