Interface IIngredientMapMutable<T,M,V>

Type Parameters:
T - The instance type.
M - The matching condition parameter.
V - The type of mapped values.
All Superinterfaces:
IIngredientCollectionLike<T,M,Map.Entry<T,V>>, IIngredientMap<T,M,V>, Iterable<Map.Entry<T,V>>
All Known Implementing Classes:
IngredientHashMap, IngredientMapAdapter, IngredientMapMultiClassified, IngredientMapSingleClassified, IngredientMapWrappedAdapter, IngredientTreeMap

public interface IIngredientMapMutable<T,M,V> extends IIngredientMap<T,M,V>
A mutable mapping from ingredient component instances to values of any type. This does not conform to the Map interface as instances are compared using the matcher in IngredientComponent.getMatcher().
  • Method Details

    • clear

      void clear()
      Clears this map of all instances.
    • put

      @Nullable V put(T key, V value)
      Add a new entry.
      Parameters:
      key - An instance key.
      value - A value.
      Returns:
      The previous value that was associated with the given instance.
    • remove

      @Nullable V remove(T key)
      Remove the mapping for the given key instance.
      Parameters:
      key - An instance key.
      Returns:
      The value that was associated with the given instance.
    • removeAll

      int removeAll(T instance, M matchCondition)
      Remove all occurrences of the given key instance under the given match conditions. This instance will be compared based on the matcher from the ingredient component type using the given match condition.
      Parameters:
      instance - An instance.
      matchCondition - A match condition.
      Returns:
      The number of removed instances.
    • removeAll

      default int removeAll(Iterable<? extends T> instances)
      Remove all the given key instances from the collection.
      Parameters:
      instances - Instances.
      Returns:
      The number of removed instances.
    • removeAll

      default int removeAll(Iterable<? extends T> instances, M matchCondition)
      Remove all occurrences of the given instances under the given match conditions. The instances will be compared based on the matcher from the ingredient component type using the given match condition.
      Parameters:
      instances - Instances.
      matchCondition - A match condition.
      Returns:
      The number of removed instances.
    • compute

      @Nullable default V compute(T key, BiFunction<T,V,V> remappingFunction)
      Compute a new value for the given key instance, following Map.compute(K, java.util.function.BiFunction<? super K, ? super V, ? extends V>) semantics. The remapping function is passed the key and the currently mapped value, or null when the key is absent. Returning null removes the mapping, returning anything else stores it. Implementations back onto a hash of the key instance, which for some component types is expensive. Doing this in one call rather than a get followed by a put lets them hash once.
      Parameters:
      key - An instance key.
      remappingFunction - A function computing the new value from the key and the old value.
      Returns:
      The new value associated with the key, or null if none.
    • putAll

      default int putAll(IIngredientMap<? extends T,M,? extends V> map)
      Add all entries from the given map to this map.
      Parameters:
      map - A map, that will not be changed, only read.
      Returns:
      The amount of entries from the given map that were added to this map.