package business; import java.util.function.Function; import java.util.function.Supplier; public interface StatefulSupplier extends Supplier { class StatefulSupplierImpl implements StatefulSupplier { private S state; private Function getter; private StatefulSupplierImpl(S state, Function getter) { this.state = state; this.getter = getter; } @Override public T get(S s) { return getter.apply(s); } public T get() { return get(state); } } T get(S s); static StatefulSupplier get(S state, Function getter) { return new StatefulSupplierImpl<>(state, getter); } }