@Test public void constructorIterable_order() { final List<Comparator<File>> list = new ArrayList<Comparator<File>>(); list.add(SizeFileComparator.SIZE_COMPARATOR); list.add(ExtensionFileComparator.EXTENSION_COMPARATOR); final Comparator<File> c = new CompositeFileComparator(list); assertEquals("equal", 0, c.compare(equalFile1, equalFile2)); assertTrue("less", c.compare(lessFile, moreFile) < 0); assertTrue("more", c.compare(moreFile, lessFile) > 0); }
public int compare(final File file1, final File file2) { int result = 0; for (final Comparator<File> delegate : delegates) { result = delegate.compare(file1, file2); if (result != 0) { break; } } return result; }
CompositeFileComparator extends AbstractFileComparator implements Serializable { public int compare(final File file1, final File file2) { int result = 0; for (final Comparator<File> delegate : delegates) { result = delegate.compare(file1, file2); if (result != 0) { break; } } return result; } }
CompositeFileComparator extends AbstractFileComparator implements Serializable { public int compare(final File file1, final File file2) { int result = 0; for (final Comparator<File> delegate : delegates) { result = delegate.compare(file1, file2); if (result != 0) { break; } } return result; } @SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct  CompositeFileComparator(final Comparator<File>... delegates); @SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct  CompositeFileComparator(final Iterable<Comparator<File>> delegates); }
CompositeFileComparator extends AbstractFileComparator implements Serializable { public int compare(final File file1, final File file2) { int result = 0; for (final Comparator<File> delegate : delegates) { result = delegate.compare(file1, file2); if (result != 0) { break; } } return result; } @SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct  CompositeFileComparator(final Comparator<File>... delegates); @SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct  CompositeFileComparator(final Iterable<Comparator<File>> delegates); int compare(final File file1, final File file2); @Override String toString(); }
CompositeFileComparator extends AbstractFileComparator implements Serializable { public int compare(final File file1, final File file2) { int result = 0; for (final Comparator<File> delegate : delegates) { result = delegate.compare(file1, file2); if (result != 0) { break; } } return result; } @SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct  CompositeFileComparator(final Comparator<File>... delegates); @SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct  CompositeFileComparator(final Iterable<Comparator<File>> delegates); int compare(final File file1, final File file2); @Override String toString();  }