From 5608c84a27437ec16ea732c76cf4fd176342a605 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 3 Apr 2023 14:08:53 +0200 Subject: [PATCH] Clean up sal-clustering-commons Clean up argument finality and whitespace in for(:) constructs. Change-Id: If22f693e6c499aafc8fe0a606b2abb40a9f67cfc Signed-off-by: Robert Varga --- .../notifications/RoleChangeNotifier.java | 2 +- .../cluster/io/ChunkedOutputStreamTest.java | 4 +-- .../io/FileBackedOutputStreamTest.java | 27 +++++++++---------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/notifications/RoleChangeNotifier.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/notifications/RoleChangeNotifier.java index 01f3827da7..ed0c10a717 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/notifications/RoleChangeNotifier.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/notifications/RoleChangeNotifier.java @@ -82,7 +82,7 @@ public class RoleChangeNotifier extends AbstractUntypedActor implements AutoClos new RoleChangeNotification(roleChanged.getMemberId(), roleChanged.getOldRole(), roleChanged.getNewRole()); - for (ActorRef listener: registeredListeners.values()) { + for (ActorRef listener : registeredListeners.values()) { listener.tell(latestRoleChangeNotification, getSelf()); } } else if (message instanceof LeaderStateChanged leaderStateChanged) { diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/io/ChunkedOutputStreamTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/io/ChunkedOutputStreamTest.java index 56c78f1c70..a93b6a8baa 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/io/ChunkedOutputStreamTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/io/ChunkedOutputStreamTest.java @@ -70,8 +70,8 @@ public class ChunkedOutputStreamTest { } int counter = 0; - for (byte[] chunk: assertFinishedStream(size, 2)) { - for (byte actual: chunk) { + for (byte[] chunk : assertFinishedStream(size, 2)) { + for (byte actual : chunk) { assertEquals((byte) counter++, actual); } } diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/io/FileBackedOutputStreamTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/io/FileBackedOutputStreamTest.java index ff5d61b41d..da5c5b6763 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/io/FileBackedOutputStreamTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/io/FileBackedOutputStreamTest.java @@ -18,7 +18,6 @@ import com.google.common.base.Stopwatch; import com.google.common.util.concurrent.Uninterruptibles; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.util.Arrays; import java.util.concurrent.TimeUnit; import org.junit.After; @@ -98,16 +97,14 @@ public class FileBackedOutputStreamTest { assertEquals("Temp file", tempFileName, findTempFileName(TEMP_DIR)); assertEquals("Size", bytes.length, fbos.asByteSource().size()); - InputStream inputStream = fbos.asByteSource().openStream(); + try (var inputStream = fbos.asByteSource().openStream()) { + assertArrayEquals("Read bytes", bytes, fbos.asByteSource().read()); - assertArrayEquals("Read bytes", bytes, fbos.asByteSource().read()); - - byte[] inBytes = new byte[bytes.length]; - assertEquals("# bytes read", bytes.length, inputStream.read(inBytes)); - assertArrayEquals("Read InputStream", bytes, inBytes); - assertEquals("End of stream", -1, inputStream.read()); - - inputStream.close(); + byte[] inBytes = new byte[bytes.length]; + assertEquals("# bytes read", bytes.length, inputStream.read(inBytes)); + assertArrayEquals("Read InputStream", bytes, inBytes); + assertEquals("End of stream", -1, inputStream.read()); + } fbos.cleanup(); @@ -182,27 +179,27 @@ public class FileBackedOutputStreamTest { fail("Temp file was not deleted"); } - static String findTempFileName(String dirPath) { + static String findTempFileName(final String dirPath) { String[] files = new File(dirPath).list(); assertNotNull(files); assertTrue("Found more than one temp file: " + Arrays.toString(files), files.length < 2); return files.length == 1 ? files[0] : null; } - static boolean deleteFile(String file) { + static boolean deleteFile(final String file) { return new File(file).delete(); } - static void deleteTempFiles(String path) { + static void deleteTempFiles(final String path) { String[] files = new File(path).list(); if (files != null) { - for (String file: files) { + for (String file : files) { deleteFile(path + File.separator + file); } } } - static void createDir(String path) { + static void createDir(final String path) { File dir = new File(path); if (!dir.exists() && !dir.mkdirs()) { throw new RuntimeException("Failed to create temp dir " + path); -- 2.36.6