class MediaType {

  public static MediaType parse(String value) {
    try {
      List<String> components = Component.parseComponents(value);
      Map<String, String> parameters = new LinkedHashMap<>();
      for (int i = 2; i < components.size(); i += 2) {
        parameters.put(components.get(i), components.get(i + 1));
      }
      return of(components.get(0), components.get(1), parameters);
    } catch (IllegalArgumentException | IllegalStateException e) {
      throw new IllegalArgumentException(format("couldn't parse: '%s'", value), e);
    }
  }

  private  MediaType(String type, String subtype);
  private  MediaType(String type, String subtype, Map<String, String> parameters);

}