Class CachedValue<T>

java.lang.Object
me.hsgamer.hscore.common.CachedValue<T>
Type Parameters:
T - the type of the value
All Implemented Interfaces:
Supplier<T>

public abstract class CachedValue<T> extends Object implements Supplier<T>
The base class for caching value
  • Constructor Details

    • CachedValue

      public CachedValue()
  • Method Details

    • of

      public static <T> CachedValue<T> of(Supplier<T> supplier)
      Create a new cached value from a supplier
      Type Parameters:
      T - the type of the value
      Parameters:
      supplier - the supplier
      Returns:
      the cached value
    • getValue

      public T getValue()
      Get the cached value or generate one if the cache is null
      Returns:
      the value
    • clearCache

      public void clearCache()
      Clear the cached value
    • generate

      public abstract T generate()
      Generate the value
      Returns:
      the value
    • get

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