Code refactoring
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Thu, 13 Oct 2022 19:46:51 +0000 (22:46 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Thu, 13 Oct 2022 19:46:51 +0000 (22:46 +0300)
src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/AbstractIndexer.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/FilesystemIndexer.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/DirectoryMetadata.java

index 258f2f1..0aa459b 100644 (file)
@@ -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) {
index e553c80..ce8e3fb 100755 (executable)
@@ -107,8 +107,7 @@ public class FilesystemIndexer extends AbstractIndexer {
 
     private List<String> getChildPath(final File file) {
 
-        final List<String> result = new ArrayList<>();
-        result.addAll(pathElements);
+        final List<String> result = new ArrayList<>(pathElements);
         result.add(file.getName());
 
         return result;
index 64933e1..0725382 100755 (executable)
@@ -33,15 +33,7 @@ public class DirectoryMetadata implements Serializable {
      * images that no longer exist in the filesystem.
      */
     public void cleanup() {
-        final Iterator<AbstractFile> 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<AbstractFile> files = new ArrayList<>(
                 fileNameToFileMap.values());
 
-        Collections.sort(files, new FileSortComparator());
+        files.sort(new FileSortComparator());
 
         return files;
     }