mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 23:39:39 +07:00
testdata IDEA-132560
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Collection<Integer> result = new LinkedList<>();
|
||||
Optional<A> _1 = Optional.of(new A());
|
||||
Optional<B> _2 = Optional.of(new B());
|
||||
BiFunction<Integer, Integer, Boolean> le = (a, b) -> a <= b;
|
||||
|
||||
addIfTrue(result, compareIfPresent(_1.map(A::getValue), _2.map(B::getValue), le), 3);
|
||||
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
private static <T, U> boolean compareIfPresent(Optional<T> arg1, Optional<U> arg2, BiFunction<T, U, Boolean> comparator) {
|
||||
if (!arg1.isPresent()) return true;
|
||||
if (!arg2.isPresent()) return true;
|
||||
return comparator.apply(arg1.get(), arg2.get());
|
||||
}
|
||||
|
||||
public static <T> void addIfTrue(Collection<T> list, boolean canAdd, T t) {
|
||||
if (canAdd) {
|
||||
addIfNotNull(list, t);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void addIfNotNull(Collection<T> list, T t) {
|
||||
if (t != null) {
|
||||
list.add(t);
|
||||
}
|
||||
}
|
||||
|
||||
static class A {
|
||||
public Integer getValue() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static class B {
|
||||
public Integer getValue() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user