Package org.kiwiproject.net
Class SimpleHostAndPort
- java.lang.Object
-
- org.kiwiproject.net.SimpleHostAndPort
-
public class SimpleHostAndPort extends Object
Inspired by Guava'sHostAndPortbut much simpler in implementation. (Just go look at the code inHostAndPort.fromString(String)if you don't believe me.) Because it is much simpler, it also only handles a very specific host/port format, which ishost: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.
-
-
Constructor Summary
Constructors Constructor Description SimpleHostAndPort()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SimpleHostAndPortfrom(String hostPortString)ParsehostPortStringassuming formathost:portstatic SimpleHostAndPortfrom(String hostPortString, String defaultHost, int defaultPort)ParsehostPortStringassuming formathost:port; if it is blank, use the specifieddefaultHostanddefaultPortvalues to create a linkSimpleHostAndPort.StringtoString()Return a string inhost:portformat.
-
-
-
Method Detail
-
from
public static SimpleHostAndPort from(String hostPortString, String defaultHost, int defaultPort)
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
public static SimpleHostAndPort from(String hostPortString)
ParsehostPortStringassuming formathost:port- Parameters:
hostPortString- a string containing host and port, e.g. foo.com:9000- Returns:
- a new SimpleHostAndPort instance
- Throws:
NullPointerException- ifhostPortStringis nullIllegalStateException- if not in the expected formatNumberFormatException- if port is not a valid number
-
-