Class SimpleHostAndPort


  • public class SimpleHostAndPort
    extends Object
    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.

    • Constructor Detail

      • SimpleHostAndPort

        public SimpleHostAndPort()
    • Method Detail

      • from

        public static SimpleHostAndPort from​(String hostPortString,
                                             String defaultHost,
                                             int defaultPort)
        Parse hostPortString assuming format host:port; if it is blank, use the specified defaultHost and defaultPort values to create a link SimpleHostAndPort.

        No validation is performed on the default values.

        Parameters:
        hostPortString - a string containing host and port, e.g. acme.com:8001
        defaultHost - a default host if the host/port string is blank
        defaultPort - a default port if the host/port string is blank
        Returns:
        a new SimpleHostAndPort instance
      • toString

        public String toString()
        Return a string in host:port format.
        Overrides:
        toString in class Object