- java.lang.Object
-
- com.aoapps.net.DomainName
-
- All Implemented Interfaces:
DtoFactory<DomainName>
,FastExternalizable
,Internable<DomainName>
,Externalizable
,Serializable
,Comparable<DomainName>
public final class DomainName extends Object implements Comparable<DomainName>, FastExternalizable, DtoFactory<DomainName>, Internable<DomainName>
Represents a DNS domain name. Domain names must:- Be non-null
- Be non-empty
- May not be "default" (case-insensitive) - to avoid conflicts with Cyrus no-domain configurations.
- Conform to definition in https://wikipedia.org/wiki/Hostname#Internet_hostnames and https://wikipedia.org/wiki/DNS_label#Parts_of_a_domain_name
- May be "localhost" or "localhost.localdomain" - other checks that conflict with this are skipped.
- Last domain label must be alphabetic (not be all numeric)
- Last label must be a valid top level domain.
- For reverse IP address delegation, if the domain ends with ".in-addr.arpa", the first label may also be in the format "##/##".
- Not end with a period (.)
- Author:
- AO Industries, Inc.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static DomainName
LOCALHOST
static DomainName
LOCALHOST_LOCALDOMAIN
static int
MAX_LENGTH
-
Constructor Summary
Constructors Constructor Description DomainName()
Deprecated.Only required for implementation, do not use directly.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static int
compareLabels(String labels1, String labels2)
TODO: Should not be public once all classes using validator types.int
compareTo(DomainName other)
Sorts by top level domain, then subdomain, then sub-subdomain, ...boolean
equals(Object obj)
DomainName
getDto()
long
getSerialVersionUID()
int
hashCode()
DomainName
intern()
Interns this domain much in the same fashion asString.intern()
.boolean
isArpa()
static boolean
isArpa(String domain)
Checks if ends with .in-addr.arpa (case insensitive).void
readExternal(ObjectInput in)
String
toLowerCase()
Gets the lower-case form of the domain.String
toString()
static ValidationResult
validate(String domain)
Validates a domain name, but doesn't allow an ending period.static DomainName
valueOf(String domain)
void
writeExternal(ObjectOutput out)
-
-
-
Field Detail
-
MAX_LENGTH
public static final int MAX_LENGTH
- See Also:
- Constant Field Values
-
LOCALHOST
public static final DomainName LOCALHOST
-
LOCALHOST_LOCALDOMAIN
public static final DomainName LOCALHOST_LOCALDOMAIN
-
-
Constructor Detail
-
DomainName
@Deprecated public DomainName()
Deprecated.Only required for implementation, do not use directly.- See Also:
FastExternalizable
-
-
Method Detail
-
isArpa
public static boolean isArpa(String domain)
Checks if ends with .in-addr.arpa (case insensitive).Performance measurement of new implementation versus old (10,000,000 iterations): "This is not an arpa" Old: 2911.130028 ms New: 37.805258 ms Improvement: 77.0 times "this is not an arpa" Old: 1746.381520 ms New: 50.407891 ms Improvement: 34.7 times "subnet0.144.71.64.in-addr.arpa" Old: 2712.463721 ms New: 284.561373 ms Improvement: 9.5 times
-
validate
public static ValidationResult validate(String domain)
Validates a domain name, but doesn't allow an ending period.- See Also:
DomainLabel.validate(java.lang.String)
-
valueOf
public static DomainName valueOf(String domain) throws ValidationException
- Parameters:
domain
- whennull
, returnsnull
- Throws:
ValidationException
-
compareLabels
public static int compareLabels(String labels1, String labels2)
TODO: Should not be public once all classes using validator types.
-
compareTo
public int compareTo(DomainName other)
Sorts by top level domain, then subdomain, then sub-subdomain, ...- Specified by:
compareTo
in interfaceComparable<DomainName>
-
toLowerCase
public String toLowerCase()
Gets the lower-case form of the domain. If two different domains are interned and their toLowerCase is the same String instance, then they are equal in case-insensitive manner.
-
isArpa
public boolean isArpa()
-
intern
public DomainName intern()
Interns this domain much in the same fashion asString.intern()
.- Specified by:
intern
in interfaceInternable<DomainName>
- See Also:
String.intern()
-
getDto
public DomainName getDto()
- Specified by:
getDto
in interfaceDtoFactory<DomainName>
-
getSerialVersionUID
public long getSerialVersionUID()
- Specified by:
getSerialVersionUID
in interfaceFastExternalizable
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
-