diff --git a/src/main/java/com/owncloud/android/utils/FileSortOrder.java b/src/main/java/com/owncloud/android/utils/FileSortOrder.java index c5612791df..cbcb1bef72 100644 --- a/src/main/java/com/owncloud/android/utils/FileSortOrder.java +++ b/src/main/java/com/owncloud/android/utils/FileSortOrder.java @@ -42,7 +42,7 @@ public class FileSortOrder { public static final Map sortOrders; static { - sortOrders = new HashMap(); + sortOrders = new HashMap<>(); sortOrders.put(sort_a_to_z.mName, sort_a_to_z); sortOrders.put(sort_z_to_a.mName, sort_z_to_a); sortOrders.put(sort_old_to_new.mName, sort_old_to_new); diff --git a/src/main/java/com/owncloud/android/utils/FileSortOrderByDate.java b/src/main/java/com/owncloud/android/utils/FileSortOrderByDate.java index 3a4a1897ef..0a0a7fe8be 100644 --- a/src/main/java/com/owncloud/android/utils/FileSortOrderByDate.java +++ b/src/main/java/com/owncloud/android/utils/FileSortOrderByDate.java @@ -1,4 +1,4 @@ -/** +/* * Nextcloud Android client application * * @author Sven R. Kunze @@ -23,8 +23,6 @@ package com.owncloud.android.utils; import com.owncloud.android.datamodel.OCFile; import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -63,22 +61,16 @@ public class FileSortOrderByDate extends FileSortOrder { /** * Sorts list by Date. * - * @param filesArray list of files to sort + * @param files list of files to sort */ - public File[] sortLocalFiles(File[] filesArray) { + public List sortLocalFiles(List files) { final int multiplier = mAscending ? 1 : -1; - List files = new ArrayList(Arrays.asList(filesArray)); - - Collections.sort(files, new Comparator() { - @SuppressFBWarnings(value = "Bx") - public int compare(File o1, File o2) { - Long obj1 = o1.lastModified(); - return multiplier * obj1.compareTo(o2.lastModified()); - } + Collections.sort(files, (o1, o2) -> { + Long obj1 = o1.lastModified(); + return multiplier * obj1.compareTo(o2.lastModified()); }); - File[] returnArray = new File[files.size()]; - return files.toArray(returnArray); + return files; } } diff --git a/src/main/java/com/owncloud/android/utils/FileSortOrderByName.java b/src/main/java/com/owncloud/android/utils/FileSortOrderByName.java index e94cfae25d..fb651b6d7f 100644 --- a/src/main/java/com/owncloud/android/utils/FileSortOrderByName.java +++ b/src/main/java/com/owncloud/android/utils/FileSortOrderByName.java @@ -1,4 +1,4 @@ -/** +/* * Nextcloud Android client application * * @author Sven R. Kunze @@ -23,8 +23,6 @@ package com.owncloud.android.utils; import com.owncloud.android.datamodel.OCFile; import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -70,30 +68,25 @@ public class FileSortOrderByName extends FileSortOrder { /** * Sorts list by Name. * - * @param filesArray files to sort + * @param files files to sort */ - public File[] sortLocalFiles(File[] filesArray) { + public List sortLocalFiles(List files) { final int multiplier = mAscending ? 1 : -1; - List files = new ArrayList<>(Arrays.asList(filesArray)); - - Collections.sort(files, new Comparator() { - public int compare(File o1, File o2) { - if (o1.isDirectory() && o2.isDirectory()) { - return multiplier * o1.getPath().toLowerCase(Locale.getDefault()) - .compareTo(o2.getPath().toLowerCase(Locale.getDefault())); - } else if (o1.isDirectory()) { - return -1; - } else if (o2.isDirectory()) { - return 1; - } - return multiplier * new AlphanumComparator().compare(o1.getPath() - .toLowerCase(Locale.getDefault()), - o2.getPath().toLowerCase(Locale.getDefault())); + Collections.sort(files, (o1, o2) -> { + if (o1.isDirectory() && o2.isDirectory()) { + return multiplier * o1.getPath().toLowerCase(Locale.getDefault()) + .compareTo(o2.getPath().toLowerCase(Locale.getDefault())); + } else if (o1.isDirectory()) { + return -1; + } else if (o2.isDirectory()) { + return 1; } + return multiplier * new AlphanumComparator().compare(o1.getPath() + .toLowerCase(Locale.getDefault()), + o2.getPath().toLowerCase(Locale.getDefault())); }); - File[] returnArray = new File[files.size()]; - return files.toArray(returnArray); + return files; } } diff --git a/src/main/java/com/owncloud/android/utils/FileSortOrderBySize.java b/src/main/java/com/owncloud/android/utils/FileSortOrderBySize.java index fbf0e8a329..38ecdd7dd7 100644 --- a/src/main/java/com/owncloud/android/utils/FileSortOrderBySize.java +++ b/src/main/java/com/owncloud/android/utils/FileSortOrderBySize.java @@ -23,8 +23,6 @@ package com.owncloud.android.utils; import com.owncloud.android.datamodel.OCFile; import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -73,32 +71,26 @@ public class FileSortOrderBySize extends FileSortOrder { /** * Sorts list by Size. * - * @param filesArray list of files to sort + * @param files list of files to sort */ - public File[] sortLocalFiles(File[] filesArray) { + public List sortLocalFiles(List files) { final int multiplier = mAscending ? 1 : -1; - List files = new ArrayList<>(Arrays.asList(filesArray)); - - Collections.sort(files, new Comparator() { - @SuppressFBWarnings(value = "Bx") - public int compare(File o1, File o2) { - if (o1.isDirectory() && o2.isDirectory()) { - Long obj1 = FileStorageUtils.getFolderSize(o1); - return multiplier * obj1.compareTo(FileStorageUtils.getFolderSize(o2)); - } else if (o1.isDirectory()) { - return -1; - } else if (o2.isDirectory()) { - return 1; - } else { - Long obj1 = o1.length(); - return multiplier * obj1.compareTo(o2.length()); - } + Collections.sort(files, (o1, o2) -> { + if (o1.isDirectory() && o2.isDirectory()) { + Long obj1 = FileStorageUtils.getFolderSize(o1); + return multiplier * obj1.compareTo(FileStorageUtils.getFolderSize(o2)); + } else if (o1.isDirectory()) { + return -1; + } else if (o2.isDirectory()) { + return 1; + } else { + Long obj1 = o1.length(); + return multiplier * obj1.compareTo(o2.length()); } }); - File[] returnArray = new File[files.size()]; - return files.toArray(returnArray); + return files; } }