From b31cfd7cf3e322554bf4d8860b17b6f45f9dda13 Mon Sep 17 00:00:00 2001 From: Antal K Date: Tue, 22 Jun 2021 15:42:54 +0200 Subject: [PATCH] no natural sort for ComparableMark --- .../openoffice/rangesort/RangeSortVisual.java | 48 +++++-------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/jabref/model/openoffice/rangesort/RangeSortVisual.java b/src/main/java/org/jabref/model/openoffice/rangesort/RangeSortVisual.java index 969f9fed44e..e971e7ea67c 100644 --- a/src/main/java/org/jabref/model/openoffice/rangesort/RangeSortVisual.java +++ b/src/main/java/org/jabref/model/openoffice/rangesort/RangeSortVisual.java @@ -3,7 +3,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Objects; import org.jabref.model.openoffice.uno.NoDocumentException; import org.jabref.model.openoffice.uno.UnoScreenRefresh; @@ -73,7 +72,7 @@ public static List> visualSort(List> input input.getIndexInPosition(), input)); } - Collections.sort(set); + Collections.sort(set, RangeSortVisual::compareTopToBottomLeftToRight); if (set.size() != inputSize) { throw new IllegalStateException("visualSort: set.size() != inputSize"); @@ -115,6 +114,17 @@ private static Point findPositionOfTextRange(XTextRange range, XTextViewCursor c return cursor.getPosition(); } + private static int compareTopToBottomLeftToRight(ComparableMark a, ComparableMark b) { + + if (a.position.Y != b.position.Y) { + return a.position.Y - b.position.Y; + } + if (a.position.X != b.position.X) { + return a.position.X - b.position.X; + } + return a.indexInPosition - b.indexInPosition; + } + /** * A reference mark name paired with its visual position. * @@ -123,7 +133,7 @@ private static Point findPositionOfTextRange(XTextRange range, XTextViewCursor c * * Used for sorting reference marks by their visual positions. */ - private static class ComparableMark implements Comparable> { + private static class ComparableMark { private final Point position; private final int indexInPosition; @@ -135,42 +145,10 @@ public ComparableMark(Point position, int indexInPosition, T content) { this.content = content; } - @Override - public int compareTo(ComparableMark other) { - - if (position.Y != other.position.Y) { - return position.Y - other.position.Y; - } - if (position.X != other.position.X) { - return position.X - other.position.X; - } - return indexInPosition - other.indexInPosition; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (o instanceof ComparableMark) { - ComparableMark other = (ComparableMark) o; - return ((this.position.X == other.position.X) - && (this.position.Y == other.position.Y) - && (this.indexInPosition == other.indexInPosition) - && Objects.equals(this.content, other.content)); - } - return false; - } - public T getContent() { return content; } - @Override - public int hashCode() { - return Objects.hash(position, indexInPosition, content); - } } }