From bbe3d2923a34ea189f5e99409c1a4667a6b03935 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 5 May 2024 15:03:34 +0200 Subject: [PATCH] Reformat JournalSegmentFile 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 --- .../storage/journal/JournalSegmentFile.java | 115 +++++++++--------- 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentFile.java b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentFile.java index 2190dee5a7..1306c4b79f 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentFile.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentFile.java @@ -15,80 +15,79 @@ */ package io.atomix.storage.journal; -import java.io.File; - import static java.util.Objects.requireNonNull; +import java.io.File; + /** * Segment file utility. * * @author Jordan Halterman */ 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)); + } } -- 2.36.6