/**
 * 
 */
package myDirectory;

/**
 * @author walker
 *  Base class for recording information for people in a directory
 */
public class Person implements Comparable <Person>{
   String firstName;
   String lastName;
   String emailAddress;

   /**
    * The default constructor assigns null to each internal field
    */
   public Person() {
   }

   /**
    * The 3-parameter constructor specifies each basic field for a directory entry 
    * @param firstName
    * @param lastName
    * @param emailAddress
    */
   public Person(String firstName, String lastName, String emailAddress) {
      this.firstName = firstName;
      this.lastName = lastName;
      this.emailAddress = emailAddress;
   }



   /**
    * @return the firstName
    */
   public String getfirstName() {
      return firstName;
   }

   /**
    * @param firstName the firstName to set
    */
   public void setfirstName(String firstName) {
      this.firstName = firstName;
   }

   /**
    * @return the lastName
    */
   public String getLastName() {
      return lastName;
   }

   /**
    * @param lastName the lastName to set
    */
   public void setLastName(String lastName) {
      this.lastName = lastName;
   }

   /**
    * @return the emailAddress
    */
   public String getEmailAddress() {
      return emailAddress;
   }

   /**
    * @param emailAddress the emailAddress to set
    */
   public void setEmailAddress(String emailAddress) {
      this.emailAddress = emailAddress;
   }

   
   
   @Override
   public String toString() {
      return "Person ["
               + (firstName != null ? "firstName=" + firstName + ", " : "")
               + (lastName != null ? "lastName=" + lastName + ", " : "")
               + (emailAddress != null ? "emailAddress=" + emailAddress : "")
               + "]";
   }

   
   
   @Override
   public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result
               + ((firstName == null) ? 0 : firstName.hashCode());
      result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
      return result;
   }

   @Override
   public boolean equals(Object obj) {
      if (this == obj)
         return true;
      if (obj == null)
         return false;
      if (getClass() != obj.getClass())
         return false;
      Person other = (Person) obj;
      if (firstName == null) {
         if (other.firstName != null)
            return false;
      } else if (!firstName.equals(other.firstName))
         return false;
      if (lastName == null) {
         if (other.lastName != null)
            return false;
      } else if (!lastName.equals(other.lastName))
         return false;
      return true;
   }

   
   
   /**
    * @param args
    */
   public static void main(String[] args) {
      // TODO Auto-generated method stub

   }

   @Override
   public int compareTo(Person per) {
      if (this == null && per == null)
         return 0;
      if (this == null)
         return 1;
      if (per == null)
         return -1;
      if (this.lastName.equals (per.lastName)) {
         return this.firstName.compareTo(per.firstName);
      }
      else {
         return this.lastName.compareTo(per.lastName);
      }
   }  


}
