From: Robert Varga Date: Tue, 12 Mar 2024 21:17:44 +0000 (+0100) Subject: Modernize Indexed X-Git-Tag: v9.0.1~19 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=dd05f95d0fe58515adddc0468a6e73d558a70f20;ds=sidebyside Modernize Indexed 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 --- diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/Indexed.java b/atomix-storage/src/main/java/io/atomix/storage/journal/Indexed.java index cfb6a6750b..d1642f4129 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/Indexed.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/Indexed.java @@ -15,63 +15,22 @@ */ package io.atomix.storage.journal; -import static com.google.common.base.MoreObjects.toStringHelper; +import com.google.common.base.MoreObjects; /** * Indexed journal entry. + * + * @param entry type + * @param index the entry index + * @param entry the indexed entry + * @param size the serialized entry size */ -public class Indexed { - 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(long index, E entry, int size) { + @Override + public String toString() { + return MoreObjects.toStringHelper(this).add("index", index).add("entry", entry).toString(); + } } diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentReader.java b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentReader.java index 88b5fbf97d..4d63eaf550 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentReader.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentReader.java @@ -120,6 +120,7 @@ abstract sealed class JournalSegmentReader 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();