package com.informagen; import java.io.FilenameFilter; import java.io.File; import java.util.Enumeration; import java.util.Vector; public class FilterBySuffix implements FilenameFilter { final Vector theSuffixes = new Vector(); public boolean accept(File dir, String name) { String suffix = getSuffix(name); // Test lowercase varients only Enumeration e = theSuffixes.elements(); String aSuffix = null; while (e.hasMoreElements()) { aSuffix = (String)e.nextElement(); if ( suffix.equals(aSuffix) ) return true; } return false; } public void addSuffix(String inSuffix) { String suffix = inSuffix; if (suffix.charAt(0) == '.') suffix = suffix.substring(1); theSuffixes.addElement(suffix); } // Returns the suffix in lowercase without the "dot" private String getSuffix(String s) { String suffix = ""; int i = s.lastIndexOf('.'); if(i > 0 && i < s.length() - 1) suffix = s.substring(i+1).toLowerCase(); return suffix; } }