rsvp.model
Class EmailAddress

java.lang.Object
  extended by rsvp.model.EmailAddress
All Implemented Interfaces:
java.io.Serializable, EmailAddressInterface

public class EmailAddress
extends java.lang.Object
implements java.io.Serializable, EmailAddressInterface

This class models an email address.

Author:
willb
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface rsvp.model.EmailAddressInterface
serialVersionUID
 
Constructor Summary
EmailAddress(java.lang.String email)
          Creates a new EmailAddress from the given String, which must be a valid email address, as defined by EmailAddress.isValid(String).
 
Method Summary
 java.lang.String getDisplayEmail()
          Returns the "displayable form" of the responder's email address.
 java.lang.String getEmail()
          Returns the address, as a String.
static boolean isValid(java.lang.String address)
          Determines whether or not a given String corresponds to a valid email address.
 void setEmail(java.lang.String email)
          Sets this email address to the given String.
 java.lang.String toString()
          Returns a String representation of this email address.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EmailAddress

public EmailAddress(java.lang.String email)
Creates a new EmailAddress from the given String, which must be a valid email address, as defined by EmailAddress.isValid(String).

Parameters:
email - a valid email address
Method Detail

isValid

public static boolean isValid(java.lang.String address)
Determines whether or not a given String corresponds to a valid email address. A valid email address:
  1. Is of the general form username@domain. That is, it has exactly one "@" sign.
  2. Has at least one period in the domain section.
Therefore, fred@bedrock.gov is a valid email address, but fred123, f@r@ed.com, and fred@bedrock are not.

Parameters:
address -
Returns:
true if and only if address is valid

toString

public java.lang.String toString()
Description copied from interface: EmailAddressInterface
Returns a String representation of this email address.

Specified by:
toString in interface EmailAddressInterface
Overrides:
toString in class java.lang.Object
Returns:
a String representation of this email address.

setEmail

public void setEmail(java.lang.String email)
Description copied from interface: EmailAddressInterface
Sets this email address to the given String. If the given String does not correspond to a "valid" email address, this method will throw a BogusParameterException.

Specified by:
setEmail in interface EmailAddressInterface
Parameters:
email - an email address; must be "valid," as defined by EmailAddress.isValid(String)

getDisplayEmail

public java.lang.String getDisplayEmail()
Description copied from interface: EmailAddressInterface

Returns the "displayable form" of the responder's email address. This is obscured somewhat to prevent spam. The "displayable form" of an email address consists of:

  1. the username (that is, the part before the "@"),
  2. an at symbol,
  3. the first character of the domain name,
  4. an ellipsis (...), and
  5. the top-level domain of the domain name (e.g. com, org, or edu)

As an example, the email address fred@flintstones.bedrock.gov would have the displayable form fred@f...gov

Precondition: this EmailAddress has been initialized with a String corresponding to a valid email address. If this is not the case, this method will throw a StateException.

Specified by:
getDisplayEmail in interface EmailAddressInterface
Returns:
the "displayable form" of the responder's email address.

getEmail

public java.lang.String getEmail()
Description copied from interface: EmailAddressInterface

Returns the address, as a String.

Precondition: this EmailAddress has been initialized with a String corresponding to a valid email address. If this is not the case, this method will throw an exception.

Specified by:
getEmail in interface EmailAddressInterface
Returns:
the address, as a String.