com.sun.jdo.spi.persistence.utility
Class BucketizedHashtable

java.lang.Object
  extended by com.sun.jdo.spi.persistence.utility.BucketizedHashtable
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map

public class BucketizedHashtable
extends java.lang.Object
implements java.lang.Cloneable, java.util.Map, java.io.Serializable

This class implements bucketize hashtable, which subdivide the key collection stored into several hashtables (buckets) of smaller size. This will reduce the contention of hashtable.

Author:
Shing Wai Chan
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
BucketizedHashtable()
          Constructs a new, empty BucketizedHashtable with the default bucket size 11, default initial capacity (11 * bucketSize) and default load factor 0.75.
BucketizedHashtable(int bucketSize)
          Constructs a new, empty BucketizedHashtable with the specified bucket size, default initial capacity (11 * bucketSize) and default load factor 0.75.
BucketizedHashtable(int bucketSize, int initialCapacity)
          Constructs a new, empty BucketizedHashtable with the specified bucket size, initial capacity and default load factor 0.75.
BucketizedHashtable(int bucketSize, int initialCapacity, float loadFactor)
          Constructs a new, empty BucketizedHashtable with the specified bucket size, initial capacity and load factor.
 
Method Summary
 void clear()
          Clears this BucketizedHashtable so that it contains no key.
 java.lang.Object clone()
          Creates and returns a shallow copy of this object.
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set entrySet()
          The return set is backed by the map, so changes to the map are reflected in the set, and vice-versa.
 boolean equals(java.lang.Object o)
          Compares the specified object with this map for equality.
 java.lang.Object get(java.lang.Object key)
           
 int hashCode()
           
 boolean isEmpty()
           
 java.util.Set keySet()
          The return set is backed by the map, so changes to the map are reflected in the set, and vice-versa.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Maps the specified key to the specified value in this hashtable.
 void putAll(java.util.Map t)
           
 java.lang.Object remove(java.lang.Object key)
          Remove the key and its corresponding value.
 int size()
           
 java.lang.String toString()
           
 java.util.Collection values()
          The return collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BucketizedHashtable

public BucketizedHashtable(int bucketSize,
                           int initialCapacity,
                           float loadFactor)
Constructs a new, empty BucketizedHashtable with the specified bucket size, initial capacity and load factor.

Parameters:
bucketSize - the number of buckets used for hashing
initialCapacity - the initial capacity of BucketizedHashtable
loadFactor - the load factor of hashtable

BucketizedHashtable

public BucketizedHashtable(int bucketSize,
                           int initialCapacity)
Constructs a new, empty BucketizedHashtable with the specified bucket size, initial capacity and default load factor 0.75.

Parameters:
bucketSize - the number of buckets used for hashing
initialCapacity - the initial capacity of hashtable

BucketizedHashtable

public BucketizedHashtable(int bucketSize)
Constructs a new, empty BucketizedHashtable with the specified bucket size, default initial capacity (11 * bucketSize) and default load factor 0.75.

Parameters:
bucketSize - the number of buckets used for hashing

BucketizedHashtable

public BucketizedHashtable()
Constructs a new, empty BucketizedHashtable with the default bucket size 11, default initial capacity (11 * bucketSize) and default load factor 0.75.

Method Detail

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map
Parameters:
key - a key in the hashtable
Returns:
the value to which the specified key is mapped.

remove

public java.lang.Object remove(java.lang.Object key)
Remove the key and its corresponding value.

Specified by:
remove in interface java.util.Map
Parameters:
key - the key that needs to be removed
Returns:
the value to which the key had been mapped, or null if the key did not have a mapping.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Maps the specified key to the specified value in this hashtable. Neither the key nor the value can be null.

Specified by:
put in interface java.util.Map
Parameters:
key - the hashtable key
value - the value
Returns:
the previous value of the specified key in hashtables, or null if it did not have one.

putAll

public void putAll(java.util.Map t)
Specified by:
putAll in interface java.util.Map
Parameters:
t - BucketizedHashtable or a Map with a supported operation entrySet

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map
Parameters:
key - possible key
Returns:
true if and only if the specified object is a key in one of of the hashtables

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map
Parameters:
value - possible value
Returns:
true if and only if the specified object is a value in one of of the hashtables

size

public int size()
Specified by:
size in interface java.util.Map
Returns:
the total number of key-value mappings of all buckets

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Map
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code value for this map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map
Returns:
true if this map contains no key-value mappings

clear

public void clear()
Clears this BucketizedHashtable so that it contains no key.

Specified by:
clear in interface java.util.Map

entrySet

public java.util.Set entrySet()
The return set is backed by the map, so changes to the map are reflected in the set, and vice-versa.

Specified by:
entrySet in interface java.util.Map
Returns:
a set of Map.Entry when bucketSet equal 1
Throws:
java.lang.UnsupportedOperationException - when bucketSize is greater one

keySet

public java.util.Set keySet()
The return set is backed by the map, so changes to the map are reflected in the set, and vice-versa.

Specified by:
keySet in interface java.util.Map
Returns:
a set of keys when bucketSet equal 1
Throws:
java.lang.UnsupportedOperationException - when bucketSize is greater one

values

public java.util.Collection values()
The return collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa.

Specified by:
values in interface java.util.Map
Returns:
a collection of values when bucketSet equal 1
Throws:
java.lang.UnsupportedOperationException - when bucketSize is greater one

equals

public boolean equals(java.lang.Object o)
Compares the specified object with this map for equality.

Specified by:
equals in interface java.util.Map
Overrides:
equals in class java.lang.Object
Returns:
true if the specified object is a BucketizedHashtable with hashtables represent the same set of mappings.

clone

public java.lang.Object clone()
Creates and returns a shallow copy of this object. The keys and values are not cloned.

Overrides:
clone in class java.lang.Object
Returns:
a clone of BucketizedHashtable

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this BucketizedHashtable


Copyright © 2012 GlassFish Community. All Rights Reserved.