Class CompositeStorageImpl
java.lang.Object
com.refinedmods.refinedstorage.api.storage.composite.CompositeStorageImpl
- All Implemented Interfaces:
CompositeAwareChild
,CompositeStorage
,ParentComposite
,ExtractableStorage
,InsertableStorage
,Storage
,StorageView
,TrackedStorage
@API(status=STABLE,
since="2.0.0-milestone.1.0")
public class CompositeStorageImpl
extends Object
implements CompositeStorage, CompositeAwareChild, ParentComposite
An implementation of
CompositeStorage
that can be contained into other CompositeStorage
s.-
Nested Class Summary
Nested classes/interfaces inherited from interface com.refinedmods.refinedstorage.api.storage.composite.CompositeAwareChild
CompositeAwareChild.Amount
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a source and resorts them.void
addToCache
(ResourceKey resource, long amount) Adds a resource to the composite storage cache.void
Clears all sources.compositeExtract
(ResourceKey resource, long amount, Action action, Actor actor) Extracts a resource from a storage.compositeInsert
(ResourceKey resource, long amount, Action action, Actor actor) Inserts a resource into a storage.boolean
long
extract
(ResourceKey resource, long amount, Action action, Actor actor) Extracts a resource from a storage.findTrackedResourceByActorType
(ResourceKey resource, Class<? extends Actor> actorType) Finds the tracked resource by actor type.getAll()
long
long
insert
(ResourceKey resource, long amount, Action action, Actor actor) Inserts a resource into a storage.void
onAddedIntoComposite
(ParentComposite parentComposite) Called by aCompositeStorage
when thisCompositeAwareChild
is added into the composite storage.void
onRemovedFromComposite
(ParentComposite parentComposite) Called by aCompositeStorage
when thisCompositeAwareChild
is removed from the composite storage.void
onSourceAddedToChild
(Storage source) Called by theCompositeAwareChild
to notify to this parent composite storage that a source has been added.void
onSourceRemovedFromChild
(Storage source) Called by theCompositeAwareChild
to notify to this parent composite storage that a source has been removed.void
removeFromCache
(ResourceKey resource, long amount) Removes a resource from the composite storage cache.void
removeSource
(Storage source) Removes a source and resorts them.void
Sorts storages that implementPriorityProvider
.
-
Constructor Details
-
CompositeStorageImpl
- Parameters:
list
- the backing list of this composite storage, used to retrieve a view of the sources
-
-
Method Details
-
sortSources
public void sortSources()Description copied from interface:CompositeStorage
Sorts storages that implementPriorityProvider
.- Specified by:
sortSources
in interfaceCompositeStorage
-
addSource
Description copied from interface:CompositeStorage
Adds a source and resorts them.- Specified by:
addSource
in interfaceCompositeStorage
- Parameters:
source
- the source
-
removeSource
Description copied from interface:CompositeStorage
Removes a source and resorts them.- Specified by:
removeSource
in interfaceCompositeStorage
- Parameters:
source
- the source
-
getSources
- Specified by:
getSources
in interfaceCompositeStorage
- Returns:
- an unmodifiable source list
-
clearSources
public void clearSources()Description copied from interface:CompositeStorage
Clears all sources.- Specified by:
clearSources
in interfaceCompositeStorage
-
contains
- Specified by:
contains
in interfaceCompositeAwareChild
-
extract
Description copied from interface:ExtractableStorage
Extracts a resource from a storage.- Specified by:
extract
in interfaceExtractableStorage
- Parameters:
resource
- the resource, may not be nullamount
- the amount, must be larger than 0action
- the mode of extractionactor
- the source- Returns:
- the amount extracted
-
insert
Description copied from interface:InsertableStorage
Inserts a resource into a storage.- Specified by:
insert
in interfaceInsertableStorage
- Parameters:
resource
- the resource, may not be nullamount
- the amount, must be larger than 0action
- the mode of insertionactor
- the source- Returns:
- the amount inserted
-
getAll
- Specified by:
getAll
in interfaceStorageView
- Returns:
- a list of resource amounts
-
getStored
public long getStored()- Specified by:
getStored
in interfaceStorageView
- Returns:
- the amount stored
-
findTrackedResourceByActorType
public Optional<TrackedResource> findTrackedResourceByActorType(ResourceKey resource, Class<? extends Actor> actorType) Description copied from interface:TrackedStorage
Finds the tracked resource by actor type.- Specified by:
findTrackedResourceByActorType
in interfaceTrackedStorage
- Parameters:
resource
- the resourceactorType
- the actor type- Returns:
- the tracked resource modified by the given actor type, if present
-
onAddedIntoComposite
Description copied from interface:CompositeAwareChild
Called by aCompositeStorage
when thisCompositeAwareChild
is added into the composite storage.- Specified by:
onAddedIntoComposite
in interfaceCompositeAwareChild
- Parameters:
parentComposite
- the composite storage that thisCompositeAwareChild
is contained in
-
onRemovedFromComposite
Description copied from interface:CompositeAwareChild
Called by aCompositeStorage
when thisCompositeAwareChild
is removed from the composite storage.- Specified by:
onRemovedFromComposite
in interfaceCompositeAwareChild
- Parameters:
parentComposite
- the composite storage that thisCompositeAwareChild
is/was contained in
-
compositeInsert
public CompositeAwareChild.Amount compositeInsert(ResourceKey resource, long amount, Action action, Actor actor) Description copied from interface:CompositeAwareChild
Inserts a resource into a storage.- Specified by:
compositeInsert
in interfaceCompositeAwareChild
- Parameters:
resource
- the resource, may not be nullamount
- the amount, must be larger than 0action
- the mode of insertionactor
- the source- Returns:
- the amount inserted
-
compositeExtract
public CompositeAwareChild.Amount compositeExtract(ResourceKey resource, long amount, Action action, Actor actor) Description copied from interface:CompositeAwareChild
Extracts a resource from a storage.- Specified by:
compositeExtract
in interfaceCompositeAwareChild
- Parameters:
resource
- the resource, may not be nullamount
- the amount, must be larger than 0action
- the mode of extractionactor
- the source- Returns:
- the amount extracted
-
onSourceAddedToChild
Description copied from interface:ParentComposite
Called by theCompositeAwareChild
to notify to this parent composite storage that a source has been added.- Specified by:
onSourceAddedToChild
in interfaceParentComposite
- Parameters:
source
- the source
-
onSourceRemovedFromChild
Description copied from interface:ParentComposite
Called by theCompositeAwareChild
to notify to this parent composite storage that a source has been removed.- Specified by:
onSourceRemovedFromChild
in interfaceParentComposite
- Parameters:
source
- the source
-
addToCache
Description copied from interface:ParentComposite
Adds a resource to the composite storage cache.- Specified by:
addToCache
in interfaceParentComposite
- Parameters:
resource
- the resourceamount
- the amount
-
removeFromCache
Description copied from interface:ParentComposite
Removes a resource from the composite storage cache.- Specified by:
removeFromCache
in interfaceParentComposite
- Parameters:
resource
- the resourceamount
- the amount
-