Skip to content

Instantly share code, notes, and snippets.

View Koboo's full-sized avatar
powered by coffee

Koboo

powered by coffee
View GitHub Profile
@Koboo
Koboo / Handle.java
Created June 11, 2021 07:24
Java Consumer imitation with up to 5 parameters
public interface Handle {
interface Two<T1, T2> {
void handle(T1 item1, T2 item2);
}
interface Three<T1, T2, T3> {
void handle(T1 item1, T2 item2, T3 item3);
}
@Koboo
Koboo / Tuple.java
Created June 11, 2021 07:05
Simple class to "fake" Tuple functionality from C# in java
public interface Tuple {
static <T extends Tuple, T1, T2> T create(T1 item1, T2 item2) {
return (T) new Two<>(item1, item2);
}
static <T extends Tuple, T1, T2, T3> T create(T1 item1, T2 item2, T3 item3) {
return (T) new Three<>(item1, item2, item3);
}
@Koboo
Koboo / MongoFilters.java
Last active October 5, 2021 06:46
MongoDB Java Driver Filter for equals ignore case / case insensitive
import com.mongodb.client.model.Filters;
import org.bson.conversions.Bson;
import java.util.regex.Pattern;
public class MongoFilters {
public static Bson eqIgn(String fieldName, String value) {
String patternString = new StringBuilder("(?i)^").append(value).append("$").toString();
Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);