Skip to content

Commit d05e9cc

Browse files
committed
Add IORunnable.noop()
1 parent 64f321b commit d05e9cc

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ The <action> type attribute can be add,update,fix,remove.
102102
<action dev="ggregory" type="add" due-to="Gary Gregory">Add BrokenInputStream.Builder.</action>
103103
<action dev="ggregory" type="add" due-to="Gary Gregory">Add PathUtils.getExtension(Path).</action>
104104
<action dev="ggregory" type="add" due-to="Gary Gregory">Add ThrottledInputStream.</action>
105+
<action dev="ggregory" type="add" due-to="Gary Gregory">Add IORunnable.noop().</action>
105106
<!-- UPDATE -->
106107
<action dev="ggregory" type="fix" due-to="Gary Gregory">Bump commons.bytebuddy.version from 1.14.10 to 1.14.11 #534.</action>
107108
</release>

src/main/java/org/apache/commons/io/function/Constants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ final class Constants {
2828
@SuppressWarnings("rawtypes")
2929
static final IOBiConsumer IO_BI_CONSUMER = (t, u) -> {/* No-op */};
3030

31+
/**
32+
* No-op singleton.
33+
*/
34+
static final IORunnable IO_RUNNABLE = () -> {/* No-op */};
35+
3136
/**
3237
* No-op singleton.
3338
*/

src/main/java/org/apache/commons/io/function/IORunnable.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
@FunctionalInterface
2929
public interface IORunnable {
3030

31+
/**
32+
* Returns the constant no-op runnable.
33+
*
34+
* @return a constant no-op runnable.
35+
* @since 2.16.0
36+
*/
37+
static IORunnable noop() {
38+
return Constants.IO_RUNNABLE;
39+
}
40+
3141
/**
3242
* Creates a {@link Runnable} for this instance that throws {@link UncheckedIOException} instead of {@link IOException}.
3343
*

src/test/java/org/apache/commons/io/function/IORunnableTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.junit.jupiter.api.Assertions.assertEquals;
2121
import static org.junit.jupiter.api.Assertions.assertNull;
2222
import static org.junit.jupiter.api.Assertions.assertThrows;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2324

2425
import java.io.IOException;
2526
import java.io.UncheckedIOException;
@@ -55,4 +56,11 @@ public void testAsRunnable() throws Exception {
5556
assertNull(Executors.callable(runnable.asRunnable()).call());
5657
}
5758

59+
@SuppressWarnings("cast")
60+
@Test
61+
public void testNoop() throws IOException {
62+
assertTrue(IORunnable.noop() instanceof IORunnable);
63+
IORunnable.noop().run();
64+
}
65+
5866
}

0 commit comments

Comments
 (0)