class Converter<T> {
    final Class<T> type;

    Converter(Class<T> type) {
      this.type = type;
    }

    boolean appliesTo(Object subject) {
      return subject != null && type.isAssignableFrom(subject.getClass());
    }

    String convert(Object subject) {
      return toString(type.cast(subject));
    }

    abstract String toString(T subject);
  }

  public Errors() {
  }

  /** Returns the formatted message for an exception with the specified messages. */
  public static String format(String heading, Collection<ErrorMessage> errorMessages) {<FILL_FUNCTION_BODY>

    @SuppressWarnings("resource")
    Formatter fmt = new Formatter().format(heading).format(":%n%n");
    int index = 1;
    boolean displayCauses = getOnlyCause(errorMessages) == null;

    for (ErrorMessage errorMessage : errorMessages) {
      fmt.format("%s) %s%n", index++, errorMessage.getMessage());

      Throwable cause = errorMessage.getCause();
      if (displayCauses && cause != null) {
        StringWriter writer = new StringWriter();
        cause.printStackTrace(new PrintWriter(writer));
        fmt.format("Caused by: %s", writer.getBuffer());
      }

      fmt.format("%n");
    }

    if (errorMessages.size() == 1)
      fmt.format("1 error");
    else
      fmt.format("%s errors", errorMessages.size());

    return fmt.toString();
  
<no_super_class>