Class IntHashtable
- java.lang.Object
-
- com.aowagie.text.pdf.IntHashtable
-
- All Implemented Interfaces:
java.lang.Cloneable
class IntHashtable extends java.lang.Object implements java.lang.CloneableA 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classIntHashtable.EntryInnerclass that acts as a datastructure to create a new entry in the table.private static classIntHashtable.IntHashtableIterator
-
Field Summary
Fields Modifier and Type Field Description private intcountThe total number of entries in the hash table.private floatloadFactorThe load factor for the hashtable.private IntHashtable.Entry[]tableThe hash table data.private intthresholdThe table is rehashed when its size exceeds this threshold.
-
Constructor Summary
Constructors Modifier Constructor Description IntHashtable()Constructs a new, empty hashtable with a default capacity and load factor, which is20and0.75respectively.IntHashtable(int initialCapacity)Constructs a new, empty hashtable with the specified initial capacity and default load factor, which is0.75.privateIntHashtable(int initialCapacity, float loadFactor)Constructs a new, empty hashtable with the specified initial capacity and the specified load factor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidclear()Clears this hashtable so that it contains no keys.java.lang.Objectclone()(package private) booleancontainsKey(int key)Tests if the specified int is a key in this hashtable.(package private) intget(int key)Returns the value to which the specified key is mapped in this map.java.util.IteratorgetEntryIterator()int[]getKeys()intgetOneKey()booleanisEmpty()Tests if this hashtable maps no keys to values.(package private) intput(int key, int value)Maps the specifiedkeyto the specifiedvaluein this hashtable.private voidrehash()Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently.(package private) intremove(int key)Removes the key (and its corresponding value) from this hashtable.(package private) intsize()Returns the number of keys in this hashtable.(package private) int[]toOrderedKeys()
-
-
-
Field Detail
-
table
private transient IntHashtable.Entry[] table
The hash table data.
-
count
private transient int count
The total number of entries in the hash table.
-
threshold
private int threshold
The table is rehashed when its size exceeds this threshold. (The value of this field is (int)(capacity * loadFactor).)
-
loadFactor
private final float loadFactor
The load factor for the hashtable.
-
-
Constructor Detail
-
IntHashtable
public IntHashtable()
Constructs a new, empty hashtable with a default capacity and load factor, which is
20and0.75respectively.
-
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:
java.lang.IllegalArgumentException- if the initial capacity is less than zero.
-
IntHashtable
private 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:
java.lang.IllegalArgumentException- if the initial capacity is less than zero, or if the load factor is nonpositive.
-
-
Method Detail
-
size
int size()
Returns the number of keys in this hashtable.
- Returns:
- the number of keys in this hashtable.
-
isEmpty
public boolean isEmpty()
Tests if this hashtable maps no keys to values.
- Returns:
trueif this hashtable maps no keys to values;falseotherwise.
-
containsKey
boolean containsKey(int key)
Tests if the specified int is a key in this hashtable.
- Parameters:
key- possible key.- Returns:
trueif and only if the specified int is a key in this hashtable, as determined by the equals method;falseotherwise.- See Also:
#contains(int)
-
get
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;
nullif the key is not mapped to any value in this hashtable. - See Also:
put(int, int)
-
rehash
private 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.
-
put
int put(int key, int value)Maps the specified
keyto the specifiedvaluein this hashtable. The key cannot benull.The value can be retrieved by calling the
getmethod 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
nullif it did not have one. - Throws:
java.lang.NullPointerException- if the key isnull.- See Also:
get(int)
-
remove
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
nullif the key did not have a mapping.
-
clear
void clear()
Clears this hashtable so that it contains no keys.
-
getEntryIterator
public java.util.Iterator getEntryIterator()
-
toOrderedKeys
int[] toOrderedKeys()
-
getKeys
public int[] getKeys()
-
getOneKey
public int getOneKey()
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object
-
-