This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git


The following commit(s) were added to refs/heads/master by this push:
     new 69c9a28  [VFS-734] Add functional interface 
org.apache.commons.vfs2.function.VfsConsumer.
69c9a28 is described below

commit 69c9a28b1c00748e31c3042251a8a66a91fcc824
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Oct 5 16:35:30 2019 -0400

    [VFS-734] Add functional interface
    org.apache.commons.vfs2.function.VfsConsumer.
---
 .../apache/commons/vfs2/function/VfsConsumer.java  | 59 ++++++++++++++++++++++
 .../commons/vfs2/function/VfsConsumerTest.java     | 47 +++++++++++++++++
 src/changes/changes.xml                            |  3 ++
 3 files changed, 109 insertions(+)

diff --git 
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/function/VfsConsumer.java 
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/function/VfsConsumer.java
new file mode 100644
index 0000000..075f619
--- /dev/null
+++ 
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/function/VfsConsumer.java
@@ -0,0 +1,59 @@
+/*
+ * 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.function;
+
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+
+/**
+ * A {@link java.util.function.Consumer} that throws {@link 
FileSystemException}.
+ *
+ * @param <T> the type of the input to the operation
+ *
+ * @since 2.5.0
+ */
+@FunctionalInterface
+public interface VfsConsumer<T> {
+
+    /**
+     * Performs this operation on the given argument.
+     *
+     * @param t the input argument
+     * @throws FileSystemException Thrown when VFS detects an error.
+     */
+    void accept(T t) throws FileSystemException;
+
+    /**
+     * Returns a composed {@code Consumer} that performs, in sequence, this 
operation followed by the {@code after}
+     * operation. If performing either operation throws an exception, it is 
relayed to the caller of the composed
+     * operation. If performing this operation throws an exception, the {@code 
after} operation will not be performed.
+     *
+     * @param after the operation to perform after this operation
+     * @return a composed {@code Consumer} that performs in sequence this 
operation followed by the {@code after}
+     *         operation
+     * @throws NullPointerException if {@code after} is null
+     */
+    default VfsConsumer<T> andThen(VfsConsumer<? super T> after) {
+        Objects.requireNonNull(after);
+        return (T t) -> {
+            accept(t);
+            after.accept(t);
+        };
+    }
+}
\ No newline at end of file
diff --git 
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/function/VfsConsumerTest.java
 
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/function/VfsConsumerTest.java
new file mode 100644
index 0000000..197d8d8
--- /dev/null
+++ 
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/function/VfsConsumerTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.function;
+
+import java.nio.file.Paths;
+
+import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.VFS;
+import org.junit.Test;
+
+/**
+ * Tests {@link VfsConsumer}.
+ * 
+ * @since 2.5.0
+ */
+public class VfsConsumerTest {
+
+    /**
+     * Tests {@link VfsConsumer}.
+     */
+    @Test
+    public void test() throws FileSystemException {
+        test(fileObject -> fileObject.exists());
+    }
+
+    private void test(VfsConsumer<FileObject> consumer) throws 
FileSystemException {
+        try (FileObject fileObject = 
VFS.getManager().resolveFile(Paths.get("DoesNotExist.not)").toUri())) {
+            consumer.accept(fileObject);
+        }
+    }
+}
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d2d98f6..cefecec 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -77,6 +77,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="update" due-to="Gary Gregory">
         Update tests using org.mockito:mockito-core from 3.0.0 to 3.1.0.
       </action>
+      <action issue="VFS-734" dev="ggregory" type="update" due-to="Gary 
Gregory">
+        Add functional interface org.apache.commons.vfs2.function.VfsConsumer.
+      </action>
     </release>
     <release version="2.4.1" date="2019-08-10" description="Bug fix release.">
       <action issue="VFS-725" dev="ggregory" type="fix" due-to="Gary Gregory">

Reply via email to