com.h20.course.tp4
Class NameDirectory

java.lang.Object
  extended by com.h20.course.tp4.NameDirectory

public final class NameDirectory
extends java.lang.Object

This class implements a list of names, which consists of a set of names (Entry), plus a set of labels. We use labels to group related names. Typical labels are, say, "work", "friends", "university", etc. This class is a SINGLETON. Notice that the life cycle of a static object is not well under your control; if the application logic depends on the destruction of specific objects, then to abide by the life-cycle model, the application class should initiate and tear down these static objects in the onCreate() and onTerminate() methods of the Application Class.

Author:
fpereira

Method Summary
static void add(java.lang.String name, java.lang.String number)
          This method adds a new entry to the phone list.
static boolean addLabel(java.lang.String name, java.lang.String label)
          Adds a new label to the directory of names.
static void delete(java.lang.String name)
          This method deletes an entry from the list.
static java.util.List<Entry> getEntries()
          Return an array with all the entries stored in this directory.
static java.util.List<java.lang.String> getLabels()
          This method returns the list of all the labels in the data-set.
static java.util.List<java.lang.String> getLabels(java.lang.String name)
          This method returns the list of labels that mark a given entry.
static void removeLabel(java.lang.String name, java.lang.String label)
          This method removes the label from a given name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getLabels

public static java.util.List<java.lang.String> getLabels()
This method returns the list of all the labels in the data-set.

Returns:
a list of strings, each one representing a label.

getLabels

public static java.util.List<java.lang.String> getLabels(java.lang.String name)
This method returns the list of labels that mark a given entry.

Parameters:
name - the identifier of the target entry.
Returns:
the list of labels associated to the entry.

add

public static void add(java.lang.String name,
                       java.lang.String number)
This method adds a new entry to the phone list. If the name was already present in the collection of names, then the old name will be overwritten by the new one.

Parameters:
name - the owner of the telephone.
number - the number that will be bound to the name.

delete

public static void delete(java.lang.String name)
This method deletes an entry from the list.

Parameters:
name - the name that identifies the entry that will be deleted.

addLabel

public static boolean addLabel(java.lang.String name,
                               java.lang.String label)
                        throws NameNotFoundException
Adds a new label to the directory of names.

Parameters:
name - the name of the entry that will be labeled.
label - the new label that will be created.
Returns:
a boolean value that will be true if the label was not present in the list of available labels, and had to be created by this method. It will be false if the label already existed, and was just associated to the Entry corresponding to the name.
Throws:
NameNotFoundException - in case the name was not present in the directory.

removeLabel

public static void removeLabel(java.lang.String name,
                               java.lang.String label)
                        throws NameNotFoundException,
                               LabelNotFoundException
This method removes the label from a given name.

Parameters:
name - The target name
label - The label to be removed
Throws:
NameNotFoundException - If the name is not present.
LabelNotFoundException - If the label does not exist.

getEntries

public static java.util.List<Entry> getEntries()
Return an array with all the entries stored in this directory.

Returns:
an array of entries.