/** * Creates a new <tt>ValueHolder</tt> with the given initial value. * <p> * This method can be used instead of a constructor, so that the type parameters don't need to be re-typed. * * @param initialValue sets the value of the value holder * @param <T> the type of the value being held by this <tt>ValueHolder</tt> * @return a new ValueHolder initialized with the given value. */ public static <T> ValueHolder<T> of(T initialValue) { return new ValueHolder<>(initialValue); }
/** * Marks the promise as successful and completed with the given value. * * @param value the value to be used as promised result. * @return <tt>this</tt> for fluent method chaining */ public Promise<V> success(@Nullable final V value) { this.value = new ValueHolder<>(value); for (final CompletionHandler<V> handler : handlers) { completeHandler(value, handler); } return this; }
/** * Invokes the given supplier and returns the cached result for every other call. * * @return the cached computation result of the given supplier. */ @Override public T get() { if (value == null) { value = new ValueHolder<>(supplier.get()); } return value.get(); } }
final ValueHolder<Config> result = new ValueHolder<>(ConfigFactory.empty());