Class IngredientCollectionPrototypeMap<T,M>

java.lang.Object
org.cyclops.cyclopscore.ingredient.collection.IngredientCollectionAdapter<T,M>
org.cyclops.cyclopscore.ingredient.collection.IngredientCollectionPrototypeMap<T,M>
Type Parameters:
T - The instance type.
M - The matching condition parameter.
All Implemented Interfaces:
Iterable<T>, IIngredientCollapsedCollection<T,M>, IIngredientCollapsedCollectionMutable<T,M>, IIngredientCollection<T,M>, IIngredientCollectionLike<T,M,T>, IIngredientCollectionMutable<T,M>

public class IngredientCollectionPrototypeMap<T,M> extends IngredientCollectionAdapter<T,M> implements IIngredientCollapsedCollectionMutable<T,M>
An ingredient collection that stores the collection as an IIngredientMap where instances are stored as keys and their amounts as values. By default, a IngredientHashMap will be used as internal map. Note: This uses slightly different semantics compared to the IIngredientCollection interface. For instance, multiple instances that are equal (ignoring quantity) are combined by this collection. Optionally, negative quantities can be allowed, which means that even if an instance is not present, it can still be removed, but it will result in a negative quantity.
  • Constructor Details

  • Method Details

    • add

      public boolean add(T instance)
      Description copied from interface: IIngredientCollectionMutable
      Add the given instance to the collection.
      Specified by:
      add in interface IIngredientCollectionMutable<T,M>
      Parameters:
      instance - An instance.
      Returns:
      If the collection was changed due to this addition. This can be false in the case of sets in which each instance can only exists once.
    • remove

      public boolean remove(T instance)
      Description copied from interface: IIngredientCollectionMutable
      Remove the given instance from the collection.
      Specified by:
      remove in interface IIngredientCollectionMutable<T,M>
      Overrides:
      remove in class IngredientCollectionAdapter<T,M>
      Parameters:
      instance - An instance.
      Returns:
      If the collection was changed due to this addition. Can be false if the collection did not contain the instance.
    • contains

      public boolean contains(T instance)
      Description copied from interface: IIngredientCollection
      Check if this collection contains the given instance. This instance will be compared based on the matcher from the ingredient component type.
      Specified by:
      contains in interface IIngredientCollection<T,M>
      Overrides:
      contains in class IngredientCollectionAdapter<T,M>
      Parameters:
      instance - An instance.
      Returns:
      If this collection contains the given instance.
    • contains

      public boolean contains(T instance, M matchCondition)
      Description copied from interface: IIngredientCollection
      Check if this collection contains the given 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.
      Specified by:
      contains in interface IIngredientCollection<T,M>
      Overrides:
      contains in class IngredientCollectionAdapter<T,M>
      Parameters:
      instance - An instance.
      matchCondition - A match condition.
      Returns:
      If this collection contains the given instance under the given match conditions.
    • clear

      public void clear()
      Description copied from interface: IIngredientCollectionMutable
      Clears this collection of all instances.
      Specified by:
      clear in interface IIngredientCollectionMutable<T,M>
    • size

      public int size()
      Specified by:
      size in interface IIngredientCollectionLike<T,M,T>
      Returns:
      The number of instances contained in this collection.
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • iterator

      public Iterator<T> iterator(T instance, M matchCondition)
      Description copied from interface: IIngredientCollection
      An iterator over this collection over all occurrences of the given instance under the given match conditions.
      Specified by:
      iterator in interface IIngredientCollection<T,M>
      Specified by:
      iterator in interface IIngredientCollectionLike<T,M,T>
      Overrides:
      iterator in class IngredientCollectionAdapter<T,M>
      Parameters:
      instance - An instance.
      matchCondition - A match condition.
      Returns:
      An iterator over this collection over all occurrences of the given instance under the given match conditions.
    • prototypeIterator

      public Iterator<Map.Entry<T,Long>> prototypeIterator()
      Returns:
      An iterator over all available counted prototypes. This will contain all non-zero quantity instances, but with a quantity of 1.
    • prototypeIterator

      public Iterator<Map.Entry<T,Long>> prototypeIterator(T instance, M matchCondition)
      Parameters:
      instance - An instance.
      matchCondition - A match condition.
      Returns:
      An iterator over all available counted prototypes under the given match conditions. This will contain all non-zero quantity instances, but with a quantity of 1.
    • getPrototype

      protected T getPrototype(T instance)
    • setQuantity

      public void setQuantity(T instance, long quantity)
      Description copied from interface: IIngredientCollapsedCollectionMutable
      Set the quantity of the given instance.
      Specified by:
      setQuantity in interface IIngredientCollapsedCollectionMutable<T,M>
      Parameters:
      instance - An instance, its quantity will be ignored.
      quantity - The new quantity to set.
    • getQuantity

      public long getQuantity(T instance)
      Description copied from interface: IIngredientCollapsedCollectionMutable
      Get the quantity of the given instance.
      Specified by:
      getQuantity in interface IIngredientCollapsedCollectionMutable<T,M>
      Parameters:
      instance - An instance, its quantity will be ignored.
      Returns:
      The quantity.
    • isNegativeQuantities

      public boolean isNegativeQuantities()
      Returns:
      If negative quantities are allowed in this collection.