class OptionalUtils {

    public static <T, U> boolean matches(Optional<T> optional1, Optional<U> optional2, BiPredicate<T, U> biPredicate) {
        return optional1.map(value1 ->
            optional2
                .map(value2 -> biPredicate.test(value1, value2))
                .orElse(false))
            .orElse(false);
    }

}