- deleted useless new StringBuilder allocation - use of a new reusable FileNameFilter - added javadocpull/12/head
parent
c1d937a90c
commit
7e4c1d2282
@ -0,0 +1,83 @@
|
||||
// SourceFileFilter.java
|
||||
// -------------------------------------
|
||||
// part of YACY
|
||||
// (C) by Michael Peter Christen; mc@yacy.net
|
||||
// first published on http://www.anomic.de
|
||||
// Frankfurt, Germany, 2004
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $LastChangedBy$
|
||||
//
|
||||
// This program 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 2 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 General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package net.yacy.utils.translation;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* File filter for source files to translate
|
||||
*
|
||||
* @author luc
|
||||
*
|
||||
*/
|
||||
public class SourceFileFilter implements FilenameFilter {
|
||||
|
||||
/** Extensions required to pass filter */
|
||||
private List<String> extensions;
|
||||
|
||||
/**
|
||||
* Contructor with extensions
|
||||
*
|
||||
* @param extensions
|
||||
* extensions required. When this list is null or empty, filter
|
||||
* let pass all files.
|
||||
*/
|
||||
public SourceFileFilter(List<String> extensions) {
|
||||
if (extensions == null) {
|
||||
this.extensions = new ArrayList<>();
|
||||
} else {
|
||||
this.extensions = new ArrayList<>(extensions);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param file
|
||||
* file to check
|
||||
* @return true when file name ends with one of the extensions list or
|
||||
* extensions list is empty
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
boolean accepted = false;
|
||||
if (name != null) {
|
||||
if (extensions.size() == 0) {
|
||||
accepted = true;
|
||||
} else {
|
||||
for (String ext : extensions) {
|
||||
if (name.endsWith(ext)) {
|
||||
accepted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return accepted;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue