Class LazyEvaluatedObject<T>

  • Type Parameters:
    T - the (arbitrary) type of data to hold
    All Implemented Interfaces:
    Supplier<T>

    public class LazyEvaluatedObject<T>
    extends Object
    implements Supplier<T>
    A lazily evaluated object.

    Useful as a wrapper to hold values which are potentially expensive to calculate, but might sometimes not be requested.

    • Constructor Detail

      • LazyEvaluatedObject

        public LazyEvaluatedObject​(Supplier<T> evaluator)
        Constructs a LazyEvaluatedObject using a evaluator (supplier function) which returns a value of generic type T, when requested from this object.
        Parameters:
        evaluator - a Supplier function which returns the value of interest when executed
      • LazyEvaluatedObject

        public LazyEvaluatedObject​(T value)
        Constructs a LazyEvaluatedObject using an already known value of generic type T.

        This simply wraps the value with a supplier method, but can be useful in situations where sometimes an expensive to calculate value is already know, but one wants to use the lazy evaluated interface for the remaining cases.

        Parameters:
        value - the value to store
    • Method Detail

      • get

        public T get()
        Specified by:
        get in interface Supplier<T>
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • wasEvaluated

        public boolean wasEvaluated()