diff options
-rw-r--r-- | subprojects/store/src/main/java/tools/refinery/store/map/internal/MapCursor.java | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapCursor.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapCursor.java index f874137b..50fcfcd3 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapCursor.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapCursor.java | |||
@@ -117,7 +117,12 @@ public class MapCursor<K, V> implements Cursor<K, V> { | |||
117 | * same position. | 117 | * same position. |
118 | */ | 118 | */ |
119 | public static <K, V> int compare(MapCursor<K, V> cursor1, MapCursor<K, V> cursor2) { | 119 | public static <K, V> int compare(MapCursor<K, V> cursor1, MapCursor<K, V> cursor2) { |
120 | // two cursors are equally deep | 120 | // Checking the state of the cursors |
121 | if(!cursor1.isTerminated() && cursor2.isTerminated()) return -1; | ||
122 | else if(cursor1.isTerminated() && !cursor2.isTerminated()) return 1; | ||
123 | else if(cursor1.isTerminated() && cursor2.isTerminated()) return 0; | ||
124 | |||
125 | // If the state does not determine the order, then compare @nodeIndexStack. | ||
121 | Iterator<Integer> stack1 = cursor1.nodeIndexStack.descendingIterator(); | 126 | Iterator<Integer> stack1 = cursor1.nodeIndexStack.descendingIterator(); |
122 | Iterator<Integer> stack2 = cursor2.nodeIndexStack.descendingIterator(); | 127 | Iterator<Integer> stack2 = cursor2.nodeIndexStack.descendingIterator(); |
123 | if (stack1.hasNext()) { | 128 | if (stack1.hasNext()) { |
@@ -137,6 +142,8 @@ public class MapCursor<K, V> implements Cursor<K, V> { | |||
137 | // stack 2 has more element, thus stack 2 is deeper | 142 | // stack 2 has more element, thus stack 2 is deeper |
138 | return 1; | 143 | return 1; |
139 | } | 144 | } |
145 | |||
146 | // two cursors are equally deep decide by data index | ||
140 | return Integer.compare(cursor1.dataIndex, cursor2.dataIndex); | 147 | return Integer.compare(cursor1.dataIndex, cursor2.dataIndex); |
141 | } | 148 | } |
142 | } | 149 | } |