-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #385 from dmlloyd/binary-search
- Loading branch information
Showing
15 changed files
with
1,735 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
function/src/main/java/io/smallrye/common/function/ExceptionObjIntFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.smallrye.common.function; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* A function which operates on an object and an integer, yielding an object. | ||
* | ||
* @param <T> the first argument type | ||
* @param <R> the result type | ||
* @param <E> the exception type | ||
*/ | ||
public interface ExceptionObjIntFunction<T, R, E extends Exception> { | ||
/** | ||
* Applies this function to the given arguments. | ||
* | ||
* @param arg1 the first argument | ||
* @param arg2 the second argument | ||
* @return the function result | ||
* @throws E if an exception occurs | ||
*/ | ||
R apply(T arg1, int arg2) throws E; | ||
|
||
/** | ||
* {@return a function that applies the given function to the result of this function} | ||
* | ||
* @param after the next function (must not be {@code null}) | ||
* @param <V> the final return type | ||
*/ | ||
default <V> ExceptionObjIntFunction<T, V, E> andThen(ExceptionFunction<? super R, ? extends V, ? extends E> after) { | ||
Objects.requireNonNull(after); | ||
return (T t, int u) -> after.apply(apply(t, u)); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
function/src/main/java/io/smallrye/common/function/ExceptionObjIntPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.smallrye.common.function; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* A predicate that operates on an object and an integer. | ||
* | ||
* @param <T> the first argument type | ||
* @param <E> the exception type | ||
*/ | ||
public interface ExceptionObjIntPredicate<T, E extends Exception> { | ||
/** | ||
* Evaluate this predicate on the given arguments. | ||
* | ||
* @param object the first argument | ||
* @param value the second argument | ||
* @return {@code true} if the predicate passes, {@code false} otherwise | ||
* @throws E if an exception occurs | ||
*/ | ||
boolean test(T object, int value) throws E; | ||
|
||
/** | ||
* {@return a predicate which is {@code true} only when this and the given predicate return {@code true}} | ||
* | ||
* @param other the other predicate (must not be {@code null}) | ||
*/ | ||
default ExceptionObjIntPredicate<T, E> and(ExceptionObjIntPredicate<? super T, ? extends E> other) { | ||
Objects.requireNonNull(other); | ||
return (t, i) -> test(t, i) && other.test(t, i); | ||
} | ||
|
||
/** | ||
* {@return a predicate which is {@code true} when this predicate is {@code false}, and vice-versa} | ||
*/ | ||
default ExceptionObjIntPredicate<T, E> negate() { | ||
return (t, i) -> !test(t, i); | ||
} | ||
|
||
/** | ||
* {@return a predicate which is {@code true} when either this or the given predicate return {@code true}} | ||
* | ||
* @param other the other predicate (must not be {@code null}) | ||
*/ | ||
default ExceptionObjIntPredicate<T, E> or(ExceptionObjIntPredicate<? super T, ? extends E> other) { | ||
Objects.requireNonNull(other); | ||
return (t, i) -> test(t, i) || other.test(t, i); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
function/src/main/java/io/smallrye/common/function/ExceptionObjLongFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.smallrye.common.function; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* A function which operates on an object and a long integer, yielding an object. | ||
* | ||
* @param <T> the first argument type | ||
* @param <R> the result type | ||
* @param <E> the exception type | ||
*/ | ||
public interface ExceptionObjLongFunction<T, R, E extends Exception> { | ||
/** | ||
* Applies this function to the given arguments. | ||
* | ||
* @param arg1 the first argument | ||
* @param arg2 the second argument | ||
* @return the function result | ||
* @throws E if an exception occurs | ||
*/ | ||
R apply(T arg1, long arg2) throws E; | ||
|
||
/** | ||
* {@return a function that applies the given function to the result of this function} | ||
* | ||
* @param after the next function (must not be {@code null}) | ||
* @param <V> the final return type | ||
*/ | ||
default <V> ExceptionObjLongFunction<T, V, E> andThen(ExceptionFunction<? super R, ? extends V, ? extends E> after) { | ||
Objects.requireNonNull(after); | ||
return (T t, long u) -> after.apply(apply(t, u)); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
function/src/main/java/io/smallrye/common/function/ExceptionObjLongPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.smallrye.common.function; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* A predicate that operates on an object and a long integer. | ||
* | ||
* @param <T> the first argument type | ||
* @param <E> the exception type | ||
*/ | ||
public interface ExceptionObjLongPredicate<T, E extends Exception> { | ||
/** | ||
* Evaluate this predicate on the given arguments. | ||
* | ||
* @param object the first argument | ||
* @param value the second argument | ||
* @return {@code true} if the predicate passes, {@code false} otherwise | ||
* @throws E if an exception occurs | ||
*/ | ||
boolean test(T object, long value) throws E; | ||
|
||
/** | ||
* {@return a predicate which is {@code true} only when this and the given predicate return {@code true}} | ||
* | ||
* @param other the other predicate (must not be {@code null}) | ||
*/ | ||
default ExceptionObjLongPredicate<T, E> and(ExceptionObjLongPredicate<? super T, ? extends E> other) { | ||
Objects.requireNonNull(other); | ||
return (t, i) -> test(t, i) && other.test(t, i); | ||
} | ||
|
||
/** | ||
* {@return a predicate which is {@code true} when this predicate is {@code false}, and vice-versa} | ||
*/ | ||
default ExceptionObjLongPredicate<T, E> negate() { | ||
return (t, i) -> !test(t, i); | ||
} | ||
|
||
/** | ||
* {@return a predicate which is {@code true} when either this or the given predicate return {@code true}} | ||
* | ||
* @param other the other predicate (must not be {@code null}) | ||
*/ | ||
default ExceptionObjLongPredicate<T, E> or(ExceptionObjLongPredicate<? super T, ? extends E> other) { | ||
Objects.requireNonNull(other); | ||
return (t, i) -> test(t, i) || other.test(t, i); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
function/src/main/java/io/smallrye/common/function/ObjIntFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.smallrye.common.function; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* A function which operates on an object and an integer, yielding an object. | ||
* | ||
* @param <T> the first argument type | ||
* @param <R> the result type | ||
*/ | ||
public interface ObjIntFunction<T, R> { | ||
/** | ||
* Applies this function to the given arguments. | ||
* | ||
* @param arg1 the first argument | ||
* @param arg2 the second argument | ||
* @return the function result | ||
*/ | ||
R apply(T arg1, int arg2); | ||
|
||
/** | ||
* {@return a function that applies the given function to the result of this function} | ||
* | ||
* @param after the next function (must not be {@code null}) | ||
* @param <V> the final return type | ||
*/ | ||
default <V> ObjIntFunction<T, V> andThen(Function<? super R, ? extends V> after) { | ||
Objects.requireNonNull(after); | ||
return (T t, int u) -> after.apply(apply(t, u)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
function/src/main/java/io/smallrye/common/function/ObjIntPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.smallrye.common.function; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* A predicate that operates on an object and an integer. | ||
* | ||
* @param <T> the first argument type | ||
*/ | ||
public interface ObjIntPredicate<T> { | ||
/** | ||
* Evaluate this predicate on the given arguments. | ||
* | ||
* @param object the first argument | ||
* @param value the second argument | ||
* @return {@code true} if the predicate passes, {@code false} otherwise | ||
*/ | ||
boolean test(T object, int value); | ||
|
||
/** | ||
* {@return a predicate which is {@code true} only when this and the given predicate return {@code true}} | ||
* | ||
* @param other the other predicate (must not be {@code null}) | ||
*/ | ||
default ObjIntPredicate<T> and(ObjIntPredicate<? super T> other) { | ||
Objects.requireNonNull(other); | ||
return (t, i) -> test(t, i) && other.test(t, i); | ||
} | ||
|
||
/** | ||
* {@return a predicate which is {@code true} when this predicate is {@code false}, and vice-versa} | ||
*/ | ||
default ObjIntPredicate<T> negate() { | ||
return (t, i) -> !test(t, i); | ||
} | ||
|
||
/** | ||
* {@return a predicate which is {@code true} when either this or the given predicate return {@code true}} | ||
* | ||
* @param other the other predicate (must not be {@code null}) | ||
*/ | ||
default ObjIntPredicate<T> or(ObjIntPredicate<? super T> other) { | ||
Objects.requireNonNull(other); | ||
return (t, i) -> test(t, i) || other.test(t, i); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
function/src/main/java/io/smallrye/common/function/ObjLongFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.smallrye.common.function; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* A function which operates on an object and a long integer, yielding an object. | ||
* | ||
* @param <T> the first argument type | ||
* @param <R> the result type | ||
*/ | ||
public interface ObjLongFunction<T, R> { | ||
/** | ||
* Applies this function to the given arguments. | ||
* | ||
* @param arg1 the first argument | ||
* @param arg2 the second argument | ||
* @return the function result | ||
*/ | ||
R apply(T arg1, long arg2); | ||
|
||
/** | ||
* {@return a function that applies the given function to the result of this function} | ||
* | ||
* @param after the next function (must not be {@code null}) | ||
* @param <V> the final return type | ||
*/ | ||
default <V> ObjLongFunction<T, V> andThen(Function<? super R, ? extends V> after) { | ||
Objects.requireNonNull(after); | ||
return (T t, long u) -> after.apply(apply(t, u)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
function/src/main/java/io/smallrye/common/function/ObjLongPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.smallrye.common.function; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* A predicate that operates on an object and a long integer. | ||
* | ||
* @param <T> the first argument type | ||
*/ | ||
public interface ObjLongPredicate<T> { | ||
/** | ||
* Evaluate this predicate on the given arguments. | ||
* | ||
* @param object the first argument | ||
* @param value the second argument | ||
* @return {@code true} if the predicate passes, {@code false} otherwise | ||
*/ | ||
boolean test(T object, long value); | ||
|
||
/** | ||
* {@return a predicate which is {@code true} only when this and the given predicate return {@code true}} | ||
* | ||
* @param other the other predicate (must not be {@code null}) | ||
*/ | ||
default ObjLongPredicate<T> and(ObjLongPredicate<? super T> other) { | ||
Objects.requireNonNull(other); | ||
return (t, i) -> test(t, i) && other.test(t, i); | ||
} | ||
|
||
/** | ||
* {@return a predicate which is {@code true} when this predicate is {@code false}, and vice-versa} | ||
*/ | ||
default ObjLongPredicate<T> negate() { | ||
return (t, i) -> !test(t, i); | ||
} | ||
|
||
/** | ||
* {@return a predicate which is {@code true} when either this or the given predicate return {@code true}} | ||
* | ||
* @param other the other predicate (must not be {@code null}) | ||
*/ | ||
default ObjLongPredicate<T> or(ObjLongPredicate<? super T> other) { | ||
Objects.requireNonNull(other); | ||
return (t, i) -> test(t, i) || other.test(t, i); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.smallrye.common</groupId> | ||
<artifactId>smallrye-common-parent</artifactId> | ||
<version>3.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>smallrye-common-search</artifactId> | ||
|
||
<name>SmallRye Common: Search</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>smallrye-common-function</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>coverage</id> | ||
<properties> | ||
<argLine>@{jacocoArgLine}</argLine> | ||
</properties> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>report</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>report</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
|
||
</project> |
Oops, something went wrong.