001 package edu.harvard.deas.hyperenc; 002 003 import java.io.Serializable; 004 005 import javax.mail.Address; 006 007 /** 008 * Represents a communication partner for hyper-encryption. Each Contact has a 009 * name and an e-mail address; each Contact should be uniquely identified by its 010 * e-mail address. That is, no two Contacts should be created with the same 011 * e-mail address. 012 * <p> 013 * Contacts are immutable. 014 */ 015 public class Contact implements Serializable { 016 private static final long serialVersionUID = 1L; 017 018 private final String fullName; 019 private final Address email; 020 private final String displayName; 021 022 /** 023 * Create a new Contact. 024 * 025 * @param fullName 026 * Full name of this contact 027 * @param email 028 * E-mail address for this contact 029 * @param displayName 030 * Display name for this contact 031 */ 032 public Contact(String fullName, Address email, String displayName) { 033 this.fullName = fullName; 034 this.email = email; 035 this.displayName = displayName; 036 } 037 038 /** 039 * Returns the name of this contact. 040 * @return the name of this contact 041 */ 042 public String getFullName() { 043 return fullName; 044 } 045 046 /** 047 * Returns the e-mail address of this contact. 048 * @return the e-mail address of this contact 049 */ 050 public Address getEmail() { 051 return email; 052 } 053 054 /** 055 * Returns the display name of this contact. The display name is the name that 056 * is displayed in places where an abbreviated or more casual name is desired. 057 * (But the display name is not required to have any particular relationship 058 * to the full name.) 059 * 060 * @return the displayName 061 */ 062 public String getDisplayName() { 063 return displayName; 064 } 065 066 /** 067 * Returns a String representation of this Contact. 068 * @return a String representation of this Contact 069 */ 070 @Override 071 public String toString() { 072 return this.displayName + " <" + this.email.toString() + ">"; 073 } 074 075 /** 076 * Compares this Contact to the given Object. Returns <code>true</code> iff 077 * <code>o</code> is a Contact with an e-mail address equal to this Contact's 078 * e-mail address. 079 */ 080 @Override 081 public boolean equals(Object o) { 082 if (o instanceof Contact) { 083 Contact c = (Contact)o; 084 return (email.equals(c.getEmail())); 085 } else { 086 return false; 087 } 088 } 089 090 @Override 091 public int hashCode() { 092 return email.hashCode(); 093 } 094 }