Java Reference
In-Depth Information
Note:
The ADT dictionary contains entries that are key-value pairs organized by their
search keys. You can add a new entry, and you can locate, retrieve, or remove an entry, given
its search key. In addition, you can traverse a dictionary's search keys or values.
The following specifications define a set of operations for the ADT dictionary:
A
BSTRACT
D
ATA
T
YPE
: D
ICTIONARY
D
ATA
A collection of pairs (
k
,
v
) of objects
k
and
v
, where
k
is the search key and
v
is the corresponding value
●
The number of pairs in the collection
●
O
PERATIONS
P
SEUDOCODE
UML
D
ESCRIPTION
add(key, value)
+add(key : K, value : V) : void
Task: Adds the pair (
key
,
value
) to the dictionary.
Input:
key
is an object search key,
value
is an
associated object.
Output: None.
remove(key)
+remove(key : K) : V
Task: Removes from the dictionary the entry
that corresponds to a given search key.
Input:
key
is an object search key.
Output: Returns either the value that was
associated with the search key or
null
if
no such object exists.
getValue(key)
+getValue(key : K) : V
Task: Retrieves from the dictionary the value
that corresponds to a given search key.
Input:
key
is an object search key.
Output: Returns either the value associated
with the search key or
null
if no such
object exists.
contains(key)
+contains(key : K) : boolean
Task: Sees whether any entry in the dictionary
has a given search key.
Input:
key
is an object search key.
Output: Returns true if an entry in the dictionary
has
key
as its search key.
getKeyIterator()
+getKeyIterator() : Iterator<K>
Task: Creates an iterator that traverses all search
keys in the dictionary.
Input: None.
Output: Returns an iterator that provides
sequential access to the search keys
in the dictionary.