1 36 package org.columba.ristretto.message; 37 38 import java.io.IOException ; 39 import java.io.Serializable ; 40 41 import org.columba.ristretto.parser.AddressParser; 42 import org.columba.ristretto.parser.ParserException; 43 44 50 public class Address implements Serializable , Comparable { 51 52 private String displayName; 53 private String mailAddress; 54 55 static final long serialVersionUID = -7663098020871087578l; 56 57 64 public Address(String mailAddress) { 65 this("", mailAddress); 66 } 67 68 76 77 public Address(String displayName, String mailAddress) { 78 this.displayName = displayName; 79 this.mailAddress = mailAddress; 80 } 81 82 89 public String getDisplayName() { 90 return displayName; 91 } 92 93 101 public String getMailAddress() { 102 return mailAddress; 103 } 104 105 113 public String getCanonicalMailAddress() { 114 return '<' + mailAddress + '>'; 115 } 116 117 125 public String getShortAddress() { 126 if ((displayName != null) && (displayName.length() > 0)) { 127 return displayName; 128 } else { 129 return mailAddress; 130 } 131 } 132 133 140 public void setDisplayName(String displayName) { 141 this.displayName = displayName; 142 } 143 144 145 148 public boolean equals(Object arg0) { 149 boolean result = false; 150 if ((arg0 != null) && (arg0 instanceof Address)) { 151 Address a = (Address) arg0; 152 result = true; 153 if (mailAddress != null) { 154 result = result && mailAddress.equals(a.getMailAddress()); 155 } 156 } 157 158 return result; 159 } 160 161 162 165 public String toString() { 166 if (displayName == null || displayName.length() == 0) { 167 return mailAddress; 168 } else { 169 return "\"" + displayName + "\" " + getCanonicalMailAddress(); 170 } 171 } 172 173 177 private void writeObject(java.io.ObjectOutputStream out) throws IOException { 178 if (displayName != null) { 179 out.writeByte(1); 181 out.writeUTF(displayName); 182 out.writeUTF(mailAddress); 183 } else { 184 out.writeByte(0); 186 out.writeUTF(mailAddress); 187 } 188 } 189 190 private void readObject(java.io.ObjectInputStream in) throws IOException , ClassNotFoundException { 191 byte mode = in.readByte(); 192 193 if (mode == 1) { 194 displayName = in.readUTF(); 195 } 196 197 mailAddress = in.readUTF(); 198 } 199 200 203 public int compareTo(Object arg0) { 204 return mailAddress.compareTo(((Address) arg0).getMailAddress()); 205 } 206 207 210 public int hashCode() { 211 return mailAddress.hashCode(); 212 } 213 214 221 public static Address parse(CharSequence source) throws ParserException { 222 return AddressParser.parseAddress(source); 223 } 224 } 225 | Popular Tags |