1 15 16 18 36 package ixenon.free.nodes; 37 38 import java.io.*; 39 import java.util.*; 40 41 public class SimpleFilenameFilter implements FilenameFilter 42 { 43 45 public final static int MATCH_BEGINNING = 1; 46 47 49 public final static int MATCH_MIDDLE = 2; 50 51 53 public final static int MATCH_END = 3; 54 55 56 private int matchType; 58 private Vector matchList; 59 60 65 public SimpleFilenameFilter( String matchString ) 66 { 67 this( matchString, MATCH_END ); 68 } 69 70 79 public SimpleFilenameFilter( String matchString, int matchType ) 80 { 81 this( new String [] { matchString }, matchType ); 82 } 83 84 89 public SimpleFilenameFilter( String [] matches ) 90 { 91 this( matches, MATCH_END ); 92 } 93 94 103 public SimpleFilenameFilter( String [] matches, int matchType ) { 104 this.matchType = matchType; 105 matchList = new Vector(); 106 107 for (int k=0; k<matches.length; ++k) 108 if ( matches[k] != null ) 109 matchList.addElement( matches[k] ); 110 } 111 112 117 public boolean accept(File dir, String name) { 118 File file = new File( dir, name ); 119 if (!file.isFile() ) 120 return (false); 121 122 for (int k=0; k<matchList.size(); ++k) { 123 String matchString = (String )matchList.elementAt(k); 124 switch (matchType) { 125 case MATCH_BEGINNING: 126 if (name.startsWith(matchString)) 128 return (true); 129 130 case MATCH_MIDDLE: 131 if (name.indexOf(matchString) >= 0) 133 return (true); 134 135 case MATCH_END: 136 if (name.endsWith(matchString)) 138 return (true); 139 } 140 } 141 142 return (false); 143 } 144 } 145 146 | Popular Tags |