Class LazyInt


  • @ParametersAreNonnullByDefault
    public final class LazyInt
    extends Object
    An object that automatically loads an integer by using a IntSupplier during the first call to getAsInt().
    • Method Detail

      • of

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

        @Nonnull
        public static LazyInt with​(IntSupplier loadFunction)
        Creates a new lazy integer with the IntSupplier to load the embed value.
        Parameters:
        loadFunction - the function used to load the value
        Returns:
        a new lazy object
      • getAsInt

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

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

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