/**
 * A phone with a phone number and possibly a phone that called it.
 */
public class Phone {
  
  private String number;
  private Phone from;
  
  /**
   * A Phone with the given phone number, and currently no calling phone.
   * @param number  the phone number
   */
  public Phone(String number) {
    this.number = number;
  }
  
  /**
   * Return the phone that called this phone, or null if none.
   * @return  the phone that called this phone, or null if none
   */
  public Phone fromPhone() {
    return from;
  }
  
  /**
   * Set the phone that called this phone.
   * @param fromPhone  the phone that called this phone, or null if none
   */
  public void setFromPhone(Phone fromPhone) {
    from = fromPhone;
  }
  
  /**
   * Return whether an object is a phone with the same phone number as this phone.
   * @param o  an object to compare
   * @return  whether o is a phone with the same phone number as this
   */
  public boolean equals(Object o) {
    return o != null
      && o instanceof Phone
      && number.equals(((Phone)o).number);
  }
  
  /** 
   * Return a string representation of this phone: its phone number.
   * @return  a string representation of this phone: its phone number
   */
  public String toString() {
    return number;
  }
}

