SubSequence.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package org.cnnlp.data.splitter;
  2. import org.jetbrains.annotations.NotNull;
  3. import java.io.Serializable;
  4. import java.util.Objects;
  5. public class SubSequence implements Serializable {
  6. String text;
  7. int startOffset;
  8. int endOffset;
  9. public SubSequence() {
  10. }
  11. public SubSequence(String text, int startOffset, int endOffset) {
  12. this.text = text;
  13. this.startOffset = startOffset;
  14. this.endOffset = endOffset;
  15. }
  16. // @Override
  17. // public int compareTo(@NotNull SubSequence o) {
  18. // return startOffset - o.startOffset;
  19. // }
  20. public String getText() {
  21. return text;
  22. }
  23. public void setText(String text) {
  24. this.text = text;
  25. }
  26. public int getStartOffset() {
  27. return startOffset;
  28. }
  29. public void setStartOffset(int startOffset) {
  30. this.startOffset = startOffset;
  31. }
  32. public int getEndOffset() {
  33. return endOffset;
  34. }
  35. public void setEndOffset(int endOffset) {
  36. this.endOffset = endOffset;
  37. }
  38. public void incrementalOffset(int offset) {
  39. startOffset = startOffset + offset;
  40. endOffset = endOffset + offset;
  41. }
  42. @Override
  43. public boolean equals(Object o) {
  44. if (this == o) return true;
  45. if (o == null || getClass() != o.getClass()) return false;
  46. SubSequence that = (SubSequence) o;
  47. return startOffset == that.startOffset && endOffset == that.endOffset && Objects.equals(text, that.text);
  48. }
  49. @Override
  50. public int hashCode() {
  51. return Objects.hash(text, startOffset, endOffset);
  52. }
  53. @Override
  54. public String toString() {
  55. return "SubSequence{" +
  56. "text='" + text + '\'' +
  57. ", startOffset=" + startOffset +
  58. ", endOffset=" + endOffset +
  59. '}';
  60. }
  61. public static SubSequence build(String text, int startOffset, int endOffset) {
  62. SubSequence ss = new SubSequence(text, startOffset, endOffset);
  63. return ss;
  64. }
  65. }