So, I have this method that runs repeatedly.
public static boolean isReady(String dirPath, int numPdfInPrintJob){
File dir = new File(dirPath);
String[] fileList = dir.list(new FilenameFilter(){
public boolean accept(File file, String filename) {
return (filename.toLowerCase().endsWith(".pdf"));
}
});
if(fileList.length >= numPdfInPrintJob) return true;
else return false;
}
This method uses anonymous classthat will create a new instance FilenameFilterwith each call and call this method many times. So I want to do it anonymous classin singleton. So my initial thought was to create a new class singletonthat looks like this:
public class PdfFileNameFilter implements FilenameFilter{
private PdfFileNameFilter(){}
public static final PdfFileNameFilter INSTANCE = new PdfFileNameFilter();
public boolean accept(File dir, String name) {
return (name.toLowerCase().endsWith(".pdf"));
}
}
Can I reorganize this a little more. I also need to do ZipFileNameFilterand possibly many different file extensions. Do not want to create a class for each filter. I need to reorganize this project a little more. Maybe interfacecome to a place somewhere here.