Package com.iizix

Class HostNameOrAddress


  • public class HostNameOrAddress
    extends java.lang.Object
    The host name and/or IP address, used to look-up region location information.
    Author:
    Christopher Mindus
    • Constructor Summary

      Constructors 
      ConstructorDescription
      HostNameOrAddress​(java.lang.String host)
      Constructs the region location from a host name or IP address (version 4 or 6).
      HostNameOrAddress​(java.net.InetAddress address)
      Constructs the region location from an IP address (version 4 or 6).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      booleanequals​(java.lang.Object obj)
      Checks if two region locations object are equal.
      java.net.InetAddressgetAddress()
      Gets the address.
      java.lang.StringgetHost()
      Gets the host name or address.
      inthashCode()
      Returns the hashCode.
      java.lang.StringtoString()
      Creates a string representation of the instance.
      • Methods inherited from class java.lang.Object

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

      • HostNameOrAddress

        public HostNameOrAddress​(java.net.InetAddress address)
        Constructs the region location from an IP address (version 4 or 6).
        Parameters:
        address - The IPv4/IPv6 address.
        Throws:
        java.lang.NullPointerException - If address is null.
      • HostNameOrAddress

        public HostNameOrAddress​(java.lang.String host)
                          throws java.net.UnknownHostException
        Constructs the region location from a host name or IP address (version 4 or 6).
        Parameters:
        host - The host name or IPv4/IPv6 address.
        Throws:
        java.lang.NullPointerException - If hostName is null.
        java.net.UnknownHostException - If hostName InetAddress cannot be determined.
    • Method Detail

      • getHost

        public java.lang.String getHost()
        Gets the host name or address.
        Returns:
        The host address if this instance was constructed from an {@link InetAddress}, otherwise the original host name or address as specified in the constructor.
      • getAddress

        public java.net.InetAddress getAddress()
        Gets the address.
        Returns:
        The InetAddress as IPv4 or IPv6 instance.
      • toString

        public java.lang.String toString()
        Creates a string representation of the instance.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A String formatted as host+"("+InetAddress.getHostAddress()+')'.
      • hashCode

        public int hashCode()
        Returns the hashCode.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        The hash code.
      • equals

        public boolean equals​(java.lang.Object obj)
        Checks if two region locations object are equal.

        Consider the following code:

         HostNameOrAddress h1 = new HostNameOrAddress("dns.google");
         HostNameOrAddress h2 = new HostNameOrAddress("8.8.8.8");
         InetAddress dnsGoogle = InetAddress.getByName("8.8.8.8");
         HostNameOrAddress h3 = new HostNameOrAddress(dnsGoogle);
         

        The instances h2 equals h3, but neither h2 or h3 equals h1.

        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - The object to compare with.
        Returns:
        Equals flag.