Changeset 1404 for trunk/src/java/org/jcoderz/commons/types
- Timestamp:
- 04/14/09 12:34:34 (3 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/java/org/jcoderz/commons/types/EmailAddress.java
r1205 r1404 91 91 * </pre> 92 92 * 93 * <p>The maximum length of an email address is: 64+1+255 characters (local-part + @ + domain). 94 * The minimum length of an email address is: 1+1+4 characters (local-part + @ + domain).</p> 93 * <p>The maximum length of an email address is: 94 * 64+1+255 characters (local-part + @ + domain). 95 * The minimum length of an email address is: 96 * 1+1+4 characters (local-part + @ + domain).</p> 95 97 * 96 98 * <p>A valid list of top-level domains is defined by the IANA. A top-level … … 123 125 private static final String LET_DIG = "[a-zA-Z0-9]"; 124 126 private static final String LET_DIG_HYP = "[a-zA-Z0-9-]"; 125 private static final String RFC_LABEL = LET_DIG + LET_DIG_HYP + "{0,61}" + LET_DIG; 126 private static final String DOMAIN = RFC_LABEL + "(\\." + RFC_LABEL + ")*\\." + LETTER + "{2,6}"; 127 private static final String RFC_LABEL 128 = LET_DIG + LET_DIG_HYP + "{0,61}" + LET_DIG; 129 private static final String DOMAIN 130 = RFC_LABEL + "(\\." + RFC_LABEL + ")*\\." + LETTER + "{2,6}"; 127 131 128 132 //Combined together, these form the allowed email regexp allowed by RFC 2822: … … 141 145 * @param email The email address. 142 146 */ 143 public EmailAddress (String email)147 public EmailAddress (String email) 144 148 { 145 149 Assert.notNull(email, "email"); … … 156 160 { 157 161 throw new ArgumentMalformedException("email", email, 158 "The local part is longer than " + MAX_LENGTH_LOCAL_PART + " characters!"); 162 "The local part is longer than " + MAX_LENGTH_LOCAL_PART 163 + " characters!"); 159 164 } 160 165 if (mail.length() - at - 1 > MAX_LENGTH_DOMAIN) 161 166 { 162 167 throw new ArgumentMalformedException("email", email, 163 "The domain is longer than " + MAX_LENGTH_DOMAIN + " characters!"); 168 "The domain is longer than " + MAX_LENGTH_DOMAIN 169 + " characters!"); 164 170 } 165 171 mLocalPart = mail.substring(0, at); … … 171 177 172 178 /** 173 * Factory method for converting a String into an instance of type EmailAddress. 179 * Factory method for converting a String into an instance of type 180 * EmailAddress. 174 181 * 175 182 * @param email the email address to parse … … 183 190 /** 184 191 * Returns the local part of the address. 185 *186 192 * @return the local part of the address. 187 193 */ 188 public String getName ()194 public String getName () 189 195 { 190 196 return mLocalPart; … … 194 200 /** 195 201 * Returns the domain name of the address. 196 *197 202 * @return the domain name of the address. 198 203 */ 199 public String getDomain ()204 public String getDomain () 200 205 { 201 206 return mDomain; … … 205 210 /** 206 211 * Returns the top-level domain name of the address. 207 *208 212 * @return the top-level domain name of the address. 209 213 */ 210 public String getTopLevelDomain ()214 public String getTopLevelDomain () 211 215 { 212 216 return mTopLevelDomain; 213 217 } 214 218 215 216 /**217 * Returns the full email address.218 *219 * @return the full email address.220 */221 public String getAddress()222 {223 return mLocalPart + "@" + mDomain;224 }225 219 226 220 /** … … 228 222 * @return the full email address. 229 223 */ 230 public String toString()224 public String getAddress () 231 225 { 232 226 return mLocalPart + "@" + mDomain; … … 234 228 235 229 /** 230 * Returns the full email address. 231 * @return the full email address. 232 */ 233 public String toString () 234 { 235 return mLocalPart + "@" + mDomain; 236 } 237 238 /** 236 239 * Returns the true if this email address equals the other. 240 * @param obj the object to compare to. 237 241 * @return the true if this email address equals the other. 238 242 * @see java.lang.Object#equals(java.lang.Object) 239 243 */ 240 public boolean equals (Object obj)244 public boolean equals (Object obj) 241 245 { 242 246 boolean result = false; … … 261 265 * @return the hash code for this email. 262 266 */ 263 public int hashCode ()267 public int hashCode () 264 268 { 265 269 int hashCode = HashCodeUtil.hash(HashCodeUtil.SEED, mLocalPart);
