-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilterOldest.java
More file actions
30 lines (25 loc) · 945 Bytes
/
FilterOldest.java
File metadata and controls
30 lines (25 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.io.File;
import java.util.ArrayList;
import java.util.Collections; // Import the Collections utility
public class FilterOldest extends Filter {
// The constructor can be empty or call super(null, null) since we don't use the parts.
public FilterOldest() {
super(null, null);
}
@Override
public ArrayList<File> eval(String ignoredArgument, ArrayList<File> duplicateSet) {
if (duplicateSet == null || duplicateSet.isEmpty()) {
return new ArrayList<>();
}
File newestFile = duplicateSet.get(0);
for (File file : duplicateSet) {
if (file.lastModified() < newestFile.lastModified()) {
newestFile = file;
}
}
// The filter's only job is to return a list containing the one file it selected.
ArrayList<File> result = new ArrayList<>();
result.add(newestFile);
return result;
}
}