Используйте List<IntSupplier>
и a для l oop:
int method(List<IntSupplier> list) {
int status = success;
for (Iterator<IntSupplier> it = list.iterator(); status == success && it.hasNext();) {
status = it.next().get();
}
return status;
}
Вызвать как:
int status = method(List.of(
() -> method0(arg0),
() -> method1(arg1) /* etc */));
(Конечно, List.of - это метод Java 9 . Составьте свой список так, как вам нравится).
Ваш CommandPipe
класс было бы довольно легко написать:
class CommandPipe {
int status = success;
CommandPipe next(IntSupplier supplier) {
if (status == success) {
status = supplier.get();
}
return this;
}
int getResult() { return status; }
}
Вызов, как вы написали в вопросе.