FileComparator implements Comparator<AbstractFile> { public boolean equals(Object o) { if(! (o instanceof FileComparator)) return false; FileComparator fc = (FileComparator)o; return criterion ==fc.criterion && ascending==fc.ascending; } FileComparator(int criterion, boolean ascending, boolean directoriesFirst, Function<AbstractFile, String> nameFunc); int compare(AbstractFile f1, AbstractFile f2); boolean equals(Object o); final static int NAME_CRITERION; final static int SIZE_CRITERION; final static int DATE_CRITERION; final static int EXTENSION_CRITERION; final static int PERMISSIONS_CRITERION; final static int OWNER_CRITERION; final static int GROUP_CRITERION; }
@Test public void testCompareNameDir() { Arrays.sort(files, new FileComparator(FileComparator.NAME_CRITERION, true, true, AbstractFile::getName)); assert B.equals(files[0]); assert D.equals(files[1]); assert A.equals(files[2]); assert C.equals(files[3]); }
@Test public void testCompareNameDirDesc() { Arrays.sort(files, new FileComparator(FileComparator.NAME_CRITERION, false, true, AbstractFile::getName)); assert D.equals(files[0]); assert B.equals(files[1]); assert C.equals(files[2]); assert A.equals(files[3]); }
@Test public void testCompareName() { Arrays.sort(files, new FileComparator(FileComparator.NAME_CRITERION, true, false, AbstractFile::getName)); assert A.equals(files[0]); assert B.equals(files[1]); assert C.equals(files[2]); assert D.equals(files[3]); }
@Test public void testCompareNameDesc() { Arrays.sort(files, new FileComparator(FileComparator.NAME_CRITERION, false, false, AbstractFile::getName)); assert D.equals(files[0]); assert C.equals(files[1]); assert B.equals(files[2]); assert A.equals(files[3]); }
@Test public void testCompareSizeDir() { Arrays.sort(files, new FileComparator(FileComparator.SIZE_CRITERION, true, true, AbstractFile::getName)); assert B.equals(files[0]); assert D.equals(files[1]); assert C.equals(files[2]); assert A.equals(files[3]); }
@Test public void testCompareSize() { Arrays.sort(files, new FileComparator(FileComparator.SIZE_CRITERION, true, false, AbstractFile::getName)); assert B.equals(files[0]); assert D.equals(files[1]); assert C.equals(files[2]); assert A.equals(files[3]); }
@Test public void testCompareSizeDirDesc() { Arrays.sort(files, new FileComparator(FileComparator.SIZE_CRITERION, false, true, AbstractFile::getName)); assert D.equals(files[0]); assert B.equals(files[1]); assert A.equals(files[2]); assert C.equals(files[3]); }
@Test public void testCompareSizeDesc() { Arrays.sort(files, new FileComparator(FileComparator.SIZE_CRITERION, false, false, AbstractFile::getName)); assert A.equals(files[0]); assert C.equals(files[1]); assert D.equals(files[2]); assert B.equals(files[3]); }
@Test public void testCompareDateDir() { Arrays.sort(files, new FileComparator(FileComparator.DATE_CRITERION, true, true, AbstractFile::getName)); assert B.equals(files[0]); assert D.equals(files[1]); assert A.equals(files[2]); assert C.equals(files[3]); }
@Test public void testCompareDate() { Arrays.sort(files, new FileComparator(FileComparator.DATE_CRITERION, true, false, AbstractFile::getName)); assert A.equals(files[0]); assert B.equals(files[1]); assert C.equals(files[2]); assert D.equals(files[3]); }
@Test public void testCompareDateDirDesc() { Arrays.sort(files, new FileComparator(FileComparator.DATE_CRITERION, false, true, AbstractFile::getName)); assert D.equals(files[0]); assert B.equals(files[1]); assert C.equals(files[2]); assert A.equals(files[3]); }
@Test public void testCompareDateDesc() { Arrays.sort(files, new FileComparator(FileComparator.DATE_CRITERION, false, false, AbstractFile::getName)); assert D.equals(files[0]); assert C.equals(files[1]); assert B.equals(files[2]); assert A.equals(files[3]); }
@Test public void testCompareExtDir() { Arrays.sort(files, new FileComparator(FileComparator.EXTENSION_CRITERION, true, true, AbstractFile::getName)); assert B.equals(files[0]); assert D.equals(files[1]); assert A.equals(files[2]); assert C.equals(files[3]); }
@Test public void testCompareExt() { Arrays.sort(files, new FileComparator(FileComparator.EXTENSION_CRITERION, true, false, AbstractFile::getName)); assert A.equals(files[0]); assert B.equals(files[1]); assert D.equals(files[2]); assert C.equals(files[3]); }
@Test public void testCompareExtDirDesc() { Arrays.sort(files, new FileComparator(FileComparator.EXTENSION_CRITERION, false, true, AbstractFile::getName)); assert D.equals(files[0]); assert B.equals(files[1]); assert C.equals(files[2]); assert A.equals(files[3]); }
@Test public void testCompareExtDesc() { Arrays.sort(files, new FileComparator(FileComparator.EXTENSION_CRITERION, false, false, AbstractFile::getName)); assert C.equals(files[0]); assert D.equals(files[1]); assert B.equals(files[2]); assert A.equals(files[3]); }