From 86fa75973c67df92191d7733544dd666ac7900d4 Mon Sep 17 00:00:00 2001 From: Fabrice Bacchella Date: Sun, 19 Mar 2023 20:36:41 +0100 Subject: [PATCH] Needs some compatability code for missing features in Android. --- .../java/zmq/util/function/BiConsumer.java | 23 +++++++++++++++++++ src/main/java/zmq/util/function/Optional.java | 23 +++++++++++++++++++ .../zmq/io/mechanism/MechanismTester.java | 8 +++---- .../zmq/io/mechanism/SecurityCurveTest.java | 4 ++-- .../zmq/io/mechanism/SecurityNullTest.java | 4 ++-- .../zmq/io/mechanism/SecurityPlainTest.java | 4 ++-- 6 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 src/main/java/zmq/util/function/BiConsumer.java create mode 100644 src/main/java/zmq/util/function/Optional.java diff --git a/src/main/java/zmq/util/function/BiConsumer.java b/src/main/java/zmq/util/function/BiConsumer.java new file mode 100644 index 000000000..33df7d8f9 --- /dev/null +++ b/src/main/java/zmq/util/function/BiConsumer.java @@ -0,0 +1,23 @@ +package zmq.util.function; + +/** + Represents an operation that accepts two input arguments and returns no result. This is the two-arity specialization of Consumer. + Unlike most other functional interfaces, {@link BiConsumer} is expected to operate via side-effects. + + * + *

This is a functional interface + * whose functional method is {@link #accept(Object, Object)}. + * + * @param the type of the input to the operation + * + */ +public interface BiConsumer +{ + /** + * Performs this operation on the given argument. + * + * @param t the first input argument + * @param t the second input argument + */ + void accept(T t, U u); +} diff --git a/src/main/java/zmq/util/function/Optional.java b/src/main/java/zmq/util/function/Optional.java new file mode 100644 index 000000000..875061c79 --- /dev/null +++ b/src/main/java/zmq/util/function/Optional.java @@ -0,0 +1,23 @@ +package zmq.util.function; + +public class Optional +{ + private final T value; + + private Optional(T value) + { + this.value = value; + } + + public void ifPresent(Consumer consumer) + { + if (value != null) { + consumer.accept(value); + } + } + + public static Optional ofNullable(T value) + { + return new Optional<>(value); + } +} diff --git a/src/test/java/zmq/io/mechanism/MechanismTester.java b/src/test/java/zmq/io/mechanism/MechanismTester.java index 17285f35a..342720b42 100644 --- a/src/test/java/zmq/io/mechanism/MechanismTester.java +++ b/src/test/java/zmq/io/mechanism/MechanismTester.java @@ -3,14 +3,10 @@ import java.io.IOException; import java.io.OutputStream; import java.net.Socket; -import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.function.BiFunction; -import java.util.function.Consumer; -import java.util.function.Function; import zmq.Ctx; import zmq.Helper; @@ -19,6 +15,10 @@ import zmq.SocketBase; import zmq.ZMQ; import zmq.util.TestUtils; +import zmq.util.function.BiFunction; +import zmq.util.function.Function; +import zmq.util.function.Consumer; +import zmq.util.function.Optional; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; diff --git a/src/test/java/zmq/io/mechanism/SecurityCurveTest.java b/src/test/java/zmq/io/mechanism/SecurityCurveTest.java index d2f138bc0..f9bdb8f3e 100644 --- a/src/test/java/zmq/io/mechanism/SecurityCurveTest.java +++ b/src/test/java/zmq/io/mechanism/SecurityCurveTest.java @@ -1,14 +1,14 @@ package zmq.io.mechanism; import java.util.concurrent.CompletableFuture; -import java.util.function.BiFunction; -import java.util.function.Function; import org.junit.Test; import zmq.SocketBase; import zmq.ZMQ; import zmq.io.mechanism.curve.Curve; +import zmq.util.function.BiFunction; +import zmq.util.function.Function; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; diff --git a/src/test/java/zmq/io/mechanism/SecurityNullTest.java b/src/test/java/zmq/io/mechanism/SecurityNullTest.java index 468bfba43..05d81d65d 100644 --- a/src/test/java/zmq/io/mechanism/SecurityNullTest.java +++ b/src/test/java/zmq/io/mechanism/SecurityNullTest.java @@ -1,13 +1,13 @@ package zmq.io.mechanism; import java.util.concurrent.CompletableFuture; -import java.util.function.BiFunction; -import java.util.function.Function; import org.junit.Test; import zmq.SocketBase; import zmq.ZMQ; +import zmq.util.function.BiFunction; +import zmq.util.function.Function; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; diff --git a/src/test/java/zmq/io/mechanism/SecurityPlainTest.java b/src/test/java/zmq/io/mechanism/SecurityPlainTest.java index a80f986b5..845facc52 100644 --- a/src/test/java/zmq/io/mechanism/SecurityPlainTest.java +++ b/src/test/java/zmq/io/mechanism/SecurityPlainTest.java @@ -1,13 +1,13 @@ package zmq.io.mechanism; import java.util.concurrent.CompletableFuture; -import java.util.function.BiFunction; -import java.util.function.Function; import org.junit.Test; import zmq.SocketBase; import zmq.ZMQ; +import zmq.util.function.BiFunction; +import zmq.util.function.Function; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue;