From f90f42e8834964b4e3f5a3504d896e64995b9a01 Mon Sep 17 00:00:00 2001 From: OszkarSemerath Date: Sun, 5 Feb 2023 00:37:55 +0100 Subject: Code quality improvements in cursors --- .../java/tools/refinery/store/map/internal/HashClash.java | 4 ++-- .../java/tools/refinery/store/map/internal/MapCursor.java | 12 +++++++----- .../tools/refinery/store/map/internal/MapDiffCursor.java | 13 ++++++------- 3 files changed, 15 insertions(+), 14 deletions(-) (limited to 'subprojects/store/src') diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/HashClash.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/HashClash.java index 5402ed4a..0806c486 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/HashClash.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/HashClash.java @@ -5,12 +5,12 @@ enum HashClash { * Not stuck. */ NONE, - + /** * Clashed, next we should return the key of cursor 1. */ STUCK_CURSOR_1, - + /** * Clashed, next we should return the key of cursor 2. */ 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 91a71e3d..f874137b 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 @@ -96,7 +96,7 @@ public class MapCursor implements Cursor { return Set.of(this.map); } - public static boolean sameSubnode(MapCursor cursor1, MapCursor cursor2) { + public static boolean sameSubNode(MapCursor cursor1, MapCursor cursor2) { Node nodeOfCursor1 = cursor1.nodeStack.peek(); Node nodeOfCursor2 = cursor2.nodeStack.peek(); if (nodeOfCursor1 != null && nodeOfCursor2 != null) { @@ -107,10 +107,12 @@ public class MapCursor implements Cursor { } /** - * @param - * @param - * @param cursor1 - * @param cursor2 + * Compares the state of two cursors started on two @{@link VersionedMap of the }same + * {@link tools.refinery.store.map.VersionedMapStore}. + * @param Key type + * @param Value type + * @param cursor1 first cursor + * @param cursor2 second cursor * @return Positive number if cursor 1 is behind, negative number if cursor 2 is behind, and 0 if they are at the * same position. */ diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapDiffCursor.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapDiffCursor.java index 9cd78113..beaff13b 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapDiffCursor.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapDiffCursor.java @@ -131,22 +131,21 @@ public class MapDiffCursor implements DiffCursor, Cursor { protected void resolveHashClashWithSecondEntry() { switch (this.hashClash) { - case STUCK_CURSOR_1: + case STUCK_CURSOR_1 -> { this.hashClash = HashClash.NONE; this.cursorRelation = 0; this.key = cursor1.key; this.fromValue = cursor1.value; this.toValue = defaultValue; - break; - case STUCK_CURSOR_2: + } + case STUCK_CURSOR_2 -> { this.hashClash = HashClash.NONE; this.cursorRelation = 0; this.key = cursor2.key; this.fromValue = defaultValue; this.toValue = cursor2.value; - break; - default: - throw new IllegalArgumentException("Inconsistent compare result for diffcursor"); + } + default -> throw new IllegalArgumentException("Inconsistent compare result for diffcursor"); } } @@ -189,7 +188,7 @@ public class MapDiffCursor implements DiffCursor, Cursor { boolean lastResult = true; do { changed = false; - if (MapCursor.sameSubnode(cursor1, cursor2)) { + if (MapCursor.sameSubNode(cursor1, cursor2)) { lastResult = skipNode(); changed = true; } -- cgit v1.2.3-54-g00ecf