Author: ggregory Date: Sat Jan 21 22:23:53 2017 New Revision: 1779762 URL: http://svn.apache.org/viewvc?rev=1779762&view=rev Log: [VFS-628] Add a file inverter FileSelector: InvertIncludeFileSelector.
Added: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/InvertIncludeFileSelector.java commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/InvertIncludeFileSelectorTest.java Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/PatternFileSelectorTest.java commons/proper/vfs/trunk/src/changes/changes.xml Added: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/InvertIncludeFileSelector.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/InvertIncludeFileSelector.java?rev=1779762&view=auto ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/InvertIncludeFileSelector.java (added) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/InvertIncludeFileSelector.java Sat Jan 21 22:23:53 2017 @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.commons.vfs2; + +import java.util.Objects; + +/** + * Inverts file inclusion of a delegate FileSelector, folder traversal is delegated. + * + * @since 2.2 + */ +public class InvertIncludeFileSelector implements FileSelector { + + public InvertIncludeFileSelector(final FileSelector delegateFileSelector) { + this.delegateFileSelector = Objects.requireNonNull(delegateFileSelector, "delegateFileSelector"); + } + + private final FileSelector delegateFileSelector; + + /** + * Inverts the result of calling {@link #includeFile(FileSelectInfo)} on the delegate. + */ + @Override + public boolean includeFile(final FileSelectInfo fileInfo) throws Exception { + return !delegateFileSelector.includeFile(fileInfo); + } + + /** + * Calls {@link #traverseDescendents(FileSelectInfo)} on the delegate. + */ + @Override + public boolean traverseDescendents(final FileSelectInfo fileInfo) throws Exception { + return delegateFileSelector.traverseDescendents(fileInfo); + } + +} Added: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/InvertIncludeFileSelectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/InvertIncludeFileSelectorTest.java?rev=1779762&view=auto ============================================================================== --- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/InvertIncludeFileSelectorTest.java (added) +++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/InvertIncludeFileSelectorTest.java Sat Jan 21 22:23:53 2017 @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.commons.vfs2; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class InvertIncludeFileSelectorTest { + + @BeforeClass + public static void setUpClass() throws Exception { + PatternFileSelectorTest.setUpClass(); + } + + @AfterClass + public static void tearDownClass() throws Exception { + PatternFileSelectorTest.tearDownClass(); + } + + @Test + public void testInvertMatchAll() throws Exception { + final FileObject[] list = PatternFileSelectorTest.getBaseFolder() + .findFiles(new InvertIncludeFileSelector(new PatternFileSelector(".*"))); + Assert.assertEquals(0, list.length); + } + + @Test + public void testInvertMatchSome() throws Exception { + final FileObject[] list = PatternFileSelectorTest.getBaseFolder() + .findFiles(new InvertIncludeFileSelector(new PatternFileSelector(".*\\.html"))); + Assert.assertEquals(7, list.length); + } + +} Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/PatternFileSelectorTest.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/PatternFileSelectorTest.java?rev=1779762&r1=1779761&r2=1779762&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/PatternFileSelectorTest.java (original) +++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/PatternFileSelectorTest.java Sat Jan 21 22:23:53 2017 @@ -139,4 +139,8 @@ public class PatternFileSelectorTest } } + static FileObject getBaseFolder() { + return BaseFolder; + } + } Modified: commons/proper/vfs/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1779762&r1=1779761&r2=1779762&view=diff ============================================================================== --- commons/proper/vfs/trunk/src/changes/changes.xml (original) +++ commons/proper/vfs/trunk/src/changes/changes.xml Sat Jan 21 22:23:53 2017 @@ -50,6 +50,9 @@ The <action> type attribute can be add,u <!-- [Local] Need an easy way to convert from a FileObject to a File. --> <!-- </action> --> <!-- START Might need to be moved to the next version --> + <action issue="VFS-628" dev="ggregory" type="add"> + Add a file inverter FileSelector: InvertIncludeFileSelector. + </action> <action issue="VFS-612" dev="ggregory" type="update"> Update the platform requirement from Java 6 to Java 7. </action>