Class EmailAddress

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(EmailAddress emailAddress)
      Compares this object with the specified object for order.
      boolean equals​(java.lang.Object object)
      Determines if this object is equivalent to another object.
      static EmailAddress fromString​(java.lang.String input)
      Constructs an email address from a string.
      java.lang.String getDomain()  
      static java.lang.String getDomain​(java.lang.CharSequence input)
      Returns the domain of an email address from a string.
      java.lang.String getLocalPart()  
      static java.lang.String getLocalPart​(java.lang.CharSequence input)
      Returns the local part of an email address from a string.
      java.net.URI getURI()  
      int hashCode()  
      static EmailAddress of​(java.lang.String localPart, java.lang.String domain)
      Constructs an email address from its separate components.
      java.lang.String toString()
      Constructs a string representation of the email address in its RFC 5322 format.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • getLocalPart

        public java.lang.String getLocalPart()
        Returns:
        The local part of the email address.
      • getDomain

        public java.lang.String getDomain()
        Returns:
        The domain of the email address.
      • of

        public static EmailAddress of​(java.lang.String localPart,
                                      java.lang.String domain)
                               throws ArgumentSyntaxException
        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:
        java.lang.NullPointerException - if the given local part and/or domain is null.
        ArgumentSyntaxException - if the given local part and/or domain violates RFC 5322.
      • fromString

        public static EmailAddress fromString​(java.lang.String input)
                                       throws ArgumentSyntaxException
        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:
        java.lang.NullPointerException - if the given character sequence is null.
        ArgumentSyntaxException - if the input string violates RFC 5322.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A hash code representing this object.
      • equals

        public boolean equals​(java.lang.Object object)
        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.
        Overrides:
        equals in class java.lang.Object
        Returns:
        true if the given object is an equivalent email address.
      • compareTo

        public int compareTo​(EmailAddress emailAddress)
        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 interface java.lang.Comparable<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:
        getDomain(), getLocalPart()
      • toString

        public java.lang.String toString()
        Constructs a string representation of the email address in its RFC 5322 format. This implementation returns the canonical version of the email address.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of the email address.
      • getURI

        public java.net.URI getURI()
        Specified by:
        getURI in interface Resource
        Returns:
        The resource identifier URI, or null if the identifier is not known.
      • getLocalPart

        public static java.lang.String getLocalPart​(java.lang.CharSequence input)
                                             throws ArgumentSyntaxException
        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:
        java.lang.NullPointerException - if the given character sequence is null.
        ArgumentSyntaxException - if the input string violates RFC 5322.
      • getDomain

        public static java.lang.String getDomain​(java.lang.CharSequence input)
                                          throws ArgumentSyntaxException
        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:
        java.lang.NullPointerException - if the given character sequence is null.
        ArgumentSyntaxException - if the input string violates RFC 5322.