Class Host

  • All Implemented Interfaces:
    Serializable, Comparable<Host>

    public class Host
    extends Object
    implements Serializable, Comparable<Host>
    A class representing the host component of a URI reference.

    This class provides the parse(String) method, which parses a given string as the host component of a URI reference, according to RFC 3986. If parsing succeeds, it creates a Host object, classifying the parsed host into one of the specific types: "Registered Name", "IPv4 Address", "IPv6 Address" or "IPvFuture Address". If parsing fails due to invalid input string, an IllegalArgumentException will be thrown. The getType() method can be used to retrieve the type of the host.

    This class is immutable.

    Author:
    Hideki Ikeda
    See Also:
    RFC 3986 Uniform Resource Identifier (URI): Generic Syntax, Serialized Form
    • Method Detail

      • getValue

        public String getValue()
        Get the value of this Host object.
        Returns:
        The value of this Host object.
      • getType

        public HostType getType()
        Get the type of this Host object.
        Returns:
        The type of this Host object.
      • toString

        public String toString()
        Returns a string representation of this Host object. The string representation is the value of this Host object.
        Overrides:
        toString in class Object
        Returns:
        The string representation of this Host object.
      • equals

        public boolean equals​(Object obj)
        Compares this Host object with the specified object for equality. The comparison is based on the type and value of this Host object.
        Overrides:
        equals in class Object
        Parameters:
        obj - The object to be compared for equality with this Host object.
        Returns:
        true if the specified object is equal to this Host object.
      • hashCode

        public int hashCode()
        Returns a hash code value for this Host object. The hash code is generated based on the type and value of this Host object.
        Overrides:
        hashCode in class Object
        Returns:
        The hash code value for this Host object.
      • compareTo

        public int compareTo​(Host other)
        Compares this Host object with another Host object for order. The comparison is based on the hash code of the Host objects.
        Specified by:
        compareTo in interface Comparable<Host>
        Parameters:
        other - The Host object to be compared.
        Returns:
        0 if this Host object is equal to the specified Host object. A negative value if this Host object is less than the specified object. A positive value if this Host object is greater than the specified object.
        Throws:
        NullPointerException - If the specified Host object is null.