class FormattedLines {
    private final SortedMap<Integer, String> lines = new TreeMap<>();
    private String footer;
    private boolean limited;

    /*
     * Gets a count of the number of lines in the instance.
     */
    public int getCount() {
        return lines.size();
    }

    /**
     * @return the footer
     */
    public String getFooter() {
        return footer;
    }

    public void setFooter(String value) {
        footer = value;
    }

    /*
     * Gets a value indicating if lines were limited.
     */
    public boolean isLimited() {
        return limited;
    }

    /*
     * Sets a value indicating if lines were limited.
     */
    public void setLimited(boolean value) {
        limited = value;
    }

    /**
     * Removes the highest line from the instance.
     * @return a defined value
     * @throws NoSuchElementException if the instance is empty
     */
    public String pop() {
        return lines.remove(lines.lastKey());
    }

    /**
     * Sets the specified String line for the specified line number, replacing
     * any previous entry for the same line number.
     * @param lineno a value
     * @param line a defined instance
     * @return the former value or {@code null}
     */
    public String put(int lineno, String line) {
        if (line == null) {
            throw new IllegalArgumentException("line is null");
        }
        return lines.put(lineno, line);
    }

    /**
     * Creates a new instance with lines merged from this instance and
     * {@code other}. Any lines in common for the same line number are taken
     * from this instance rather than {@code other}; and likewise for
     * {@link #getFooter()}.
     * <p>
     * {@link #isLimited()} will be {@code true} if either is {@code true}, but
     * the value is suspect since it cannot be truly known if the merged result
     * is actually the unlimited result.
     * @param other a defined instance
     * @return a defined instance
     */
    public FormattedLines merge(FormattedLines other) {<FILL_FUNCTION_BODY>}

    @Override
    public String toString() {
        StringBuilder bld = new StringBuilder();
        for (String line : lines.values()) {
            bld.append(line);
        }
        String f = footer;
        if (f != null && limited) {
            bld.append(f);
        }
        return bld.toString();
    }
}

        FormattedLines res = new FormattedLines();
        res.lines.putAll(this.lines);
        for (Map.Entry<Integer, String> kv : other.lines.entrySet()) {
            res.lines.putIfAbsent(kv.getKey(), kv.getValue());
        }

        res.setFooter(this.footer != null ? this.footer : other.footer);
        res.setLimited(this.limited || other.limited);
        return res;
    
<no_super_class>