diff options
author | 2023-02-05 01:33:46 +0100 | |
---|---|---|
committer | 2023-02-05 01:33:46 +0100 | |
commit | c5fe88455146ca948b28f85b39b1554d99529b20 (patch) | |
tree | b6b996d8306abaf1aa39e8771440aeb426e236de /subprojects/store/src/main/java/tools | |
parent | DiffCursor value comparison support for null values. (diff) | |
download | refinery-c5fe88455146ca948b28f85b39b1554d99529b20.tar.gz refinery-c5fe88455146ca948b28f85b39b1554d99529b20.tar.zst refinery-c5fe88455146ca948b28f85b39b1554d99529b20.zip |
Cursor comparison bugfix with empty cursors (and null values).
Diffstat (limited to 'subprojects/store/src/main/java/tools')
-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 | } |