com.h3c.util.ip

## Class DnsName

- java.lang.Object
- - com.h3c.util.cache.CacheableDataType
  - - com.h3c.util.ip.DnsName

- All Implemented Interfaces:
    Serializable, Comparable<DnsName>

      public final class DnsName
      extends CacheableDataType
      implements Comparable<DnsName>

  Represents a DNS name.

  All constructors for this class are private. Creating instances of `DnsName` is done via the static `valueOf(java.lang.String)` methods on the class. Note that a special value representing "Unresolvable" can be obtained via the `UNRESOLVABLE` public field.

  Instances of this class are immutable, making them inherently threadsafe.

  This class overrides `equals(java.lang.Object)` and `hashCode()` so that instances play nicely with the Collection classes.

  Implements the `Comparable` interface to ensure that a sorted list of DnsNames is presented in an intuitive order. In particular, case is ignored, and numeric suffixes are taken into account. Also note that "Unresolvable" instances are sorted to the end of the list. For example:

  - `switch1.cup.h3c.com`
  - `switch1.rose.h3c.com`
  - `switch3.cup.h3c.com`
  - `switch3.rose.h3c.com`
  - `switch4.rose.h3c.com`
  - `switch13.rose.h3c.com`
  - `switch14.rose.h3c.com`
  - `switch22.rose.h3c.com`
  - `switch23.rose.h3c.com`
  - `zodiac.rose.h3c.com`
  - `(Unresolvable DNS Name)`
  - `(Unresolvable DNS Name)`
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static DnsName` | `UNRESOLVABLE` Our instance that represents an unresolvable DNS name.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compareTo(DnsName other)` Overridden to (a) ignore case, and (b) take embedded numbers into account.
    `boolean` | `equals(Object o)`
    `String` | `getDomainName()` Returns the domain name; that is, everything after the first dot.
    `String` | `getHostName()` Returns the host name; that is, everything up to (but not including) the first dot.
    `int` | `hashCode()`
    `boolean` | `isUnresolvable()` Returns true if this instance is the "unresolvable" instance.
    `String` | `toString()`
    `static DnsName` | `valueOf(String str)` Returns an object that represents the value of the DNS name identified by the specified string.

    - ### Methods inherited from class com.h3c.util.cache.CacheableDataType

      `getRefQ, keyFromBytes`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### UNRESOLVABLE

          public static final DnsName UNRESOLVABLE

      Our instance that represents an unresolvable DNS name.

  - ### Method Detail

    - #### getHostName

          public String getHostName()

      Returns the host name; that is, everything up to (but not including) the first dot.
      Returns:
        the host name portion

    - #### getDomainName

          public String getDomainName()

      Returns the domain name; that is, everything after the first dot.
      Returns:
        the domain name portion

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### isUnresolvable

          public boolean isUnresolvable()

      Returns true if this instance is the "unresolvable" instance.
      Returns:
        true if this is the "unresolvable" instance

    - #### compareTo

          public int compareTo(DnsName other)

      Overridden to (a) ignore case, and (b) take embedded numbers into account. Note that `UNRESOLVABLE` instances will sort to the end.
      Specified by:
        `compareTo` in interface `Comparable<DnsName>`
      Parameters:
        `other` - the other instance we are comparing to
      Returns:
        a number less than, equal to, or greater than zero as this instance is earlier than, the same as, or later than the other in natural sort order

    - #### equals

          public boolean equals(Object o)

      Note that this comparison ignores case.

      Overrides:
        `equals` in class `Object`
      Parameters:
        `o` - the other instance to compare to
      Returns:
        true if this instance is equivalent to the specified instance

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### valueOf

          public static DnsName valueOf(String str)

      Returns an object that represents the value of the DNS name identified by the specified string. Note that the string is trimmed of whitespace first.

      If the parameter is an empty string (`""`) then the instance representing "unresolvable DNS name" is returned instead.

      Parameters:
        `str` - the string representation of the DNS name
      Returns:
        an object representing the specified DNS name
      Throws:
        `NullPointerException` - if the string is null

Copyright © 2014. All Rights Reserved.