From 4a166a0592ad9bf57b68d831ed20d7d784fc2ff6 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Thu, 13 Oct 2022 22:46:51 +0300 Subject: [PATCH 1/1] Code refactoring --- .../meviz/htmlindexer/indexer/AbstractIndexer.java | 5 ++--- .../meviz/htmlindexer/indexer/FilesystemIndexer.java | 3 +-- .../htmlindexer/metadata/DirectoryMetadata.java | 12 ++---------- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/AbstractIndexer.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/AbstractIndexer.java index 258f2f1..0aa459b 100644 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/AbstractIndexer.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/AbstractIndexer.java @@ -8,16 +8,15 @@ import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.*; import java.io.File; import java.io.UnsupportedEncodingException; +import java.util.Arrays; import static eu.svjatoslav.meviz.htmlindexer.Constants.SUPPORTED_IMAGE_EXTENSIONS; import static eu.svjatoslav.meviz.htmlindexer.Constants.SUPPORTED_VIDEO_EXTENSIONS; -import static java.util.Arrays.stream; public abstract class AbstractIndexer { public static boolean isImage(final String fileExtension) { - return stream(SUPPORTED_IMAGE_EXTENSIONS) - .anyMatch(ext -> ext.equals(fileExtension)); + return Arrays.asList(SUPPORTED_IMAGE_EXTENSIONS).contains(fileExtension); } public static boolean isVideo(final String fileExtension) { diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/FilesystemIndexer.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/FilesystemIndexer.java index e553c80..ce8e3fb 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/FilesystemIndexer.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/FilesystemIndexer.java @@ -107,8 +107,7 @@ public class FilesystemIndexer extends AbstractIndexer { private List getChildPath(final File file) { - final List result = new ArrayList<>(); - result.addAll(pathElements); + final List result = new ArrayList<>(pathElements); result.add(file.getName()); return result; diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/DirectoryMetadata.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/DirectoryMetadata.java index 64933e1..0725382 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/DirectoryMetadata.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/DirectoryMetadata.java @@ -33,15 +33,7 @@ public class DirectoryMetadata implements Serializable { * images that no longer exist in the filesystem. */ public void cleanup() { - final Iterator fileIterator = fileNameToFileMap.values() - .iterator(); - - while (fileIterator.hasNext()) { - final AbstractFile file = fileIterator.next(); - - if (!file.isMetadataVerified()) - fileIterator.remove(); - } + fileNameToFileMap.values().removeIf(file -> !file.isMetadataVerified()); } public void ensureFileMetadataIsUpToDate(final File parentDirectory, @@ -105,7 +97,7 @@ public class DirectoryMetadata implements Serializable { final ArrayList files = new ArrayList<>( fileNameToFileMap.values()); - Collections.sort(files, new FileSortComparator()); + files.sort(new FileSortComparator()); return files; } -- 2.20.1