public final class DnsName extends CacheableDataType implements Comparable<DnsName>
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.hp.com
switch1.rose.hp.com
switch3.cup.hp.com
switch3.rose.hp.com
switch4.rose.hp.com
switch13.rose.hp.com
switch14.rose.hp.com
switch22.rose.hp.com
switch23.rose.hp.com
zodiac.rose.hp.com
(Unresolvable DNS Name)
(Unresolvable DNS Name)
Modifier and Type | Field and Description |
---|---|
static DnsName |
UNRESOLVABLE
Our instance that represents an unresolvable DNS name.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(DnsName other)
Overridden to (a) ignore case, and (b) take embedded numbers into
account.
|
static DnsName |
dns(String s)
Convenience method that simply delegates to
valueOf(String) . |
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 s)
Returns an object that represents the value of the DNS name identified
by the specified string.
|
getRefQ, keyFromBytes
public static final DnsName UNRESOLVABLE
public String getHostName()
public String getDomainName()
public boolean isUnresolvable()
public int compareTo(DnsName other)
UNRESOLVABLE
instances will sort to the end.compareTo
in interface Comparable<DnsName>
other
- the other instance we are comparing topublic boolean equals(Object o)
Note that this comparison ignores case.
public static DnsName valueOf(String s)
If the parameter is an empty string (""
) then the instance
representing "unresolvable DNS name" is returned instead.
s
- the string representation of the DNS nameNullPointerException
- if the string is nullpublic static DnsName dns(String s)
valueOf(String)
.
Note that code can be written more concisely by using a static import
of this method; for example, the following two statements are
equivalent:
DnsName a = DnsName.valueOf("foo.hp.com"); DnsName a = dns("foo.hp.com");
s
- the string representation of the DNS nameNullPointerException
- if the string is nullCopyright © 2015. All Rights Reserved.