@NonNullByDefault public interface ValueCache
The ValueCache can be used by scripts to share information between subsequent runs of the same script or between scripts (depending on implementation).
Author:
Jan N. Klug - Initial contribution
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable Object
    compute(String key, BiFunction<String,@Nullable Object,@Nullable Object> remappingFunction)
    Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).
    @Nullable Object
    get(String key)
    Get a value from the cache
    get(String key, Supplier<Object> supplier)
    Get a value from the cache or create a new key-value-pair from the given supplier
    @Nullable Object
    put(String key, Object value)
    Add a new key-value-pair to the cache.
    @Nullable Object
    Remove a key (and its associated value) from the cache
  • Method Details

    • put

      @Nullable Object put(String key, Object value)
      Add a new key-value-pair to the cache. If the key is already present, the old value is replaces by the new value.
      Parameters:
      key - a string used as key
      value - an Object to store with the key
      Returns:
      the old value associated with this key or null if key didn't exist
    • remove

      @Nullable Object remove(String key)
      Remove a key (and its associated value) from the cache
      Parameters:
      key - the key to remove
      Returns:
      the previously associated value to this key or null if key not present
    • get

      @Nullable Object get(String key)
      Get a value from the cache
      Parameters:
      key - the key of the requested value
      Returns:
      the value associated with the key or null if key not present
    • get

      Object get(String key, Supplier<Object> supplier)
      Get a value from the cache or create a new key-value-pair from the given supplier
      Parameters:
      key - the key of the requested value
      supplier - a supplier that returns a non-null value to be used if the key was not present
      Returns:
      the value associated with the key
    • compute

      @Nullable Object compute(String key, BiFunction<String,@Nullable Object,@Nullable Object> remappingFunction)
      Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping). See java.util.Map.compute() for details.
      Parameters:
      key - the key of the requested value.
      remappingFunction - the remapping function to compute a value.
      Returns:
      the new value associated with the specified key, or null if none