Class IngredientCollectionMultiClassified<T,M>
java.lang.Object
org.cyclops.cyclopscore.ingredient.collection.IngredientCollectionAdapter<T,M>
org.cyclops.cyclopscore.ingredient.collection.IngredientCollectionMultiClassified<T,M>
- Type Parameters:
T
- An instance type.M
- The matching condition parameter.
- All Implemented Interfaces:
Iterable<T>
,IIngredientCollection<T,
,M> IIngredientCollectionLike<T,
,M, T> IIngredientCollectionLikeMultiClassifiedTrait<T,
,M, T, IngredientCollectionSingleClassified<T, M, ?, ?>> IIngredientCollectionMutable<T,
M>
public class IngredientCollectionMultiClassified<T,M>
extends IngredientCollectionAdapter<T,M>
implements IIngredientCollectionMutable<T,M>, IIngredientCollectionLikeMultiClassifiedTrait<T,M,T,IngredientCollectionSingleClassified<T,M,?,?>>
An ingredient collection that classifies instances in smaller collections
based on all category type of a component type.
This allows instances to be looked up or removed more efficiently when the used match condition
is compatible with the identifying match condition of category types.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.cyclops.cyclopscore.ingredient.collection.IIngredientCollectionLikeMultiClassifiedTrait
IIngredientCollectionLikeMultiClassifiedTrait.RemoveCallbackIterator<T,
M, I, L extends IIngredientCollectionLike<T, M, I>> -
Constructor Summary
ConstructorDescriptionIngredientCollectionMultiClassified
(IngredientComponent<T, M> component, Supplier<IIngredientCollectionMutable<T, M>> collectionCreator) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add the given instance to the collection.boolean
addAllThreaded
(ExecutorService executorService, Iterable<? extends T> instances) A multi-threaded addAll implementation.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.int
Count the number of occurrences of the given instance under the given match conditions.boolean
Check if this collection equals the given object.iterator()
An iterator over this collection over all occurrences of the given instance under the given match conditions.boolean
Remove the given instance from the collection.int
Remove all occurrences of the given instance under the given match conditions.void
removeInstance
(IngredientCollectionSingleClassified<T, M, ?, ?> collection, T iterableInstance) Remove the given instance from the given collection-like.int
size()
Methods inherited from class org.cyclops.cyclopscore.ingredient.collection.IngredientCollectionAdapter
getComponent, hashCode, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.cyclops.cyclopscore.ingredient.collection.IIngredientCollection
containsAll, containsAll, parallelStream, spliterator, stream, toArray
Methods inherited from interface org.cyclops.cyclopscore.ingredient.collection.IIngredientCollectionLike
getComponent, hashCode, isEmpty, toString
Methods inherited from interface org.cyclops.cyclopscore.ingredient.collection.IIngredientCollectionLikeMultiClassifiedTrait
getBestClassifiedCollection, getFirstMatchingCategory, getFirstSingleClassified
Methods inherited from interface org.cyclops.cyclopscore.ingredient.collection.IIngredientCollectionMutable
addAll, removeAll, removeAll
-
Constructor Details
-
IngredientCollectionMultiClassified
public IngredientCollectionMultiClassified(IngredientComponent<T, M> component, Supplier<IIngredientCollectionMutable<T, M>> collectionCreator)
-
-
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.
-
addAllThreaded
public boolean addAllThreaded(@Nullable ExecutorService executorService, Iterable<? extends T> instances) A multi-threaded addAll implementation. This will create workers for adding the given instances to all classified collections.- Parameters:
executorService
- An optional executor service. If none is provided, a new temporary one will be created for the duration of this method call.instances
- The instances that need to be added.- 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.
-
removeAll
Description copied from interface:IIngredientCollectionMutable
Remove all occurrences of 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:
removeAll
in interfaceIIngredientCollectionMutable<T,
M> - Overrides:
removeAll
in classIngredientCollectionAdapter<T,
M> - Parameters:
instance
- An instance.matchCondition
- A match condition.- Returns:
- The number of removed instances.
-
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.
-
count
Description copied from interface:IIngredientCollection
Count the number of occurrences of 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:
count
in interfaceIIngredientCollection<T,
M> - Overrides:
count
in classIngredientCollectionAdapter<T,
M> - Parameters:
instance
- An instance.matchCondition
- A match condition.- Returns:
- The number of occurrences of 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.
-
equals
Description copied from interface:IIngredientCollectionLike
Check if this collection equals the given object. -
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.
-
removeInstance
public void removeInstance(IngredientCollectionSingleClassified<T, M, ?, ?> collection, T iterableInstance) Description copied from interface:IIngredientCollectionLikeMultiClassifiedTrait
Remove the given instance from the given collection-like. This is used internally for iteration purposes.- Specified by:
removeInstance
in interfaceIIngredientCollectionLikeMultiClassifiedTrait<T,
M, T, IngredientCollectionSingleClassified<T, M, ?, ?>> - Parameters:
collection
- A collection-like.iterableInstance
- An iterator instance.
-
getClassifiedCollections
public Map<IngredientComponentCategoryType<T,M, getClassifiedCollections()?>, IngredientCollectionSingleClassified<T, M, ?, ?>> - Specified by:
getClassifiedCollections
in interfaceIIngredientCollectionLikeMultiClassifiedTrait<T,
M, T, IngredientCollectionSingleClassified<T, M, ?, ?>> - Returns:
- A mapping of all internal classified collections.
-