Class LazyDouble


  • @ParametersAreNonnullByDefault
    public final class LazyDouble
    extends Object
    An object that automatically loads a double by using a DoubleSupplier during the first call to getAsDouble().
    • Method Detail

      • of

        @Nonnull
        public static LazyDouble of​(double value)
        Creates a new lazy double with the embed value.
        Parameters:
        value - the embed value
        Returns:
        a new lazy object
      • with

        @Nonnull
        public static LazyDouble with​(DoubleSupplier loadFunction)
        Creates a new lazy double with the DoubleSupplier to load the embed value.
        Parameters:
        loadFunction - the function used to load the value
        Returns:
        a new lazy object
      • getAsDouble

        public double getAsDouble()
        Gets the wrapped value. On the first call, the object is created.
        Returns:
        the value
      • update

        public void update​(double newValue)
        Updates the wrapped value.
        Parameters:
        newValue - the new value
      • update

        public void update​(DoubleUnaryOperator updateOperator)
        Updates the wrapped value with a DoubleUnaryOperator.
        Parameters:
        updateOperator - the operator to update the wrapped value
      • isLoaded

        public boolean isLoaded()
        Returns true if the value has been loaded.
        Returns:
        true if the value has been loaded
      • ifLoaded

        public void ifLoaded​(DoubleConsumer consumer)
        If a value is loaded, invoke the specified consumer with the value, otherwise do nothing.
        Parameters:
        consumer - action to be executed if a value is present
      • unload

        public void unload()
        Unloads the wrapped value. If the value is not loaded, then this method does nothing.