Java Reference
In-Depth Information
/**
A class that implements a dictionary by using an array.
@author Frank M. Carrano
*/
public class
ArrayDictionary<K, V>
implements
DictionaryInterface<K, V>
{
private
Entry<K, V>[] dictionary;
// array of unsorted entries
private
int
numberOfEntries;
private
final static int
DEFAULT_CAPACITY = 25;
public
ArrayDictionary()
{
this
(DEFAULT_CAPACITY);
// call next constructor
}
// end default constructor
public
ArrayDictionary(
int
initialCapacity)
{
// the cast is safe because the new array contains null entries
@SuppressWarnings("unchecked")
Entry<K, V>[] tempDictionary =
(Entry<K, V>[])
new
Entry[initialCapacity];
dictionary = tempDictionary;
numberOfEntries = 0;
}
// end constructor
<
Implementations of methods in
DictionaryInterface
>
. . .
private class
Entry<S, T>
{
private
S key;
private
T value;
private
Entry(S searchKey, T dataValue)
{
key = searchKey;
value = dataValue;
}
// end constructor
private
S getKey()
{
return
key;
}
// end getKey
private
T getValue()
{