From 4e41e12bd24286a6c903e55a3c9f8eae58f18e6e Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sun, 17 Sep 2023 15:31:06 +0200 Subject: [PATCH] Small code and doc improvements Remove unnecessary else-branch and use Collections.isEmpty(). Add doc comment for splitFilename() --- .../streams/io/StoredDirectoryHelper.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/streams/io/StoredDirectoryHelper.java b/app/src/main/java/org/schabi/newpipe/streams/io/StoredDirectoryHelper.java index dede5088e..1b74c90a5 100644 --- a/app/src/main/java/org/schabi/newpipe/streams/io/StoredDirectoryHelper.java +++ b/app/src/main/java/org/schabi/newpipe/streams/io/StoredDirectoryHelper.java @@ -102,24 +102,24 @@ public class StoredDirectoryHelper { } } - if (matches.size() < 1) { + if (matches.isEmpty()) { return createFile(name, mime, true); - } else { - // check if the filename is in use - String lcName = name.toLowerCase(); - for (final String testName : matches) { - if (testName.equals(lcName)) { - lcName = null; - break; - } - } + } - // check if not in use - if (lcName != null) { - return createFile(name, mime, true); + // check if the filename is in use + String lcName = name.toLowerCase(); + for (final String testName : matches) { + if (testName.equals(lcName)) { + lcName = null; + break; } } + // create file if filename not in use + if (lcName != null) { + return createFile(name, mime, true); + } + Collections.sort(matches, String::compareTo); for (int i = 1; i < 1000; i++) { @@ -261,6 +261,12 @@ public class StoredDirectoryHelper { } } + /** + * Splits the filename into the name and extension. + * + * @param filename The filename to split + * @return A String array with the name at index 0 and extension at index 1 + */ private static String[] splitFilename(@NonNull final String filename) { final int dotIndex = filename.lastIndexOf('.');