/**
* MediaFileFilter.java
*
* Copyright (c) 2009 Brian Gibowski <brian@brgib.com>. All rights reserved.
*
* This file is part of iTunesDSM.
*
* iTunesDSM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTunesDSM 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 General Public License
* along with iTunesDSM. If not, see <http://www.gnu.org/licenses/>.
*/
package core.filter;
import java.io.File;
import java.io.FilenameFilter;
/**
* This class provides the file filter for the DuplicatesTask class.
*
* @author Brian Gibowski brian@brgib.com
*/
public class MediaFileFilter implements FilenameFilter{
private String[] fileExtensions;
private String description = "Media Files";
/**
* Creates a new MediaFileFilter object given an array of file extensions.
* @param ext the extensions to filter files by.
*/
public MediaFileFilter(String[] ext){
fileExtensions = ext;
}
/**
* This method will determine whether to accept a file or not through the file
* filter based on whether or not the file name ends with one of the given extension.
*
* @param dir the File to check for acceptance by the filter.
*
* @param name the file name of the given file.
*
* @return whether or not the file is acceptable file given the extensions to accept.
*/
@Override
public boolean accept(File dir, String name) {
for(int i=0; i<fileExtensions.length; i++){
if (name.toLowerCase().endsWith(fileExtensions[i])) {
return true;
}
}
return false;
}
/**
* Returns the description of the extensions to accept.
*
* @return the description of the extensions to accept.
*/
public String getDescription(){
return description;
}
}
|