Class ResourcesContainer<T>
- Type Parameters:
T- Der Datentyp der Ressource, die in dieser Instanz enthalten ist.
- Direct Known Subclasses:
ImagesContainer,SoundsContainer
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd the specified resource to this container.
The added element can later be retrieved from this container by callingget(resourceName).voidAdd a new container listener to this instance that observes whenever this instance is cleared.addContainerListener(ResourcesContainerListener<T> listener) Add a new container listener to this instance in order to observe resource life cycles.voidaddManipulator(ResourceManipulator<T> manipulator) Fügt einen Resourcenmanipulator zu diesem Resourcenspeicher hinzu.voidclear()Clears the resource container by removing all previously loaded resources.booleanChecks if this instance contains a resource with the specified name.booleanbooleanChecks if the specified resource is contained by this instance.intcount()Gets the amount of resources that this container holds.Gets the resource with the specified name.Gets the resource with the specified name.Gets the resource with the specified name.Gets all resources that match the specified condition.protected StringGets an alias for the specified resourceName.getAll()Gets all loaded resources from this container.Eventually gets the resource with the specified location.Eventually gets the resource with the specified location.protected abstract TRemoves the resource with the specified name from this container.voidRemove the specified listener from this container.voidremoveContainerListener(ResourcesContainerListener<T> listener) Remove the specified listener from this container.voidEntfernt den Resourcenmanipulator aus diesem Resourcenspeicher.Tries to get a resource with the specified name from this container.
-
Constructor Details
-
ResourcesContainer
public ResourcesContainer()
-
-
Method Details
-
addContainerListener
Add a new container listener to this instance in order to observe resource life cycles. The listener will get notified whenever a resource was added to or removed from this container.- Parameters:
listener- The container listener instance that will receive call backs from this container.- See Also:
-
removeContainerListener
Remove the specified listener from this container.- Parameters:
listener- The listener instance that was previously added to this container.- See Also:
-
addClearedListener
Add a new container listener to this instance that observes whenever this instance is cleared.- Parameters:
listener- The container listener instance.- See Also:
-
removeClearedListener
Remove the specified listener from this container.- Parameters:
listener- The listener instance that was previously added to this container.- See Also:
-
addManipulator
Fügt einen Resourcenmanipulator zu diesem Resourcenspeicher hinzu. -
removeManipulator
public void removeManipulator()Entfernt den Resourcenmanipulator aus diesem Resourcenspeicher. -
add
Add the specified resource to this container.
The added element can later be retrieved from this container by callingget(resourceName).Use this method to make a resource accessible over this container during runtime.
- Parameters:
resourceName- The name that the resource is managed by.resource- The resource instance.- See Also:
-
add
-
clear
public void clear()Clears the resource container by removing all previously loaded resources. -
contains
Checks if this instance contains a resource with the specified name.Note that the name is not case-sensitive.
- Parameters:
resourceName- The resource's name.- Returns:
- True if this container contains a resource with the specified name; otherwise false.
- See Also:
-
contains
-
contains
Checks if the specified resource is contained by this instance.- Parameters:
resource- The resource.- Returns:
- True if this instance contains the specified resource instance; otherwise false.
-
count
public int count()Gets the amount of resources that this container holds.- Returns:
- The amount of resources in this container.
-
get
Gets all resources that match the specified condition.- Parameters:
pred- The condition that a resource must fulfill in order to be returned.- Returns:
- All resources that match the specified condition.
-
get
Gets the resource with the specified name.
This is the most common (and preferred) way to fetch resources from a container.
If not previously loaded, this method attempts to load the resource on the fly otherwise it will be retrieved from the cache.
- Parameters:
resourceName- The resource's name.- Returns:
- The resource with the specified name or null if not found.
-
get
-
get
Gets the resource with the specified name.
If no such resource is currently present on the container, it will be loaded with the specified
loadCallbackand added to this container.- Parameters:
resourceName- The resource's name.loadCallback- The callback that is used to load the resource on-demand if it's not present on this container.- Returns:
- T The resource with the specified name.
-
get
-
get
Gets the resource with the specified name.If not previously loaded, this method attempts to load the resource on the fly otherwise it will be retrieved from the cache.
- Parameters:
resourceName- The name of the game resource.forceLoad- If set to true, cached resource (if existing) will be discarded and the resource will be freshly loaded.- Returns:
- The game resource or null if not found.
-
get
-
getAsync
Eventually gets the resource with the specified location. The resource is loaded asynchronously and can be retrieved from the returnedFutureobject returned by this method once loaded.- Parameters:
location- The location of the resource- Returns:
- A
Futureobject that can be used to retrieve the resource once it is finished loading
-
getAsync
Eventually gets the resource with the specified location. The resource is loaded asynchronously and can be retrieved from the returnedFutureobject returned by this method once loaded.- Parameters:
name- The name or location of the resource- Returns:
- A
Futureobject that can be used to retrieve the resource once it is finished loading
-
getAll
Gets all loaded resources from this container.- Returns:
- All loaded resources.
-
remove
Removes the resource with the specified name from this container.- Parameters:
resourceName- The name of the resource that should be removed.- Returns:
- The removed resource.
-
remove
-
tryGet
Tries to get a resource with the specified name from this container.This method should be used, if it's not clear whether the resource is present on this container.
It is basically a combination ofget(String)andcontains(String)and allows to check whether a resource is present while also fetching it from the container.- Parameters:
resourceName- The name of the resource.- Returns:
- An Optional instance that holds the resource instance, if present on this container.
- See Also:
-
tryGet
-
load
- Throws:
Exception
-
getAlias
Gets an alias for the specified resourceName. Note that the process of providing an alias is up to the ResourceContainer implementation.- Parameters:
resourceName- The original name of the resource.resource- The resource.- Returns:
- An alias for the specified resource.
-
getResources
-