/* * [NoSnippetsFilter.java] * * Summary: FileFilter filters out the snippets directories. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2009-11-09 initial version */ package com.mindprod.acronym; import com.mindprod.common18.EIO; import java.io.File; import java.io.FilenameFilter; import java.util.regex.Pattern; /** * FileFilter filters out the snippets directories. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2009-11-09 initial version * @since 2009-11-09 */ final class NoSnippetsFilter implements FilenameFilter { /** * split directory name into legs separated by \ or / */ private static final Pattern SPLIT_ON_SLASH = Pattern.compile( "[/\\\\]" ); /** * constructor */ public NoSnippetsFilter() { } /** * Select only files with that pass muster, dir but no snippet in name. * * @param dir the directory in which the file was found. * @param name the name of the file * * @return true if and only if the name should be included in the file list; false otherwise. */ public boolean accept( File dir, String name ) { final File f = new File( dir, name ); if ( f.isFile() || name.equals( "foot" ) || name.equals( "snippet" ) || name.equals( "image" ) || name.equals( "kjv" ) || name.equals( "sound" ) ) { return false; } final String[] legs = SPLIT_ON_SLASH.split( EIO.getCanOrAbsPath( dir ) ); for ( String leg : legs ) { if ( leg.equals( "snippet" ) || leg.equals( "image" ) || leg.equals( "kjv" ) || leg.equals( "sound" ) ) { return false; } } return true; } }