Package com.globalmentor.net
Class EmailAddress
java.lang.Object
com.globalmentor.net.EmailAddress
- All Implemented Interfaces:
Resource
,Comparable<EmailAddress>
Value class for email addresses represented in the form specified by RFC 5322: Internet Message
Format.
- Author:
- Garret Wilson
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Characters
Email addressatext
characters as per RFC 5322.static final char
The beginning delimiter of adomain-literal
.static final char
The ending delimiter of adomain-literal
.static final Pattern
A regular expression pattern for matching the domain of an email addresses according to RFC 5322.static final Characters
Email addressdtext
characters as per RFC 5322.static final Pattern
A regular expression pattern for matching email addresses according to RFC 5322.static final int
The group for returning the domain of an email address from a matcher derived fromEMAIL_ADDRESS_PATTERN
.static final int
The group for returning the local part of an email address from a matcher derived fromEMAIL_ADDRESS_PATTERN
.static final char
The delimiter separating the local part from the domain.static final Pattern
A regular expression pattern for matching the local part of an email addresses according to RFC 5322.Fields inherited from interface com.globalmentor.net.Resource
URI_PROPERTY_NAME
-
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(EmailAddress emailAddress) Compares this object with the specified object for order.boolean
Determines if this object is equivalent to another object.static EmailAddress
fromString
(String input) Constructs an email address from a string.static String
getDomain
(CharSequence input) Returns the domain of an email address from a string.static String
getLocalPart
(CharSequence input) Returns the local part of an email address from a string.getURI()
int
hashCode()
static EmailAddress
Constructs an email address from its separate components.toString()
Constructs a string representation of the email address in its RFC 5322 format.
-
Field Details
-
ATEXT_CHARACTERS
Email addressatext
characters as per RFC 5322.Printable US-ASCII characters not including specials. Used for atoms.
-
DTEXT_CHARACTERS
Email addressdtext
characters as per RFC 5322. This definition does not include the obsoleteobs-dtext
from RFC 5322.Printable US-ASCII characters not including "[", "]", or "\".
-
LOCAL_PART_DOMAIN_DELIMITER
public static final char LOCAL_PART_DOMAIN_DELIMITERThe delimiter separating the local part from the domain.- See Also:
-
DOMAIN_LITERAL_BEGIN
public static final char DOMAIN_LITERAL_BEGINThe beginning delimiter of adomain-literal
.- See Also:
-
DOMAIN_LITERAL_END
public static final char DOMAIN_LITERAL_ENDThe ending delimiter of adomain-literal
.- See Also:
-
LOCAL_PART_PATTERN
A regular expression pattern for matching the local part of an email addresses according to RFC 5322. This pattern is derived from the regular expression provided at an answer to Using a regular expression to validate an email address. -
DOMAIN_PATTERN
A regular expression pattern for matching the domain of an email addresses according to RFC 5322. This pattern is derived from the regular expression provided at an answer to Using a regular expression to validate an email address. -
EMAIL_ADDRESS_PATTERN
A regular expression pattern for matching email addresses according to RFC 5322. This pattern is derived from the regular expression provided at an answer to Using a regular expression to validate an email address. -
EMAIL_ADDRESS_PATTERN_LOCAL_PART_GROUP
public static final int EMAIL_ADDRESS_PATTERN_LOCAL_PART_GROUPThe group for returning the local part of an email address from a matcher derived fromEMAIL_ADDRESS_PATTERN
.- See Also:
-
EMAIL_ADDRESS_PATTERN_DOMAIN_GROUP
public static final int EMAIL_ADDRESS_PATTERN_DOMAIN_GROUPThe group for returning the domain of an email address from a matcher derived fromEMAIL_ADDRESS_PATTERN
.- See Also:
-
-
Method Details
-
getLocalPart
- Returns:
- The local part of the email address.
-
getDomain
- Returns:
- The domain of the email address.
-
of
Constructs an email address from its separate components.- Parameters:
localPart
- The local part of the email address.domain
- The domain of the email address.- Returns:
- An email address with the given local part and domain.
- Throws:
NullPointerException
- if the given local part and/or domain isnull
.ArgumentSyntaxException
- if the given local part and/or domain violates RFC 5322.
-
fromString
Constructs an email address from a string.- Parameters:
input
- The string to be parsed as an email address.- Returns:
- An email address from the given string representation.
- Throws:
NullPointerException
- if the given character sequence isnull
.ArgumentSyntaxException
- if the input string violates RFC 5322.
-
hashCode
public int hashCode() -
equals
Determines if this object is equivalent to another object. This method considers another object equivalent if it is another email address with the same local part and domain. -
compareTo
Compares this object with the specified object for order. This implementation primarily by domain and secondarily by local part, ignoring case and locales.- Specified by:
compareTo
in interfaceComparable<EmailAddress>
- Parameters:
emailAddress
- The object to be compared.- Returns:
- A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
- See Also:
-
toString
Constructs a string representation of the email address in its RFC 5322 format. This implementation returns the canonical version of the email address. -
getURI
-
getLocalPart
Returns the local part of an email address from a string.- Parameters:
input
- The character sequence to be parsed as an email address.- Returns:
- The local part of the given email address.
- Throws:
NullPointerException
- if the given character sequence isnull
.ArgumentSyntaxException
- if the input string violates RFC 5322.
-
getDomain
Returns the domain of an email address from a string.- Parameters:
input
- The character sequence to be parsed as an email address.- Returns:
- The domain of the given email address.
- Throws:
NullPointerException
- if the given character sequence isnull
.ArgumentSyntaxException
- if the input string violates RFC 5322.
-