Class IngredientPositionsIndex<T,M>
java.lang.Object
org.cyclops.integrateddynamics.core.network.IngredientPositionsIndex<T,M>
- Type Parameters:
T- An instance type.M- The matching condition parameter.
- All Implemented Interfaces:
Iterable<T>, org.cyclops.cyclopscore.ingredient.collection.IIngredientCollection<T,M>, org.cyclops.cyclopscore.ingredient.collection.IIngredientCollectionLike<T, M, T>, IIngredientPositionsIndex<T, M>
An index that maps ingredients to positions that contain that instance.
Positions are stored together with their priorities.
This makes it possible for instances of this class to guarantee that all returned iterators maintain priority order.
-
Constructor Summary
ConstructorsConstructorDescriptionIngredientPositionsIndex(org.cyclops.commoncapabilities.api.ingredient.IngredientComponent<T, M> component) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAll(PrioritizedPartPos pos, Iterable<? extends T> instances) voidaddPosition(T instance, PrioritizedPartPos pos) Indicate that the given position contains the given position.booleanbooleanintprotected org.cyclops.cyclopscore.ingredient.collection.IIngredientMapMutable<T, M, it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<PartPos>> Create a map for storing the positions of one priority level.Filter out duplicate positions, as the same position can hold multiple instances.protected intgetPositions(T instance, M matchFlags) Get all positions that have an instance that contain the given instance.protected TgetPrototype(T instance) longgetQuantity(T instance) Get the available quantity for the given instance.iteratePrioritized(Function<org.cyclops.cyclopscore.ingredient.collection.IIngredientMapMutable<T, M, it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<PartPos>>, Iterator<PartPos>> positionsGetter) Lazily iterate over the positions of all priority levels, in priority order, without duplicates.iterator()voidremoveAll(PrioritizedPartPos pos, Iterable<? extends T> instances) voidremovePosition(T instance, PrioritizedPartPos pos) Indicate that the given instance is removed from the given position.intsize()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.cyclops.cyclopscore.ingredient.collection.IIngredientCollection
containsAll, containsAll, parallelStream, spliterator, stream, toArrayMethods inherited from interface org.cyclops.cyclopscore.ingredient.collection.IIngredientCollectionLike
equals, hashCode, isEmpty, toString
-
Constructor Details
-
IngredientPositionsIndex
-
-
Method Details
-
getPrototype
-
getInternalPriority
-
getNonEmptyPositions
- Specified by:
getNonEmptyPositionsin interfaceIIngredientPositionsIndex<T,M> - Returns:
- Get all positions that are not empty.
-
getPositions
Description copied from interface:IIngredientPositionsIndexGet all positions that have an instance that contain the given instance.- Specified by:
getPositionsin interfaceIIngredientPositionsIndex<T,M> - Parameters:
instance- An instance to match.matchFlags- Instance match conditions.- Returns:
- The positions.
-
iteratePrioritized
protected Iterator<PartPos> iteratePrioritized(Function<org.cyclops.cyclopscore.ingredient.collection.IIngredientMapMutable<T, M, it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<PartPos>>, Iterator<PartPos>> positionsGetter) Lazily iterate over the positions of all priority levels, in priority order, without duplicates. Iteration is lazy because callers commonly stop iterating as soon as they have found a usable position.- Parameters:
positionsGetter- A callback for iterating over the matching positions within one priority level.- Returns:
- An iterator over all matching positions.
-
distinct
-
addPosition
Description copied from interface:IIngredientPositionsIndexIndicate that the given position contains the given position.- Specified by:
addPositionin interfaceIIngredientPositionsIndex<T,M> - Parameters:
instance- An instance.pos- A position.
-
createPositionsMap
protected org.cyclops.cyclopscore.ingredient.collection.IIngredientMapMutable<T, M, it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<PartPos>> createPositionsMap()Create a map for storing the positions of one priority level. Instances are classified by their first category type when the component has more than one, so that lookups by that category don't have to scan over all indexed instances.- Returns:
- A new positions map.
-
removePosition
Description copied from interface:IIngredientPositionsIndexIndicate that the given instance is removed from the given position. This will not necessarily remove the given position, only if the total instance quantity becomes zero.- Specified by:
removePositionin interfaceIIngredientPositionsIndex<T,M> - Parameters:
instance- An instance.pos- A position.
-
getQuantity
Description copied from interface:IIngredientPositionsIndexGet the available quantity for the given instance.- Specified by:
getQuantityin interfaceIIngredientPositionsIndex<T,M> - Parameters:
instance- An instance to match.- Returns:
- The indexed quantity.
-
getComponent
-
size
-
contains
-
contains
-
count
-
iterator
-
iterator
-
removeAll
-
addAll
-