Package com.globalmentor.net
Class DomainName
java.lang.Object
com.globalmentor.net.DomainName
Utilities and encapsulation of a domain name as defined in RFC 1035, DOMAIN NAMES -
IMPLEMENTATION AND SPECIFICATION.
- Author:
- Garret Wilson
- Implementation Note:
- The current implementation makes no validations of the domain name syntax other than a few simple rules related to delimiter location and number.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final char
The dot.
delimiter for domain name segments.static final DomainName
An empty relative domain name.static final DomainName
The root domain name as per RFC 1035 -
Method Summary
Modifier and TypeMethodDescriptionChecks to see if the domain name is absolute.Checks to see if this domain name is relative.boolean
static Optional<DomainName>
findGreatestCommonBase
(Iterable<DomainName> domainNames) Determines the domain name with the longest sequence of common base domains.int
hashCode()
boolean
Determines if the domain name is absolute; that is, it ends with a delimiter '.' character.boolean
isEmpty()
Determines if this is an empty domain name; that is, one consisting of only an empty string""
.boolean
Determines if this domain name is relative; that is, it does not end with a delimiter '.' character.boolean
isRoot()
Determines if this the root domain name; that is, one consisting of only the '.' delimiter.static DomainName
Returns a domain name from a string form of the name.relativize
(DomainName domainName) Relativizes the other domain against this name.resolve
(DomainName domainName) Resolves another domain name against this domain name.toString()
-
Field Details
-
DELIMITER
public static final char DELIMITERThe dot.
delimiter for domain name segments.- See Also:
-
EMPTY
An empty relative domain name. -
ROOT
The root domain name as per RFC 1035
-
-
Method Details
-
of
Returns a domain name from a string form of the name.- Parameters:
name
- The string form of the domain name; empty names are allowed.- Returns:
- A domain name from the string.
- Throws:
IllegalArgumentException
- if a domain name other than the root begins with a dot.
character, or has two subsequent dot characters.- See Also:
-
isAbsolute
public boolean isAbsolute()Determines if the domain name is absolute; that is, it ends with a delimiter '.' character.- API Note:
- An absolute domain name is also referred to as a Fully Qualified Domain Name (FQDN).
- Returns:
true
if the domain name is absolute.- See Also:
-
checkArgumentAbsolute
Checks to see if the domain name is absolute. If the domain name is not absolute, an exception is thrown.- Returns:
- This domain name.
- Throws:
IllegalArgumentException
- if the domain name is not absolute.- See Also:
-
isEmpty
public boolean isEmpty()Determines if this is an empty domain name; that is, one consisting of only an empty string""
.- API Note:
- An empty domain name is a relative domain name.
- Returns:
true
if the domain name is empty.- See Also:
-
isRoot
public boolean isRoot()Determines if this the root domain name; that is, one consisting of only the '.' delimiter.- API Note:
- The root domain is an absolute domain.
- Returns:
true
if the domain name is the root domain.- See Also:
-
isRelative
public boolean isRelative()Determines if this domain name is relative; that is, it does not end with a delimiter '.' character.- Implementation Specification:
- This implementation delegates to
isAbsolute()
. - Returns:
true
if the domain name is relative.- See Also:
-
checkArgumentRelative
Checks to see if this domain name is relative. If the domain name is not relative, an exception is thrown.- Returns:
- This domain name.
- Throws:
IllegalArgumentException
- if the domain name is not relative.- See Also:
-
relativize
Relativizes the other domain against this name. If the other domain end with the identical segments of this domain name, the given domain name is returned. A domain name relativized against itself returns an empty domain name.- Parameters:
domainName
- The domain name to relativize against this one.- Returns:
- A domain name that, when resolved against this domain, will result in the given domain.
- See Also:
-
resolve
Resolves another domain name against this domain name. If the other domain name is absolute, the other domain name is returned. If the other domain name is empty, this domain name is returned. If the other domain is not empty but this domain is empty, the other domain name is returned. Otherwise, the other domain is prepended to this domain name using theDELIMITER
delimiter, without regard to whether this- Parameters:
domainName
- The domain name to resolve against this one- Returns:
- The other domain name resolved against this one.
- See Also:
-
hashCode
public int hashCode() -
equals
-
toString
-
findGreatestCommonBase
public static Optional<DomainName> findGreatestCommonBase(@Nonnull Iterable<DomainName> domainNames) Determines the domain name with the longest sequence of common base domains. For example if any combination of the domain nameswww.example.com.
,test.example.com.
, andexample.com.
are passed, the common base domain nameexample.com.
is returned.This method requires that all domain names be relative or all be absolute.
- API Note:
- This method does not make any checks to determine whether a segment is empty, e.g.
"foo..bar"
. - Parameters:
domainNames
- The domain names to check.- Returns:
- The greatest base domain name, which may not be present if there is no longest base.
- Throws:
NullPointerException
- if the iterable isnull
or contains anull
value.IllegalArgumentException
- if both relative and absolute domains names are passed.
-