Menu

[r1]: / src / SimpleFileFilter.java  Maximize  Restore  History

Download this file

47 lines (36 with data), 1.2 kB

 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.io.*;
import java.util.*;
public class SimpleFileFilter implements FileFilter {
public static SimpleFileFilter getProjectFilter() {
return new SimpleFileFilter("prj");
}
public static SimpleFileFilter getLogFilter() {
return new SimpleFileFilter("log");
}
public static SimpleFileFilter getAttachmentFilter() {
return new SimpleFileFilter("dat");
}
private List<String> extensions;
public SimpleFileFilter(String validExtensions) {
extensions = new ArrayList<String>();
String[] ext = validExtensions.split("\\|");
int i;
for (i=0; i<ext.length; i++) {
extensions.add(ext[i]);
}
}
public boolean accept(File pathname) {
return accept(pathname.getName());
}
public boolean accept(String fullName) {
int npos = fullName.lastIndexOf('.');
boolean accepted = false;
if (npos > 0) {
String extension = fullName.substring(npos+1);
if (extensions.contains(extension)) {
accepted = true;
}
}
return accepted;
}
}
MongoDB Logo MongoDB