com.lowagie.text.pdf

Class IntHashtable

public class IntHashtable extends Object implements Cloneable

A hash map that uses primitive ints for the key rather than objects.

Note that this class is for internal optimization purposes only, and may not be supported in future releases of Jakarta Commons Lang. Utilities of this sort may be included in future releases of Jakarta Commons Collections.

Author: Justin Couch Alex Chaffee (alex@apache.org) Stephen Colebourne Bruno Lowagie (change Objects as keys into int values) Paulo Soares (added extra methods)

Nested Class Summary
static classIntHashtable.Entry

Innerclass that acts as a datastructure to create a new entry in the table.

static classIntHashtable.IntHashtableIterator
Field Summary
intcount
The total number of entries in the hash table.
floatloadFactor
The load factor for the hashtable.
IntHashtable.Entry[]table
The hash table data.
intthreshold
The table is rehashed when its size exceeds this threshold.
Constructor Summary
IntHashtable()

Constructs a new, empty hashtable with a default capacity and load factor, which is 20 and 0.75 respectively.

IntHashtable(int initialCapacity)

Constructs a new, empty hashtable with the specified initial capacity and default load factor, which is 0.75.

IntHashtable(int initialCapacity, float loadFactor)

Constructs a new, empty hashtable with the specified initial capacity and the specified load factor.

Method Summary
voidclear()

Clears this hashtable so that it contains no keys.

Objectclone()
booleancontains(int value)

Tests if some key maps into the specified value in this hashtable.

booleancontainsKey(int key)

Tests if the specified int is a key in this hashtable.

booleancontainsValue(int value)

Returns true if this HashMap maps one or more keys to this value.

Note that this method is identical in functionality to contains (which predates the Map interface).

intget(int key)

Returns the value to which the specified key is mapped in this map.

IteratorgetEntryIterator()
int[]getKeys()
intgetOneKey()
booleanisEmpty()

Tests if this hashtable maps no keys to values.

intput(int key, int value)

Maps the specified key to the specified value in this hashtable.

protected voidrehash()

Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently.

This method is called automatically when the number of keys in the hashtable exceeds this hashtable's capacity and load factor.

intremove(int key)

Removes the key (and its corresponding value) from this hashtable.

This method does nothing if the key is not present in the hashtable.

intsize()

Returns the number of keys in this hashtable.

int[]toOrderedKeys()

Field Detail

count

private transient int count
The total number of entries in the hash table.

loadFactor

private float loadFactor
The load factor for the hashtable.

Serial:

table

private transient IntHashtable.Entry[] table
The hash table data.

threshold

private int threshold
The table is rehashed when its size exceeds this threshold. (The value of this field is (int)(capacity * loadFactor).)

Serial:

Constructor Detail

IntHashtable

public IntHashtable()

Constructs a new, empty hashtable with a default capacity and load factor, which is 20 and 0.75 respectively.

IntHashtable

public IntHashtable(int initialCapacity)

Constructs a new, empty hashtable with the specified initial capacity and default load factor, which is 0.75.

Parameters: initialCapacity the initial capacity of the hashtable.

Throws: IllegalArgumentException if the initial capacity is less than zero.

IntHashtable

public IntHashtable(int initialCapacity, float loadFactor)

Constructs a new, empty hashtable with the specified initial capacity and the specified load factor.

Parameters: initialCapacity the initial capacity of the hashtable. loadFactor the load factor of the hashtable.

Throws: IllegalArgumentException if the initial capacity is less than zero, or if the load factor is nonpositive.

Method Detail

clear

public void clear()

Clears this hashtable so that it contains no keys.

clone

public Object clone()

contains

public boolean contains(int value)

Tests if some key maps into the specified value in this hashtable. This operation is more expensive than the containsKey method.

Note that this method is identical in functionality to containsValue, (which is part of the Map interface in the collections framework).

Parameters: value a value to search for.

Returns: true if and only if some key maps to the value argument in this hashtable as determined by the equals method; false otherwise.

Throws: NullPointerException if the value is null.

See Also: IntHashtable IntHashtable java.util.Map

containsKey

public boolean containsKey(int key)

Tests if the specified int is a key in this hashtable.

Parameters: key possible key.

Returns: true if and only if the specified int is a key in this hashtable, as determined by the equals method; false otherwise.

See Also: IntHashtable

containsValue

public boolean containsValue(int value)

Returns true if this HashMap maps one or more keys to this value.

Note that this method is identical in functionality to contains (which predates the Map interface).

Parameters: value value whose presence in this HashMap is to be tested.

Returns: boolean true if the value is contained

Since: JDK1.2

See Also: java.util.Map

get

public int get(int key)

Returns the value to which the specified key is mapped in this map.

Parameters: key a key in the hashtable.

Returns: the value to which the key is mapped in this hashtable; null if the key is not mapped to any value in this hashtable.

See Also: IntHashtable

getEntryIterator

public Iterator getEntryIterator()

getKeys

public int[] getKeys()

getOneKey

public int getOneKey()

isEmpty

public boolean isEmpty()

Tests if this hashtable maps no keys to values.

Returns: true if this hashtable maps no keys to values; false otherwise.

put

public int put(int key, int value)

Maps the specified key to the specified value in this hashtable. The key cannot be null.

The value can be retrieved by calling the get method with a key that is equal to the original key.

Parameters: key the hashtable key. value the value.

Returns: the previous value of the specified key in this hashtable, or null if it did not have one.

Throws: NullPointerException if the key is null.

See Also: IntHashtable

rehash

protected void rehash()

Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently.

This method is called automatically when the number of keys in the hashtable exceeds this hashtable's capacity and load factor.

remove

public int remove(int key)

Removes the key (and its corresponding value) from this hashtable.

This method does nothing if the key is not present in the hashtable.

Parameters: key the key that needs to be removed.

Returns: the value to which the key had been mapped in this hashtable, or null if the key did not have a mapping.

size

public int size()

Returns the number of keys in this hashtable.

Returns: the number of keys in this hashtable.

toOrderedKeys

public int[] toOrderedKeys()