static PortMappingWithName parsePortMapping(final String portSpec) { final Matcher matcher = PATTERN.matcher(portSpec); if (!matcher.matches()) { throw new IllegalArgumentException("Bad port mapping: " + portSpec); } final String name = matcher.group("n"); final String ip = matcher.group("ip"); final int internal = Integer.parseInt(matcher.group("i")); final Integer external = nullOrInteger(matcher.group("e")); final String protocol = fromNullable(matcher.group("p")).or(TCP); return PortMappingWithName.create(name, PortMapping.builder() .ip(ip) .internalPort(internal) .externalPort(external) .protocol(protocol) .build()); }