You have already seen this many times yourself, of that I\'m sure:
public SomeObject findSomeObject(Arguments args) {
SomeObject so = queryFirstSource(args);
I would write it like this (you may not need generics here but why not do it):
public static Optional findFirst(Predicate predicate, A argument,
Function... functions) {
return Arrays.stream(functions)
.map(f -> f.apply(argument))
.filter(predicate::test)
.findFirst();
}
And you can call it with:
return findFirst(Objects::nonNull, args, this::queryFirstSource,
this::querySecondSource,
this::queryThirdSource);
(assuming your queryXXX
methods are instance methods)
The methods will be applied in order until one returns a value that matches the predicate (in the example above: returns a non null value).