class Printer {

    public static String print(Collection<?> list, String title, int maxLines, Formatter formatter) {
        if (list == null) {
            return null;
        }

        // ograniczenie liczby linii od dolu (co najmniej 3 linie)
        int max = Math.max(maxLines, MIN_OUTPUT_LINES);

        int lines = Math.min(list.size(), maxLines);
        boolean printAll = maxLines == 0 || list.size() <= max;

        StringBuilder sb = new StringBuilder(lines * EXPECTED_LINE_LENGTH);
        sb.append(Formatter.NL);

        if (title != null) {
            sb.append(title).append(" (").append(list.size()).append(')').append(Formatter.NL);
        }

        int c = 0;
        for (Object e : list) {
            c++;
            String value = format(e, formatter);

            if (printAll || c <= max - 2 || c == list.size()) {
                sb.append(padNumber(c)).append(". ").append(value);
                sb.append(Formatter.NL);
            } else if (c == max - 1) {
                sb.append("  ...");
                sb.append(Formatter.NL);
            }
        }

        return sb.toString();
    }

    private  Printer();

}