You have already seen this many times yourself, of that I\'m sure:
public SomeObject findSomeObject(Arguments args) {
SomeObject so = queryFirstSource(args);
Yes, there is:
Arrays.asList(source1, source2, ...)
.stream()
.filter(s -> s != null)
.findFirst();
This is more flexible, since it returns an Optional
not null
in case a not-null source
is found.
Edit: If you want lazy evaluation you should use a Supplier
:
Arrays.>asList(sourceFactory::getSource1, sourceFactory::getSource2, ...)
.stream()
.filter(s -> s.get() != null)
.findFirst();