All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fxmisc.richtext.model.Replacement Maven / Gradle / Ivy

There is a newer version: 0.11.3
Show newest version
package org.fxmisc.richtext.model;

import java.util.Objects;

/**
 * Encapsulates the all the arguments for {@link EditableStyledDocument#replace(int, int, StyledDocument)}.
 */
public class Replacement {

    private final int start;
    public final int getStart() { return start; }

    private final int end;
    public final int getEnd() { return end; }

    private final ReadOnlyStyledDocument document;
    public final ReadOnlyStyledDocument getDocument() { return document; }

    public Replacement(int start, int end, ReadOnlyStyledDocument document) {
        this.start = start;
        this.end = end;
        this.document = document;
    }

    /**
     * Shortcut for {@code document.length() - (end - start)}
     */
    public int getNetLength() {
        return document.length() - (end - start);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Replacement) {
            Replacement that = (Replacement) obj;
            return Objects.equals(start, that.start) &&
                    Objects.equals(end, that.end) &&
                    Objects.equals(document, that.document);
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return Objects.hash(start, end, document);
    }

    @Override
    public String toString() {
        return String.format("Replacement(start=%s end=%s document=%s)", start, end, document);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy