fork download
  1. import java.util.stream.Stream;
  2. import java.util.Objects;
  3. import java.util.List;
  4.  
  5. class Ideone {
  6. public static void main (String[] args) {
  7. System.out.println(
  8. isAnyFooNullOrDoesAnyGetBarReturnNull(new Foo[]{
  9. new Foo(new Bar()),
  10. new Foo(new Bar())
  11. }));
  12. System.out.println(
  13. isAnyFooNullOrDoesAnyGetBarReturnNull(new Foo[]{
  14. new Foo(null),
  15. new Foo(new Bar())
  16. }));
  17. System.out.println(
  18. isAnyFooNullOrDoesAnyGetBarReturnNull(new Foo[]{
  19. null,
  20. new Foo(new Bar())
  21. }));
  22. }
  23.  
  24. public static boolean isAnyFooNullOrDoesAnyGetBarReturnNull(Foo... foos) {
  25. return Stream.of(foos)
  26. .map(foo -> Objects.isNull(foo) || Objects.isNull(foo.getBar()))
  27. .reduce(false, Boolean::logicalOr);
  28. }
  29. }
  30.  
  31. class Foo {
  32. private final Bar bar;
  33.  
  34. public Foo(final Bar bar) {
  35. this.bar = bar;
  36. }
  37.  
  38. public final Bar getBar() {
  39. return bar;
  40. }
  41. }
  42.  
  43. class Bar {}
Success #stdin #stdout 0.08s 34092KB
stdin
Standard input is empty
stdout
false
true
true