Clean up JournalSegment 95/110595/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Mar 2024 12:23:08 +0000 (13:23 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Mar 2024 12:51:31 +0000 (13:51 +0100)
We have plenty of unused and needlessly-public methods. Clean that up.

Change-Id: Ie93dd9eff7f847be23bf4d7fea9acefcac0beb60
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegment.java

index 3c27109a22b9b8dc504430eb38411b2cdd1c416d..ec685fe5c970714cdf3bacae06201da6847e58b0 100644 (file)
@@ -15,6 +15,7 @@
  */
 package io.atomix.storage.journal;
 
+import com.google.common.base.MoreObjects;
 import io.atomix.storage.journal.index.JournalIndex;
 import io.atomix.storage.journal.index.SparseJournalIndex;
 import java.io.IOException;
@@ -25,9 +26,6 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import static com.google.common.base.MoreObjects.toStringHelper;
-import static com.google.common.base.Preconditions.checkState;
-
 /**
  * Log segment.
  *
@@ -69,30 +67,12 @@ final class JournalSegment<E> implements AutoCloseable {
     writer = new FileChannelJournalSegmentWriter<>(channel, this, maxEntrySize, index, namespace);
   }
 
-  /**
-   * Returns the segment ID.
-   *
-   * @return The segment ID.
-   */
-  public long id() {
-    return descriptor.id();
-  }
-
-  /**
-   * Returns the segment version.
-   *
-   * @return The segment version.
-   */
-  public long version() {
-    return descriptor.version();
-  }
-
   /**
    * Returns the segment's starting index.
    *
    * @return The segment's starting index.
    */
-  public long index() {
+  long index() {
     return descriptor.index();
   }
 
@@ -101,7 +81,7 @@ final class JournalSegment<E> implements AutoCloseable {
    *
    * @return The last index in the segment.
    */
-  public long lastIndex() {
+  long lastIndex() {
     return writer.getLastIndex();
   }
 
@@ -110,7 +90,7 @@ final class JournalSegment<E> implements AutoCloseable {
    *
    * @return the size of the segment
    */
-  public int size() {
+  int size() {
     try {
       return (int) channel.size();
     } catch (IOException e) {
@@ -123,7 +103,7 @@ final class JournalSegment<E> implements AutoCloseable {
    *
    * @return The segment file.
    */
-  public JournalSegmentFile file() {
+  JournalSegmentFile file() {
     return file;
   }
 
@@ -132,28 +112,10 @@ final class JournalSegment<E> implements AutoCloseable {
    *
    * @return The segment descriptor.
    */
-  public JournalSegmentDescriptor descriptor() {
+  JournalSegmentDescriptor descriptor() {
     return descriptor;
   }
 
-  /**
-   * Returns a boolean value indicating whether the segment is empty.
-   *
-   * @return Indicates whether the segment is empty.
-   */
-  public boolean isEmpty() {
-    return length() == 0;
-  }
-
-  /**
-   * Returns the segment length.
-   *
-   * @return The segment length.
-   */
-  public long length() {
-    return writer.getNextIndex() - index();
-  }
-
   /**
    * Acquires a reference to the log segment.
    */
@@ -228,7 +190,9 @@ final class JournalSegment<E> implements AutoCloseable {
    * Checks whether the segment is open.
    */
   private void checkOpen() {
-    checkState(open, "Segment not open");
+    if (!open) {
+      throw new IllegalStateException("Segment not open");
+    }
   }
 
   /**
@@ -268,7 +232,7 @@ final class JournalSegment<E> implements AutoCloseable {
   /**
    * Deletes the segment.
    */
-  public void delete() {
+  void delete() {
     try {
       Files.deleteIfExists(file.file().toPath());
     } catch (IOException e) {
@@ -278,9 +242,9 @@ final class JournalSegment<E> implements AutoCloseable {
 
   @Override
   public String toString() {
-    return toStringHelper(this)
-        .add("id", id())
-        .add("version", version())
+    return MoreObjects.toStringHelper(this)
+        .add("id", descriptor.id())
+        .add("version", descriptor.version())
         .add("index", index())
         .toString();
   }