Skip to content

Commit

Permalink
Fix NullPointerException
Browse files Browse the repository at this point in the history
Improve code style.
  • Loading branch information
Borewit committed Feb 11, 2023
1 parent 2b8b9b7 commit 318bd50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,12 @@

import java.io.File;

/*
============================================================================
= Author: Jeremy Caron
= File: DirectoryThenFileThenAlphabeticalFileComparator.java
= Purpose: Sorts directories ahead of files, and then sorts files
= alphabetically (ignoring case).
============================================================================
*/

/**
*
* @author jcaron
* Sorts directories ahead of files, and then sorts files alphabetically (ignoring case).
*/
public class DirectoryThenFileThenAlphabeticalFileComparator implements java.util.Comparator<File>
{
/**
*
* @param a
* @param b
* @return
*/

@Override
public int compare(File a, File b)
{
Expand Down
44 changes: 7 additions & 37 deletions src/main/java/listfix/util/FileTypeSearch.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
/*
* listFix() - Fix Broken Playlists!
* Copyright (C) 2001-2014 Jeremy Caron
*
* This file is part of listFix().
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, please see http://www.gnu.org/licenses/
*/

package listfix.util;

import listfix.comparators.DirectoryThenFileThenAlphabeticalFileComparator;
Expand All @@ -29,14 +9,9 @@
import java.util.Collections;
import java.util.List;

/**
*
* @author jcaron
*/
public class FileTypeSearch
{
/**
*
* @param directoryToSearch
* @param filter
* @return
Expand All @@ -45,32 +20,27 @@ public List<File> findFiles(File directoryToSearch, FileFilter filter)
{
if (directoryToSearch.exists())
{
List<File> ol = new ArrayList<>();
File[] inodes = directoryToSearch.listFiles(filter);

if (inodes != null && inodes.length > 0)
{
ol.addAll(Arrays.asList(inodes));
Collections.sort(ol, new DirectoryThenFileThenAlphabeticalFileComparator());
File f;
List<File> ol = new ArrayList<>(Arrays.asList(inodes));
ol.sort(new DirectoryThenFileThenAlphabeticalFileComparator());
List<File> files = new ArrayList<>();
for (File ol1 : ol)
for (File file : ol)
{
f = ol1;
if (f.isDirectory())
if (file.isDirectory())
{
files.addAll(findFiles(f, filter));
files.addAll(findFiles(file, filter));
}
else
{
files.add(f);
files.add(file);
}
}

return files;
}
return null;
}
return null;
return Collections.emptyList();
}
}

0 comments on commit 318bd50

Please sign in to comment.