class JsonToImageTranslator {

  @VisibleForTesting
  static ImmutableSet<Port> portMapToSet(@Nullable Map<String, Map<?, ?>> portMap)
      throws BadContainerConfigurationFormatException {
    if (portMap == null) {
      return ImmutableSet.of();
    }
    ImmutableSet.Builder<Port> ports = new ImmutableSet.Builder<>();
    for (Map.Entry<String, Map<?, ?>> entry : portMap.entrySet()) {
      String port = entry.getKey();
      Matcher matcher = PORT_PATTERN.matcher(port);
      if (!matcher.matches()) {
        throw new BadContainerConfigurationFormatException(
            "Invalid port configuration: '" + port + "'.");
      }

      int portNumber = Integer.parseInt(matcher.group("portNum"));
      String protocol = matcher.group("protocol");
      ports.add(Port.parseProtocol(portNumber, protocol));
    }
    return ports.build();
  }

  private  JsonToImageTranslator();

}