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-io.git


The following commit(s) were added to refs/heads/master by this push:
     new d05e9cc0 Add IORunnable.noop()
     new 063463f5 Merge branch 'master' of 
https://ggreg...@gitbox.apache.org/repos/asf/commons-io.git
d05e9cc0 is described below

commit d05e9cc0e72f0b095e947e0d24abf064f0a7a3dc
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Dec 28 17:31:53 2023 -0500

    Add IORunnable.noop()
---
 src/changes/changes.xml                                        |  1 +
 src/main/java/org/apache/commons/io/function/Constants.java    |  5 +++++
 src/main/java/org/apache/commons/io/function/IORunnable.java   | 10 ++++++++++
 .../java/org/apache/commons/io/function/IORunnableTest.java    |  8 ++++++++
 4 files changed, 24 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 21dfffab..96efbcd2 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -102,6 +102,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="add"                due-to="Gary 
Gregory">Add BrokenInputStream.Builder.</action>
       <action dev="ggregory" type="add"                due-to="Gary 
Gregory">Add PathUtils.getExtension(Path).</action>
       <action dev="ggregory" type="add"                due-to="Gary 
Gregory">Add ThrottledInputStream.</action>
+      <action dev="ggregory" type="add"                due-to="Gary 
Gregory">Add IORunnable.noop().</action>
       <!--  UPDATE -->
       <action dev="ggregory" type="fix"                due-to="Gary 
Gregory">Bump commons.bytebuddy.version from 1.14.10 to 1.14.11 #534.</action>
     </release>
diff --git a/src/main/java/org/apache/commons/io/function/Constants.java 
b/src/main/java/org/apache/commons/io/function/Constants.java
index 6ad3a63c..89dd4c5a 100644
--- a/src/main/java/org/apache/commons/io/function/Constants.java
+++ b/src/main/java/org/apache/commons/io/function/Constants.java
@@ -28,6 +28,11 @@ final class Constants {
     @SuppressWarnings("rawtypes")
     static final IOBiConsumer IO_BI_CONSUMER = (t, u) -> {/* No-op */};
 
+    /**
+     * No-op singleton.
+     */
+    static final IORunnable IO_RUNNABLE = () -> {/* No-op */};
+
     /**
      * No-op singleton.
      */
diff --git a/src/main/java/org/apache/commons/io/function/IORunnable.java 
b/src/main/java/org/apache/commons/io/function/IORunnable.java
index 60b76bd7..4d20a96b 100644
--- a/src/main/java/org/apache/commons/io/function/IORunnable.java
+++ b/src/main/java/org/apache/commons/io/function/IORunnable.java
@@ -28,6 +28,16 @@ import java.io.UncheckedIOException;
 @FunctionalInterface
 public interface IORunnable {
 
+    /**
+     * Returns the constant no-op runnable.
+     *
+     * @return a constant no-op runnable.
+     * @since 2.16.0
+     */
+    static IORunnable noop() {
+        return Constants.IO_RUNNABLE;
+    }
+
     /**
      * Creates a {@link Runnable} for this instance that throws {@link 
UncheckedIOException} instead of {@link IOException}.
      *
diff --git a/src/test/java/org/apache/commons/io/function/IORunnableTest.java 
b/src/test/java/org/apache/commons/io/function/IORunnableTest.java
index 4788f6ee..a73038c3 100644
--- a/src/test/java/org/apache/commons/io/function/IORunnableTest.java
+++ b/src/test/java/org/apache/commons/io/function/IORunnableTest.java
@@ -20,6 +20,7 @@ package org.apache.commons.io.function;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.IOException;
 import java.io.UncheckedIOException;
@@ -55,4 +56,11 @@ public class IORunnableTest {
         assertNull(Executors.callable(runnable.asRunnable()).call());
     }
 
+    @SuppressWarnings("cast")
+    @Test
+    public void testNoop() throws IOException {
+        assertTrue(IORunnable.noop() instanceof IORunnable);
+        IORunnable.noop().run();
+    }
+
 }

Reply via email to