@PublicAPI(stability=UNCOMMITTED, mayInstantiate=false, mayExtend=false, mayInvoke=true) public final class HostPort extends Object implements Comparable<HostPort>
Due to the possibility of live network configuration changes, instances of this class are not intended for caching and should be rebuilt on demand.
Note: this class has a natural ordering that is inconsistent with equals.
Modifier and Type | Field and Description |
---|---|
static String |
WILDCARD_ADDRESS
The wildcard address allows to instruct a server to
"listen to all addresses".
|
Constructor and Description |
---|
HostPort(String host,
int port)
Creates a new
HostPort object with the specified port
number but no explicit host. |
Modifier and Type | Method and Description |
---|---|
static HostPort |
allAddresses(int port)
Returns a a new HostPort for all addresses, also known as a wildcard
address.
|
int |
compareTo(HostPort o) |
boolean |
equals(Object obj)
Returns
true if the provided Object is a HostPort object with the
same host name and port than this HostPort object. |
String |
getHost()
Retrieves the host for this
HostPort object. |
int |
getPort()
Retrieves the port number for this
HostPort object. |
int |
hashCode()
Retrieves a hash code for this HostPort object.
|
boolean |
isEquivalentTo(HostPort other)
Checks whether the supplied HostPort is an equivalent to the current
HostPort.
|
boolean |
isLocalAddress()
Whether the current object represents a local address.
|
static boolean |
isLocalAddress(InetAddress address)
Returns
true if the provided InetAddress represents the
address of one of the interfaces on the current host machine. |
static HostPort |
localAddress(int port)
Builds a new instance of
HostPort representing the local machine
with the supplied port. |
InetSocketAddress |
toInetSocketAddress()
Converts the current object to an equivalent
InetSocketAddress
object. |
static Set<String> |
toLowerCaseStrings(Set<HostPort> hostPorts)
Converts a set of
HostPort s to a new set where each host/port is converted to a
lowercase string. |
String |
toString()
Returns a string representation of this
HostPort object. |
static String |
toString(String host,
int port)
Returns a string representation of the provided host and port.
|
static HostPort |
valueOf(String hostPort)
Creates a new
HostPort object by parsing the supplied "hostName:port" String URL. |
static HostPort |
valueOf(String hostPort,
Integer defaultPort)
Creates a new
HostPort object by parsing the supplied "hostName:port" String URL. |
public static final String WILDCARD_ADDRESS
public static boolean isLocalAddress(InetAddress address)
true
if the provided InetAddress
represents the
address of one of the interfaces on the current host machine.address
- The network address.true
if the provided InetAddress
represents the
address of one of the interfaces on the current host machine.public static Set<String> toLowerCaseStrings(Set<HostPort> hostPorts)
HostPort
s to a new set where each host/port is converted to a
lowercase string.hostPorts
- the set of host ports to convertpublic static HostPort allAddresses(int port)
port
- The port number for the new HostPort
object.public static HostPort localAddress(int port)
HostPort
representing the local machine
with the supplied port.public static HostPort valueOf(String hostPort) throws NumberFormatException, IllegalArgumentException
HostPort
object by parsing the supplied "hostName:port" String URL.
This method also accepts IPV6 style "[hostAddress]:port" String URLs.hostPort
- a String representing the URL made of a host and a port.HostPort
built from the supplied string.NumberFormatException
- If the "port" in the supplied string cannot be converted to an intIllegalArgumentException
- if no port could be found in the supplied string, or if the port
is not a valid port numberpublic static HostPort valueOf(String hostPort, Integer defaultPort) throws IllegalArgumentException
HostPort
object by parsing the supplied "hostName:port" String URL.
This method also accepts IPV6 style "[hostAddress]:port" String URLs. Values without ports
are allowed if a default port is provided.hostPort
- a String representing the URL made of a host and a port.defaultPort
- if not null
then a default port to use if none is present in the string.HostPort
built from the supplied string.NumberFormatException
- If the "port" in the supplied string cannot be converted to an intIllegalArgumentException
- if no port could be found in the supplied string, or if the port
is not a valid port numberpublic String getHost()
HostPort
object.HostPort
object, or
null
if none was provided.public int getPort()
HostPort
object.HostPort
object.public boolean isLocalAddress()
public InetSocketAddress toInetSocketAddress() throws UnknownHostException
InetSocketAddress
object.InetSocketAddress
equivalent of the current object.UnknownHostException
- If the current host name cannot be resolved to an
InetAddress
public String toString()
HostPort
object. It will be
the host element (or nothing if no host was given) followed by a colon and
the port number.public static String toString(String host, int port)
host
- the host nameport
- the port numberpublic boolean isEquivalentTo(HostPort other)
other
- the HostPort to compare to "this"InetAddress.getAllByName(String)
throws an UnknownHostException.public int compareTo(HostPort o)
compareTo
in interface Comparable<HostPort>
public boolean equals(Object obj)
true
if the provided Object is a HostPort object with the
same host name and port than this HostPort object.Copyright © 2010-2017 ForgeRock AS. All Rights Reserved.