Skip to content
Snippets Groups Projects
Commit 8a33b13e authored by ribeaudc's avatar ribeaudc
Browse files

remove: - 'NamePrefixFileFilter' - use one of the Apache commons implementations.

SVN: 6301
parent 84eb94f1
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2007 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.common.utilities;
import java.io.File;
import java.io.FileFilter;
/**
* A {@link FileFilter} that checks whether the name part of the <var>pathname</var> starts (or
* does not start) with the <var>prefix</var> specified.
*
* @author Bernd Rinn
*/
public class NamePrefixFileFilter implements FileFilter
{
private final String prefix;
private boolean shouldStartWithPrefix;
public NamePrefixFileFilter(String prefix, boolean shouldStartWithPrefix)
{
assert prefix != null;
this.prefix = prefix;
this.shouldStartWithPrefix = shouldStartWithPrefix;
}
public boolean accept(File pathname)
{
assert pathname != null;
final boolean startsWithPrefix = pathname.getName().startsWith(prefix);
return startsWithPrefix == shouldStartWithPrefix;
}
}
/*
* Copyright 2007 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.common.utilities;
import java.io.File;
import java.io.FileFilter;
import org.testng.annotations.Test;
/**
* Test cases for {@link NamePrefixFileFilter}.
*
* @author Bernd Rinn
*/
public class NamePrefixFileFilterTest
{
private static final String PREFIX = "PReFiX";
@Test
public void testNamePrefixShouldOccurAndFound()
{
final FileFilter filter = new NamePrefixFileFilter(PREFIX, true);
assert filter.accept(new File(PREFIX + "andSomePostFix.txt").getAbsoluteFile());
}
@Test
public void testNamePrefixShouldOccurButNotFound()
{
final FileFilter filter = new NamePrefixFileFilter(PREFIX, true);
assert filter.accept(new File("somefilewithouttheprefix.dat").getAbsoluteFile()) == false;
}
@Test
public void testNamePrefixShouldNotOccurAndNotFound()
{
final FileFilter filter = new NamePrefixFileFilter(PREFIX, false);
assert filter.accept(new File("somefilewithouttheprefix.dat").getAbsoluteFile());
}
@Test
public void testNamePrefixShouldNotOccurButFound()
{
final FileFilter filter = new NamePrefixFileFilter(PREFIX, false);
assert filter.accept(new File(PREFIX + "andSomePostFix.txt").getAbsoluteFile()) == false;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment