|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Dictionary | +--gov.nist.nlpir.irf.index.IrfHashtable
This class is a classic implementation of an hashtable class. It adds
an important feature usual Hashtables don't provide: as storing in
the table only uses hashCode()
and equals()
,
and that these methods can be refined in each class to have a specific
behavior, it is actually possible to access an object in the hashtable
with different keys, provided these keys have the same hashCode and
return true
when they are compared with equals()
. This is used in DualKeyContainer and in IdxIntern. Thus, there
is a need for a method getActualKey()
that returns the
object actually stored as a key when you access the hashtable with a
false key - a key not actually stored.
Inheritance couldn't be used to add this feature to java.util.Hashtable
because the core of the Hashtable, ie the array of entries is private
and not protected, so that extending Hashtable doesn't allow addition
of this kind of feature.
It also contains a method that reveals the length of the base table
array.
Field Summary | |
private int |
count
The total number of entries in the hashtable. |
private float |
loadFactor
|
(package private) static long |
serialVersionUID
serial version universal id - put here so Java does not insert one which may change due to revisions and make it impossible to deserialize earlier versions of serialized objects |
protected IrfHashtableEntry[] |
table
The hashtable data -protected so that this class can be extended. |
private int |
threshold
|
Constructor Summary | |
IrfHashtable()
Constructs a new, empty hashtable with a default capacity and load factor. |
|
IrfHashtable(int initialCapacity)
Constructs a new, empty hashtable with the specified initial capacity and default load factor. |
|
IrfHashtable(int initialCapacity,
float loadFactor)
Constructs a new, empty hashtable with the specified initial capacity and the specified load factor. |
Method Summary | |
void |
clear()
Clears this hashtable so that it contains no keys. |
java.lang.Object |
clone()
Creates a shallow copy of this hashtable. |
boolean |
contains(java.lang.Object value)
Tests if some key maps into the specified value in this hashtable. |
boolean |
containsKey(java.lang.Object key)
Tests if the specified object is a key in this hashtable. |
java.util.Enumeration |
elements()
|
java.lang.Object |
get(java.lang.Object key)
Returns the value to which the specified key is mapped in this hashtable. |
java.lang.Object |
getActualKey(java.lang.Object key)
Returns the object actually stored as a key for this possible key. |
boolean |
isEmpty()
Tests if this hashtable maps no keys to values. |
java.util.Enumeration |
keys()
Returns an enumeration of the keys in this hashtable. |
int |
length()
Returns the size of the base array |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Maps the specified key to the specified
value in this hashtable. |
private void |
readObject(java.io.ObjectInputStream s)
readObject is called to restore the state of the hashtable from a stream. |
protected void |
rehash()
Rehashes the contents of the hashtable into a hashtable with a larger capacity. |
java.lang.Object |
remove(java.lang.Object key)
Removes the key (and its corresponding value) from this hashtable. |
int |
size()
Returns the number of keys in this hashtable. |
java.lang.String |
toString()
Returns a rather long string representation of this hashtable. |
java.util.Enumeration |
values()
Returns an enumeration of the values in this hashtable. |
private void |
writeObject(java.io.ObjectOutputStream s)
WriteObject is called to save the state of the hashtable to a stream. |
Methods inherited from class java.lang.Object |
|
Field Detail |
static final long serialVersionUID
protected transient IrfHashtableEntry[] table
private transient int count
private int threshold
private float loadFactor
Constructor Detail |
public IrfHashtable(int initialCapacity, float loadFactor)
initialCapacity
- the initial capacity of the hashtable.loadFactor
- a number between 0.0 and 1.0.public IrfHashtable(int initialCapacity)
initialCapacity
- the initial capacity of the hashtable.public IrfHashtable()
Method Detail |
public int size()
public int length()
public boolean isEmpty()
true
if this hashtable maps no keys to values;
false
otherwise.public java.util.Enumeration keys()
Enumeration
,
elements()
public java.util.Enumeration values()
Enumeration
,
keys()
public java.util.Enumeration elements()
public boolean contains(java.lang.Object value)
containsKey
method.value
- a value to search for.true
if some key maps to the
value
argument in this hashtable;
false
otherwise.null
.containsKey(java.lang.Object)
public boolean containsKey(java.lang.Object key)
key
- possible key.true
if the specified object is a key in this
hashtable; false
otherwise.contains(java.lang.Object)
public java.lang.Object get(java.lang.Object key)
key
- a key in the hashtable.null
if the key is not mapped to any value in
this hashtable.put(java.lang.Object, java.lang.Object)
protected void rehash()
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
key
to the specified
value
in this hashtable. Neither the key nor the
value can be null
.
The value can be retrieved by calling the get
method
with a key that is equal to the original key. Equal here means that
it has the same hash code and returns true to the method equals().
key
- the hashtable key.value
- the value.null
if it did not have one.null
.Object.equals(java.lang.Object)
,
get(java.lang.Object)
public java.lang.Object remove(java.lang.Object key)
key
- the key that needs to be removed.null
if the key did not have a mapping.public void clear()
public java.lang.Object clone()
public java.lang.String toString()
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, java.lang.ClassNotFoundException
public java.lang.Object getActualKey(java.lang.Object key)
key
- possible key.true
if the specified object is a key in this
hashtable; false
otherwise.contains(java.lang.Object)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |