package org.geotools.gce.image;

import java.io.File;
import java.io.FilenameFilter;
import java.util.HashSet;
import java.util.Iterator;

import junit.framework.TestCase;

public class WorldImageBaseTestCase extends TestCase {
	public WorldImageBaseTestCase(String name) {
		super(name);
	}

	/**
	 * Helper class used to filter files basing the decision on the file
	 * extensions. It is not so smart I know.... :-(
	 * 
	 * @author giannecchini
	 */
	class MyFileFilter implements FilenameFilter {
		private HashSet extensions = new HashSet();

		public MyFileFilter() {
			String[] extensions = new String[] { ".gif", ".jpg", ".jpeg",
					".tif", ".tiff", ".png", ".bmp" };
			this.setExtensions(extensions);
		}

		public MyFileFilter(String[] extensions) {
			this.setExtensions(extensions);
		}

		/**
		 * Sets the extensions that are allowed
		 * 
		 * @param extensions
		 */
		private void setExtensions(String[] extensions) {
			if (extensions != null) {
				this.extensions.clear();

				for (int i = 0; i < extensions.length; i++)
					this.extensions.add(extensions[i]);
			}
		}

		/**
		 * Checks whether or not a file is acceptable following the conditions
		 * stated by the given extensions.
		 * 
		 * @param file
		 *            DOCUMENT ME!
		 * @param name
		 *            DOCUMENT ME!
		 * 
		 * @return DOCUMENT ME!
		 */
		public boolean accept(File file, String name) {
			if (this.extensions.size() > 0) {
				Iterator it = this.extensions.iterator();

				while (it.hasNext())

					if (name.endsWith((String) it.next())) {
						return true;
					}
			}

			return false;
		}
	}

}
