Class SingleVariantStorage
java.lang.Object
fr.robie.machineengine.api.transfer.SnapshotParticipant<SingleVariantStorage.Snapshot>
fr.robie.machineengine.api.transfer.storage.SingleVariantStorage
- All Implemented Interfaces:
ResourceHandler
public class SingleVariantStorage
extends SnapshotParticipant<SingleVariantStorage.Snapshot>
implements ResourceHandler
One slot holding a single variant: a tank, a battery, an item slot. Different variants of the
same type combine according to the category's
MergePolicy.
Owned by one thread (ยง16); not thread-safe. Subclasses may override SnapshotParticipant.onFinalCommit()
to react to committed changes (dirty marking, wake-ups).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic final record -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSingleVariantStorage(@NotNull SingleVariantStorage.Builder builder) -
Method Summary
Modifier and TypeMethodDescriptionlongamount()static @NotNull SingleVariantStorage.Builderbuilder(long capacity) longcapacity()The most this storage holds; subclasses may change it at runtime (e.g.protected @NotNull SingleVariantStorage.Snapshotlongextract(@NotNull ResourceVariant requested, long maxAmount, @NotNull TransactionContext transaction) longinsert(@NotNull ResourceVariant incoming, long maxAmount, @NotNull TransactionContext transaction) booleanisEmpty()voidload(@Nullable ResourceVariant variant, long amount) Replaces the contents outside of any transaction.static @NotNull SingleVariantStorageof(long capacity) protected voidreadSnapshot(@NotNull SingleVariantStorage.Snapshot snapshot) Restores state captured bySnapshotParticipant.createSnapshot().booleanbooleantoString()@Nullable ResourceVariantvariant()@NotNull StorageViewview()@NotNull List<StorageView> views()Methods inherited from class SnapshotParticipant
onFinalCommit, updateSnapshotsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ResourceHandler
amountOf
-
Constructor Details
-
SingleVariantStorage
-
-
Method Details
-
builder
-
of
-
insert
public long insert(@NotNull @NotNull ResourceVariant incoming, long maxAmount, @NotNull @NotNull TransactionContext transaction) - Specified by:
insertin interfaceResourceHandler- Parameters:
maxAmount- the most to insert; must not be negative- Returns:
- how much was accepted, between 0 and
maxAmount
-
extract
public long extract(@NotNull @NotNull ResourceVariant requested, long maxAmount, @NotNull @NotNull TransactionContext transaction) - Specified by:
extractin interfaceResourceHandler- Parameters:
maxAmount- the most to extract; must not be negative- Returns:
- how much was removed, between 0 and
maxAmount
-
views
- Specified by:
viewsin interfaceResourceHandler- Returns:
- a snapshot of the current contents, one view per slot
-
view
-
supportsInsertion
public boolean supportsInsertion()- Specified by:
supportsInsertionin interfaceResourceHandler
-
supportsExtraction
public boolean supportsExtraction()- Specified by:
supportsExtractionin interfaceResourceHandler
-
variant
-
amount
public long amount() -
capacity
public long capacity()The most this storage holds; subclasses may change it at runtime (e.g. upgrades). -
isEmpty
public boolean isEmpty() -
load
Replaces the contents outside of any transaction. For loading persisted state only. -
createSnapshot
- Specified by:
createSnapshotin classSnapshotParticipant<SingleVariantStorage.Snapshot>- Returns:
- an immutable copy of the current state
-
readSnapshot
Description copied from class:SnapshotParticipantRestores state captured bySnapshotParticipant.createSnapshot().- Specified by:
readSnapshotin classSnapshotParticipant<SingleVariantStorage.Snapshot>
-
toString
-