Reformat JournalSegmentFile 21/111621/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 5 May 2024 13:03:34 +0000 (15:03 +0200)
committerRobert Varga <nite@hq.sk>
Sun, 5 May 2024 13:52:03 +0000 (13:52 +0000)
It is hard to navigate this file, which seems to be a rather pointless
class. Reformat it before we decide what to do with it next.

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

index 2190dee5a73de2917c68248558773313b6fbac80..1306c4b79f4e9b670e3a161391c888fa25805ad4 100644 (file)
  */
 package io.atomix.storage.journal;
 
-import java.io.File;
-
 import static java.util.Objects.requireNonNull;
 
+import java.io.File;
+
 /**
  * Segment file utility.
  *
  * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
  */
 public final class JournalSegmentFile {
-  private static final char PART_SEPARATOR = '-';
-  private static final char EXTENSION_SEPARATOR = '.';
-  private static final String EXTENSION = "log";
-  private final File file;
-
-  /**
-   * Returns a boolean value indicating whether the given file appears to be a parsable segment file.
-   *
-   * @throws NullPointerException if {@code file} is null
-   */
-  public static boolean isSegmentFile(String name, File file) {
-    return isSegmentFile(name, file.getName());
-  }
+    private static final char PART_SEPARATOR = '-';
+    private static final char EXTENSION_SEPARATOR = '.';
+    private static final String EXTENSION = "log";
 
-  /**
-   * Returns a boolean value indicating whether the given file appears to be a parsable segment file.
-   *
-   * @param journalName the name of the journal
-   * @param fileName the name of the file to check
-   * @throws NullPointerException if {@code file} is null
-   */
-  public static boolean isSegmentFile(String journalName, String fileName) {
-    requireNonNull(journalName, "journalName cannot be null");
-    requireNonNull(fileName, "fileName cannot be null");
+    private final File file;
 
-    int partSeparator = fileName.lastIndexOf(PART_SEPARATOR);
-    int extensionSeparator = fileName.lastIndexOf(EXTENSION_SEPARATOR);
+    /**
+     * @throws IllegalArgumentException if {@code file} is not a valid segment file
+     */
+    JournalSegmentFile(final File file) {
+        this.file = file;
+    }
 
-    if (extensionSeparator == -1
-        || partSeparator == -1
-        || extensionSeparator < partSeparator
-        || !fileName.endsWith(EXTENSION)) {
-      return false;
+    /**
+     * Returns the segment file.
+     *
+     * @return The segment file.
+     */
+    public File file() {
+        return file;
     }
 
-    for (int i = partSeparator + 1; i < extensionSeparator; i++) {
-      if (!Character.isDigit(fileName.charAt(i))) {
-        return false;
-      }
+    /**
+     * Returns a boolean value indicating whether the given file appears to be a parsable segment file.
+     *
+     * @throws NullPointerException if {@code file} is null
+     */
+    public static boolean isSegmentFile(final String name, final File file) {
+        return isSegmentFile(name, file.getName());
     }
 
-    return fileName.startsWith(journalName);
-  }
+    /**
+     * Returns a boolean value indicating whether the given file appears to be a parsable segment file.
+     *
+     * @param journalName the name of the journal
+     * @param fileName the name of the file to check
+     * @throws NullPointerException if {@code file} is null
+     */
+    public static boolean isSegmentFile(final String journalName, final String fileName) {
+        requireNonNull(journalName, "journalName cannot be null");
+        requireNonNull(fileName, "fileName cannot be null");
+
+        int partSeparator = fileName.lastIndexOf(PART_SEPARATOR);
+        int extensionSeparator = fileName.lastIndexOf(EXTENSION_SEPARATOR);
 
-  /**
-   * Creates a segment file for the given directory, log name, segment ID, and segment version.
-   */
-  static File createSegmentFile(String name, File directory, long id) {
-    return new File(directory, String.format("%s-%d.log", requireNonNull(name, "name cannot be null"), id));
-  }
+        if (extensionSeparator == -1 || partSeparator == -1 || extensionSeparator < partSeparator
+            || !fileName.endsWith(EXTENSION)) {
+            return false;
+        }
 
-  /**
-   * @throws IllegalArgumentException if {@code file} is not a valid segment file
-   */
-  JournalSegmentFile(File file) {
-    this.file = file;
-  }
+        for (int i = partSeparator + 1; i < extensionSeparator; i++) {
+            if (!Character.isDigit(fileName.charAt(i))) {
+                return false;
+            }
+        }
 
-  /**
-   * Returns the segment file.
-   *
-   * @return The segment file.
-   */
-  public File file() {
-    return file;
-  }
+        return fileName.startsWith(journalName);
+    }
+
+    /**
+     * Creates a segment file for the given directory, log name, segment ID, and segment version.
+     */
+    static File createSegmentFile(final String name, final File directory, final long id) {
+        return new File(directory, String.format("%s-%d.log", requireNonNull(name, "name cannot be null"), id));
+    }
 }