Record Class HostAndPort
java.lang.Object
java.lang.Record
eu.cloudnetservice.driver.network.HostAndPort
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionHostAndPort(@NonNull String host, int port) Constructs a new host and port instance, validating the port. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.static @NonNull HostAndPortfromSocketAddress(@NonNull SocketAddress socketAddress) Tries to convert the given socket address into a host and port, throwing an exception if not possible.final inthashCode()Returns a hash code value for this object.host()Returns the value of thehostrecord component.intport()Returns the value of theportrecord component.toString()booleanChecks if this host and port has a port provided.
-
Field Details
-
host
-
port
private final int portThe field for theportrecord component. -
NO_PORT
public static final int NO_PORT- See Also:
-
-
Constructor Details
-
HostAndPort
Constructs a new host and port instance, validating the port.- Parameters:
host- the host of the address.port- the port of the address, or -1 if no port is given.- Throws:
NullPointerException- if the given host is null.IllegalArgumentException- if the given port exceeds the port range.
-
-
Method Details
-
fromSocketAddress
@Contract("_ -> new") @NonNull public static @NonNull HostAndPort fromSocketAddress(@NonNull @NonNull SocketAddress socketAddress) Tries to convert the given socket address into a host and port, throwing an exception if not possible.- Parameters:
socketAddress- the socket address to convert.- Returns:
- the created host and port based on the given address.
- Throws:
NullPointerException- if the given socket address is null.IllegalArgumentException- if the given socket address type cannot be converted.
-
validPort
public boolean validPort()Checks if this host and port has a port provided. No port might be provided if the connection comes for example from a unix domain socket.- Returns:
- true if this host and port has a port given, false otherwise.
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
host
-
port
public int port()Returns the value of theportrecord component.- Returns:
- the value of the
portrecord component
-