net.rim.device.api.util
Class ToLongHashtable

java.lang.Object
  extended by net.rim.device.api.util.ToLongHashtable
All Implemented Interfaces:
Persistable

public class ToLongHashtable
extends Object
implements Persistable

This class implements a hashtable, which maps keys to values.

Any non-null object can be used as a key. To successfully store and retrieve values from a hashtable, the objects used as keys must implement the Object.hashCode() and Object.equals(java.lang.Object) methods.

A hashtable has two parameters that affect its efficiency: its capacity and its load factor. The load factor should be between 0.0 and 1.0. When the number of entries in the hashtable exceeds the product of the load factor and the current capacity, the capacity is increased by invoking ToLongHashtable.rehash(). Larger load factors use memory more efficiently, at the expense of larger expected time per lookup.

If many entries are to be made into a hashtable, creating it with a sufficiently large capacity may allow the entries to be inserted more efficiently than letting it perform automatic rehashing as needed to grow the table.

Since:
BlackBerry API 4.2.0

Constructor Summary
ToLongHashtable()
          Construct a new, empty hashtable with a default capacity and load factor.
ToLongHashtable(int initialCapacity)
          Construct a new, empty hashtable with the specified capacity.
 
Method Summary
 void clear()
          Flush this hashtable.
 boolean contains(long value)
          Determines if some key maps into the specified value in this hashtable.
 boolean containsKey(Object key)
          Determines if the argument specified is a key in this hashtable.
 LongEnumeration elements()
          Retrieves an enumeration of the values in this hashtable.
 long get(Object key)
          Retrieves value by key.
 boolean isEmpty()
          Determines if this hashtable maps no keys to values.
 Enumeration keys()
          Retrieves an enumeration of the keys in this hashtable.
 long put(Object key, long value)
          Maps value to key in this hashtable.
protected  void rehash()
          Rehashes the contents of this hashtable.
 long remove(Object key)
          Removes value by key.
 int size()
          Retrieves the number of keys in this hashtable.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Constructor Detail

ToLongHashtable

public ToLongHashtable(int initialCapacity)
Construct a new, empty hashtable with the specified capacity.

Parameters:
initialCapacity - Initial capacity of the hashtable.
Throws:
IllegalArgumentException - If the initial capacity is less than zero
Since:
BlackBerry API 4.2.0

ToLongHashtable

public ToLongHashtable()
Construct a new, empty hashtable with a default capacity and load factor.

Since:
BlackBerry API 4.2.0


Method Detail

size

public int size()
Retrieves the number of keys in this hashtable.

Returns:
Number of keys in this hashtable.
Since:
BlackBerry API 4.2.0

isEmpty

public boolean isEmpty()
Determines if this hashtable maps no keys to values.

Returns:
True if this hashtable has no keys mapped to values; otherwise, false.
Since:
BlackBerry API 4.2.0

keys

public Enumeration keys()
Retrieves an enumeration of the keys in this hashtable.

Returns:
Enumeration of keys in this hashtable.
See Also:
Enumeration, ToLongHashtable.elements()
Since:
BlackBerry API 4.2.0

elements

public LongEnumeration elements()
Retrieves an enumeration of the values in this hashtable.

Use the Enumeration methods on the returned object to fetch the elements sequentially.

Returns:
Enumeration of the values in this hashtable.
See Also:
Enumeration, ToLongHashtable.keys()
Since:
BlackBerry API 4.2.0

contains

public boolean contains(long value)
Determines if some key maps into the specified value in this hashtable.

This operation is more expensive than ToLongHashtable.containsKey(java.lang.Object).

Parameters:
value - Value to search for.
Returns:
True if some key maps to the provided value in this hashtable; otherwise, false.
Throws:
NullPointerException - If null value provided.
Since:
BlackBerry API 4.2.0

containsKey

public boolean containsKey(Object key)
Determines if the argument specified is a key in this hashtable.

Parameters:
key - Key to test.
Returns:
True if the provided argument is a key in this hashtable; otherwise, false.
See Also:
ToLongHashtable.contains(long)
Since:
BlackBerry API 4.2.0

clear

public void clear()
Flush this hashtable.

Invoke this method to remove all keys and values from this hashtable.

Since:
BlackBerry API 4.2.0

remove

public long remove(Object key)
Removes value by key.

If the key does not exist in this hashtable, then this method does nothing.

Parameters:
key - Key for value to remove.
Returns:
Value that had been associated with key, or -1 if no value had been associated with key.
Since:
BlackBerry API 4.2.0

get

public long get(Object key)
Retrieves value by key.

Parameters:
key - Key in this hashtable.
Returns:
Value associated with provided key, or -1 if no value associated with the key.
Since:
BlackBerry API 4.2.0

rehash

protected void rehash()
Rehashes the contents of this hashtable.

Invoke this method to rehash this hashtable into one with a larger capacity. This hashtable invokes this method automatically when the number of keys exceeds its capacity and load factor.

Since:
BlackBerry API 4.2.0

put

public long put(Object key,
                long value)
Maps value to key in this hashtable.

The value can be retrieved by invoking ToLongHashtable.get(java.lang.Object) with a key that is equal to the original key.

Parameters:
key - Key to associate with the value.
value - Value to put into table.
Returns:
Previous value associated with key, or -1 if key had no previous associated value.
Throws:
NullPointerException - If null key or null value.
Since:
BlackBerry API 4.2.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal