/**
 * A DirectoryEntry contains a name and number (both Strings).
 * The name is immutable.
 *
 * @author Zach Tomaszewski (extending Koffman & Wolfgang)
 * @verison 15 Sept 2005
 */
public class DirectoryEntry implements Comparable<DirectoryEntry> {

  private String name;
  private String number;

  /**
   * Constructor.
   */
  public DirectoryEntry(String name, String number) {
    this.name = name;
    this.number = number;
  }

  /**
   * Returns this entry's name.
   */
  public String getName() {
    return this.name;
  }

  /**
   * Returns this entry's number.
   */
  public String getNumber() {
    return this.number;
  }

  /**
   * Sets this entry's number to the given num.
   */
  public void setNumber(String num) {
    this.number = num;
  }

  /**
   * Returns a string representation of this entry.
   */
  public String toString() {
    return this.name + " \t" + this.number + "\n";
  }

  /**
   * Return true if this entry contains the same data as the given entry.
   */
  public boolean equals(Object o) {
    if (this.getClass().equals(o.getClass())) {
      DirectoryEntry rhs = (DirectoryEntry) o;
      return (this.name.equals(rhs.name) && this.number.equals(rhs.number));
    }else {
      //not even of the same class
      return false;
    }
  }

  /**
   * Return < 0 if this entry should come before <code>o</code>,
   * 0 if they are equal, or > 0 if this item should come after <code>o</code>.
   */
  public int compareTo(DirectoryEntry o){
    //use String's compareTo method to compare names
    int comparison = this.getName().compareTo(o.getName());
    if (comparison == 0) {
      //names are the same, so compare numbers to find difference
      comparison = this.getNumber().compareTo(o.getNumber());
    }
    return comparison;
  }

}//end class
