Package org.kiwiproject.net
Class SimpleHostAndPort
java.lang.Object
org.kiwiproject.net.SimpleHostAndPort
Inspired by Guava's
HostAndPort but much simpler in implementation.
(Just go look at the code in HostAndPort.fromString(String) if you don't believe me.)
Because it is much simpler, it also only handles a very specific host/port format, which is host:port.
It also does not attempt to validate anything about the host or port, e.g. it will happily accept a negative port value or a one-character long host name.
-
Method Summary
Modifier and TypeMethodDescriptionprotected booleanbooleanstatic SimpleHostAndPortParsehostPortStringassuming formathost:portstatic SimpleHostAndPortParsehostPortStringassuming formathost:port; if it is blank, use the specifieddefaultHostanddefaultPortvalues to create a linkSimpleHostAndPort.getHost()intgetPort()inthashCode()toString()Return a string inhost:portformat.
-
Method Details
-
from
ParsehostPortStringassuming formathost:port; if it is blank, use the specifieddefaultHostanddefaultPortvalues to create a linkSimpleHostAndPort.No validation is performed on the default values.
- Parameters:
hostPortString- a string containing host and port, e.g. acme.com:8001defaultHost- a default host if the host/port string is blankdefaultPort- a default port if the host/port string is blank- Returns:
- a new SimpleHostAndPort instance
-
from
ParsehostPortStringassuming formathost:port- Parameters:
hostPortString- a string containing host and port, e.g. foo.com:9000- Returns:
- a new SimpleHostAndPort instance
- Throws:
IllegalStateException- if not in the expected formatIllegalArgumentException- if hostPortString is blank or port is not a valid number- Implementation Note:
- Does no validation on the host part
-
toString
Return a string inhost:portformat. -
equals
-
canEqual
-
hashCode
public int hashCode() -
getHost
-
getPort
public int getPort()
-