Modernize Indexed 83/110683/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 12 Mar 2024 21:17:44 +0000 (22:17 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 13 Mar 2024 07:28:57 +0000 (08:28 +0100)
Indexed.getType() is not used anywhere, hence remove it. While we are
here, also turn the class into a record, as it is a pure DTO.

Also add a FIXME to require the actual entry to be non-null.

JIRA: CONTROLLER-2101
Change-Id: I8bd42a815096a3d0993eb41c59cf39655a7ed0fd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
atomix-storage/src/main/java/io/atomix/storage/journal/Indexed.java
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentReader.java

index cfb6a6750bf7cc1af4cdff39fef69246c5cfa54b..d1642f4129de5d18dec341705507391886fcd0db 100644 (file)
  */
 package io.atomix.storage.journal;
 
-import static com.google.common.base.MoreObjects.toStringHelper;
+import com.google.common.base.MoreObjects;
 
 /**
  * Indexed journal entry.
+ *
+ * @param <E> entry type
+ * @param index the entry index
+ * @param entry the indexed entry
+ * @param size the serialized entry size
  */
-public class Indexed<E> {
-  private final long index;
-  private final E entry;
-  private final int size;
-
-  public Indexed(long index, E entry, int size) {
-    this.index = index;
-    this.entry = entry;
-    this.size = size;
-  }
-
-  /**
-   * Returns the entry index.
-   *
-   * @return The entry index.
-   */
-  public long index() {
-    return index;
-  }
-
-  /**
-   * Returns the indexed entry.
-   *
-   * @return The indexed entry.
-   */
-  public E entry() {
-    return entry;
-  }
-
-  /**
-   * Returns the serialized entry size.
-   *
-   * @return The serialized entry size.
-   */
-  public int size() {
-    return size;
-  }
-
-  /**
-   * Returns the entry type class.
-   *
-   * @return The entry class.
-   */
-  public Class<?> type() {
-    return entry.getClass();
-  }
-
-  @Override
-  public String toString() {
-    return toStringHelper(this)
-        .add("index", index)
-        .add("entry", entry)
-        .toString();
-  }
+// FIXME: add @NonNullByDefault and enforce non-null entry once we can say that entries cannot be null
+// FIXME: it seems 'index' has to be non-zero, we should enforce that if that really is the case
+// FIXME: it seems 'size' has not be non-zero, we should enforce that if that really is the case
+public record Indexed<E>(long index, E entry, int size) {
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this).add("index", index).add("entry", entry).toString();
+    }
 }
index 88b5fbf97dc2f190dda53adb6ce828c875d574fa..4d63eaf550edffbfd74020517f8d0214020fba46 100644 (file)
@@ -120,6 +120,7 @@ abstract sealed class JournalSegmentReader<E> permits FileChannelJournalSegmentR
         reset();
         Position position = this.index.lookup(index - 1);
         if (position != null) {
+            // FIXME: why do we need a 'null'-based entry here?
             currentEntry = new Indexed<>(position.index() - 1, null, 0);
             setPosition(position.position());
             nextEntry = readNext();