code: public static int mapPort(Map<Integer, Integer> mapping, int port) {
      Integer mappedPort = mapping.get(port);
      if( mappedPort == null ) throw new RuntimeException("Could not map port "+port);
      return mappedPort;
    }
docs: Looks up a corresponding port number from a port mapping.
  @param mapping the port mapping
  @param port the key in the port map.
  @return the corresponding port number from the port mapping.
  @throws RuntimeException if a value could not be found.