Java Reference
In-Depth Information
Code 12.1
continued
The AddressBook
class
* @param key The name or number to be looked up.
* @return The details corresponding to the key.
*/
public ContactDetails getDetails(String key)
{
return book.get(key);
}
/**
* Return whether or not the current key is in use.
* @param key The name or number to be looked up.
* @return true if the key is in use, false otherwise.
*/
public boolean keyInUse(String key)
{
return book.containsKey(key);
}
/**
* Add a new set of details to the address book.
* @param details The details to associate with the person.
*/
public void addDetails(ContactDetails details)
{
book.put(details.getName(), details);
book.put(details.getPhone(), details);
numberOfEntries++;
}
/**
* Change the details previously stored under the given key.
* @param oldKey One of the keys used to store the details.
* @param details The replacement details.
*/
public void changeDetails(String oldKey,
ContactDetails details)
{
removeDetails(oldKey);
addDetails(details);
}
/**
* Search for all details stored under a key that starts with
* the given prefix.
* @param keyPrefix The key prefix to search on.
* @return An array of those details that have been found.
*/
Search WWH ::




Custom Search