01: package org.geotools.gce.image;
02:
03: import java.io.File;
04: import java.io.FilenameFilter;
05: import java.util.HashSet;
06: import java.util.Iterator;
07:
08: import junit.framework.TestCase;
09:
10: public class WorldImageBaseTestCase extends TestCase {
11: public WorldImageBaseTestCase(String name) {
12: super (name);
13: }
14:
15: /**
16: * Helper class used to filter files basing the decision on the file
17: * extensions. It is not so smart I know.... :-(
18: *
19: * @author giannecchini
20: */
21: class MyFileFilter implements FilenameFilter {
22: private HashSet extensions = new HashSet();
23:
24: public MyFileFilter() {
25: String[] extensions = new String[] { ".gif", ".jpg",
26: ".jpeg", ".tif", ".tiff", ".png", ".bmp" };
27: this .setExtensions(extensions);
28: }
29:
30: public MyFileFilter(String[] extensions) {
31: this .setExtensions(extensions);
32: }
33:
34: /**
35: * Sets the extensions that are allowed
36: *
37: * @param extensions
38: */
39: private void setExtensions(String[] extensions) {
40: if (extensions != null) {
41: this .extensions.clear();
42:
43: for (int i = 0; i < extensions.length; i++)
44: this .extensions.add(extensions[i]);
45: }
46: }
47:
48: /**
49: * Checks whether or not a file is acceptable following the conditions
50: * stated by the given extensions.
51: *
52: * @param file
53: * DOCUMENT ME!
54: * @param name
55: * DOCUMENT ME!
56: *
57: * @return DOCUMENT ME!
58: */
59: public boolean accept(File file, String name) {
60: if (this .extensions.size() > 0) {
61: Iterator it = this .extensions.iterator();
62:
63: while (it.hasNext())
64:
65: if (name.endsWith((String) it.next())) {
66: return true;
67: }
68: }
69:
70: return false;
71: }
72: }
73:
74: }
|