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:
java.util.Map<K,V>

public class CompactHashMap<K,V>
extends java.util.AbstractMap<K,V>


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>
 
Field Summary
protected static java.lang.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 java.lang.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(java.lang.Object k)
          Returns true if this map contains the specified key.
 boolean containsValue(java.lang.Object v)
          Returns true if this map contains the specified value.
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
          Returns a read-only set view of the map's keys.
 V get(java.lang.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.
 java.util.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(java.lang.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.
 java.util.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 java.lang.Object nullObject
This object is used to represent null, should clients use that as a key.


deletedObject

protected static final java.lang.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 java.util.Map<K,V>
Overrides:
size in class java.util.AbstractMap<K,V>

isEmpty

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

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

clear

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

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

containsKey

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

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

containsValue

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

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

entrySet

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

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

remove

public V remove(java.lang.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 java.util.Map<K,V>
Overrides:
remove in class java.util.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 java.util.Map<K,V>
Overrides:
put in class java.util.AbstractMap<K,V>

rehash

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


get

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

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

values

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

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

keySet

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

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


Copyright © 2000-2012 Ontopia.