org.fxmisc.richtext.model.Replacement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of richtextfx Show documentation
Show all versions of richtextfx Show documentation
Rich-text area for JavaFX
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);
}
}