Skip to content

Commit

Permalink
Search submodule which initially includes binary search
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Jan 15, 2025
1 parent b5beae1 commit 7b0612a
Show file tree
Hide file tree
Showing 14 changed files with 1,487 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.smallrye.common.function;

import java.util.Objects;

/**
* A function which operates on an object and an integer, yielding an object.
*/
public interface ExceptionObjIntFunction<T, R, E extends Exception> {
R apply(T arg1, int arg2) throws E;

default <V> ExceptionObjIntFunction<T, V, E> andThen(ExceptionFunction<? super R, ? extends V, ? extends E> after)
throws E {
Objects.requireNonNull(after);
return (T t, int u) -> after.apply(apply(t, u));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.smallrye.common.function;

import java.util.Objects;

/**
* A predicate that operates on an object and an integer.
*/
public interface ExceptionObjIntPredicate<T, E extends Exception> {
boolean test(T object, int value) throws E;

default ExceptionObjIntPredicate<T, E> and(ExceptionObjIntPredicate<? super T, ? extends E> other) {
Objects.requireNonNull(other);
return (t, i) -> test(t, i) && other.test(t, i);
}

default ExceptionObjIntPredicate<T, E> negate() {
return (t, i) -> !test(t, i);
}

default ExceptionObjIntPredicate<T, E> or(ExceptionObjIntPredicate<? super T, ? extends E> other) {
Objects.requireNonNull(other);
return (t, i) -> test(t, i) || other.test(t, i);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.smallrye.common.function;

import java.util.Objects;

/**
* A function which operates on an object and a long integer, yielding an object.
*/
public interface ExceptionObjLongFunction<T, R, E extends Exception> {
R apply(T arg1, long arg2) throws E;

default <V> ExceptionObjLongFunction<T, V, E> andThen(ExceptionFunction<? super R, ? extends V, ? extends E> after)
throws E {
Objects.requireNonNull(after);
return (T t, long u) -> after.apply(apply(t, u));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.smallrye.common.function;

import java.util.Objects;

/**
* A predicate that operates on an object and a long integer.
*/
public interface ExceptionObjLongPredicate<T, E extends Exception> {
boolean test(T object, long value);

default ExceptionObjLongPredicate<T, E> and(ExceptionObjLongPredicate<? super T, ? extends E> other) {
Objects.requireNonNull(other);
return (t, i) -> test(t, i) && other.test(t, i);
}

default ExceptionObjLongPredicate<T, E> negate() {
return (t, i) -> !test(t, i);
}

default ExceptionObjLongPredicate<T, E> or(ExceptionObjLongPredicate<? super T, ? extends E> other) {
Objects.requireNonNull(other);
return (t, i) -> test(t, i) || other.test(t, i);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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.
*/
public interface ObjIntFunction<T, R> {
R apply(T arg1, int arg2);

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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.smallrye.common.function;

import java.util.Objects;

/**
* A predicate that operates on an object and an integer.
*/
public interface ObjIntPredicate<T> {
boolean test(T object, int value);

default ObjIntPredicate<T> and(ObjIntPredicate<? super T> other) {
Objects.requireNonNull(other);
return (t, i) -> test(t, i) && other.test(t, i);
}

default ObjIntPredicate<T> negate() {
return (t, i) -> !test(t, i);
}

default ObjIntPredicate<T> or(ObjIntPredicate<? super T> other) {
Objects.requireNonNull(other);
return (t, i) -> test(t, i) || other.test(t, i);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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.
*/
public interface ObjLongFunction<T, R> {
R apply(T arg1, long arg2);

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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.smallrye.common.function;

import java.util.Objects;

/**
* A predicate that operates on an object and a long integer.
*/
public interface ObjLongPredicate<T> {
boolean test(T object, long value);

default ObjLongPredicate<T> and(ObjLongPredicate<? super T> other) {
Objects.requireNonNull(other);
return (t, i) -> test(t, i) && other.test(t, i);
}

default ObjLongPredicate<T> negate() {
return (t, i) -> !test(t, i);
}

default ObjLongPredicate<T> or(ObjLongPredicate<? super T> other) {
Objects.requireNonNull(other);
return (t, i) -> test(t, i) || other.test(t, i);
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<module>os</module>
<module>ref</module>
<module>resource</module>
<module>search</module>
<module>version</module>
<module>vertx-context</module>
</modules>
Expand Down
56 changes: 56 additions & 0 deletions search/pom.xml
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>
Loading

0 comments on commit 7b0612a

Please sign in to comment.