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.-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
-
Constructor Summary
ConstructorDescriptionIngredientCollectionPrototypeMap
(IngredientComponent<T, M> component) IngredientCollectionPrototypeMap
(IngredientComponent<T, M> component, boolean negativeQuantities) IngredientCollectionPrototypeMap
(IngredientComponent<T, M> component, boolean negativeQuantities, IIngredientMapMutable<T, M, Long> map) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add the given instance to the collection.void
clear()
Clears this collection of all instances.boolean
Check if this collection contains the given instance.boolean
Check if this collection contains the given instance under the given match conditions.protected T
getPrototype
(T instance) long
getQuantity
(T instance) Get the quantity of the given instance.boolean
iterator()
An iterator over this collection over all occurrences of the given instance under the given match conditions.prototypeIterator
(T instance, M matchCondition) boolean
Remove the given instance from the collection.void
setQuantity
(T instance, long quantity) Set the quantity of the given instance.int
size()
Methods inherited from class org.cyclops.cyclopscore.ingredient.collection.IngredientCollectionAdapter
count, getComponent, hashCode, removeAll, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.cyclops.cyclopscore.ingredient.collection.IIngredientCollection
containsAll, containsAll, count, parallelStream, spliterator, stream, toArray
Methods inherited from interface org.cyclops.cyclopscore.ingredient.collection.IIngredientCollectionLike
equals, getComponent, hashCode, isEmpty, toString
Methods inherited from interface org.cyclops.cyclopscore.ingredient.collection.IIngredientCollectionMutable
addAll, removeAll, removeAll, removeAll
-
Constructor Details
-
IngredientCollectionPrototypeMap
-
IngredientCollectionPrototypeMap
public IngredientCollectionPrototypeMap(IngredientComponent<T, M> component, boolean negativeQuantities) -
IngredientCollectionPrototypeMap
public IngredientCollectionPrototypeMap(IngredientComponent<T, M> component, boolean negativeQuantities, IIngredientMapMutable<T, M, Long> map)
-
-
Method Details
-
add
Description copied from interface:IIngredientCollectionMutable
Add the given instance to the collection.- Specified by:
add
in interfaceIIngredientCollectionMutable<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
Description copied from interface:IIngredientCollectionMutable
Remove the given instance from the collection.- Specified by:
remove
in interfaceIIngredientCollectionMutable<T,
M> - Overrides:
remove
in classIngredientCollectionAdapter<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
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 interfaceIIngredientCollection<T,
M> - Overrides:
contains
in classIngredientCollectionAdapter<T,
M> - Parameters:
instance
- An instance.- Returns:
- If this collection contains the given instance.
-
contains
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 interfaceIIngredientCollection<T,
M> - Overrides:
contains
in classIngredientCollectionAdapter<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 interfaceIIngredientCollectionMutable<T,
M>
-
size
public int size()- Specified by:
size
in interfaceIIngredientCollectionLike<T,
M, T> - Returns:
- The number of instances contained in this collection.
-
iterator
-
iterator
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 interfaceIIngredientCollection<T,
M> - Specified by:
iterator
in interfaceIIngredientCollectionLike<T,
M, T> - Overrides:
iterator
in classIngredientCollectionAdapter<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
- Returns:
- An iterator over all available counted prototypes. This will contain all non-zero quantity instances, but with a quantity of 1.
-
prototypeIterator
- 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
-
setQuantity
Description copied from interface:IIngredientCollapsedCollectionMutable
Set the quantity of the given instance.- Specified by:
setQuantity
in interfaceIIngredientCollapsedCollectionMutable<T,
M> - Parameters:
instance
- An instance, its quantity will be ignored.quantity
- The new quantity to set.
-
getQuantity
Description copied from interface:IIngredientCollapsedCollectionMutable
Get the quantity of the given instance.- Specified by:
getQuantity
in interfaceIIngredientCollapsedCollectionMutable<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.
-