/** * Creates an instance with the supplied value. */ public static <T> Alternative<T> preferred(final T value) { return new Alternative<>(value); }
/** * Returns itself (unchanged) iff current value != null, * otherwise returns a new instance with the value supplied by the supplier. */ public Alternative<T> alternatively(final Supplier<? extends T> supplier) { if (value != null) { return this; } return new Alternative<>(supplier.get()); }