Class LazyLong


  • @ParametersAreNonnullByDefault
    public final class LazyLong
    extends Object
    An object that automatically loads a long by using a LongSupplier during the first call to getAsLong().
    • Method Detail

      • of

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

        @Nonnull
        public static LazyLong with​(LongSupplier loadFunction)
        Creates a new lazy long with the LongSupplier to load the embed value.
        Parameters:
        loadFunction - the function used to load the value
        Returns:
        a new lazy object
      • getAsLong

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

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

        public void update​(LongUnaryOperator updateOperator)
        Updates the wrapped value with a LongUnaryOperator.
        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​(LongConsumer 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.