Skip to content

Commit

Permalink
Needs some compatability code for missing features in Android.
Browse files Browse the repository at this point in the history
  • Loading branch information
fbacchella committed Mar 19, 2023
1 parent 82db35b commit 86fa759
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 10 deletions.
23 changes: 23 additions & 0 deletions src/main/java/zmq/util/function/BiConsumer.java
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>This is a functional interface
* whose functional method is {@link #accept(Object, Object)}.
*
* @param <T> the type of the input to the operation
*
*/
public interface BiConsumer<T, U>
{
/**
* 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);
}
23 changes: 23 additions & 0 deletions src/main/java/zmq/util/function/Optional.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package zmq.util.function;

public class Optional<T>
{
private final T value;

private Optional(T value)
{
this.value = value;
}

public void ifPresent(Consumer<T> consumer)
{
if (value != null) {
consumer.accept(value);
}
}

public static <T> Optional<T> ofNullable(T value)
{
return new Optional<>(value);
}
}
8 changes: 4 additions & 4 deletions src/test/java/zmq/io/mechanism/MechanismTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/zmq/io/mechanism/SecurityCurveTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/zmq/io/mechanism/SecurityNullTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/zmq/io/mechanism/SecurityPlainTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 86fa759

Please sign in to comment.