Here you can find the source of getFilenameFilter(final String pFilter, final boolean pExclude)
Parameter | Description |
---|---|
pFilter | The filter. |
pExclude | The exclude flag. |
public static final FilenameFilter getFilenameFilter(final String pFilter, final boolean pExclude)
//package com.java2s; /**/*from w w w . ja v a2s .co m*/ * (C) Copyright 2007, Deft Labs. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.io.FilenameFilter; public class Main { /** * Returns the file filter object. This checks the cache based on the * filter value. * @param pFilter The filter. * @param pExclude The exclude flag. */ public static final FilenameFilter getFilenameFilter(final String pFilter, final boolean pExclude) { return getFilenameFilter(pFilter, pExclude, false); } /** * Returns the file filter object. This checks the cache based on the * filter value. This method can be refactored :-) In a hurry now,. * @param pFilter The filter. * @param pExclude The exclude flag. * @param pEndsWith Make sure the suffix is there (in the filter). */ public static final FilenameFilter getFilenameFilter(final String pFilter, final boolean pExclude, final boolean pEndsWith) { FilenameFilter filter; if (pExclude) { if (pEndsWith) { filter = new FilenameFilter() { public boolean accept(final File pFile, final String pName) { return !pName.endsWith(pFilter); } }; } else { filter = new FilenameFilter() { public boolean accept(final File pFile, final String pName) { return (pName.indexOf(pFilter) == -1) ? true : false; } }; } } else { if (pEndsWith) { filter = new FilenameFilter() { public boolean accept(final File pFile, final String pName) { return pName.endsWith(pFilter); } }; } else { filter = new FilenameFilter() { public boolean accept(final File pFile, final String pName) { return (pName.indexOf(pFilter) != -1) ? true : false; } }; } } return filter; } }