ResourceBuilder
final class ResourceBuilder
Package: dev.joid.lib.resource · Module: core · Source: ResourceBuilder.java
Creates resources with shared default settings and a cache that makes two loads of the same input share their data.
Description
Section titled “Description”Resource.of uses a default builder with linear filtering and a shared MemoryResourceCache.
Make your own when a group of resources needs other defaults or another cache (Give a set of images the same settings).
Every setting returns a new builder and leaves this one unchanged.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
ResourceBuilder | create() factory | Creates a builder with the shared memory cache and linear filtering. |
Methods
Section titled “Methods”Queries
Section titled “Queries”| Returns | Signature | Summary |
|---|---|---|
ResourceProperties | getProperties() | Returns a copy of the default settings that each handle starts with. |
List<ResourceBuilder> | getBuilders() static | Returns every builder still in use, as a new list. |
IResourceCache | getCache() | Returns the cache of the builder, or null when it caches nothing. |
Actions
Section titled “Actions”| Returns | Signature | Summary |
|---|---|---|
ResourceBuilder | cache(IResourceCache cache) | Returns a builder that caches in cache; null caches nothing, so each of decodes the input again. |
ResourceBuilder | interpolation(TextureFilter interpolation) | Returns a builder whose resources are filtered with interpolation. |
ResourceBuilder | linear() | Returns a builder whose resources are filtered smoothly. |
ResourceBuilder | nearest() | Returns a builder whose resources keep their pixels sharp. |
ResourceBuilder | mipmap(boolean mipmap) | Returns a builder whose resources always (true) or never (false) get mipmaps. |
ResourceBuilder | textureCoords(double u, double v, double width, double height) | Returns a builder whose resources draw the region at u, v of width × height pixels. |
Resource | of(Object input) | Returns a handle on the resource of input: a texture of the application or another input that a resolver knows, otherwise an Asset, whose format is detected from its first bytes. |
Resource | compute(String uniqueId, Supplier | Returns a handle on the data cached under uniqueId, creating it with dataSupplier when the cache does not have it. |
Resource | compute(String uniqueId, Supplier | Returns a handle on the data cached under uniqueId, creating it with dataSupplier when the cache does not have it, and calls onCreate with the handle when the data was created rather than found in the cache. |
this | remove(ResourceData data) fluent | Removes data from the cache, under the id it was cached with, when the cache still holds it. |
this | reload() fluent | Removes from the cache every data that this builder put there and that is still cached, so the next of reads the files again. |
Creation details
Section titled “Creation details”create
Section titled “create”ResourceBuilder create() factory
Creates a builder with the shared memory cache and linear filtering.
Method details
Section titled “Method details”getProperties
Section titled “getProperties”ResourceProperties getProperties()
Returns a copy of the default settings that each handle starts with.
getBuilders
Section titled “getBuilders”List<ResourceBuilder> getBuilders() static
Returns every builder still in use, as a new list.
getCache
Section titled “getCache”IResourceCache getCache()
Returns the cache of the builder, or null when it caches nothing.
ResourceBuilder cache(IResourceCache cache)
Returns a builder that caches in cache; null caches nothing, so each of decodes the input again.
interpolation
Section titled “interpolation”ResourceBuilder interpolation(TextureFilter interpolation)
Returns a builder whose resources are filtered with interpolation.
linear
Section titled “linear”ResourceBuilder linear()
Returns a builder whose resources are filtered smoothly.
nearest
Section titled “nearest”ResourceBuilder nearest()
Returns a builder whose resources keep their pixels sharp.
mipmap
Section titled “mipmap”ResourceBuilder mipmap(boolean mipmap)
Returns a builder whose resources always (true) or never (false) get mipmaps.
textureCoords
Section titled “textureCoords”ResourceBuilder textureCoords(double u, double v, double width, double height)
Returns a builder whose resources draw the region at u, v of width × height pixels.
Resource of(Object input)
Returns a handle on the resource of input: a texture of the application or another input that a resolver knows, otherwise an Asset, whose format is detected from its first bytes.
A path found nowhere gives a failed resource; an input of a type that nothing knows throws IllegalArgumentException.
compute
Section titled “compute”Resource compute(String uniqueId, Supplier<ResourceData> dataSupplier)
Returns a handle on the data cached under uniqueId, creating it with dataSupplier when the cache does not have it.
Use it in a resolver or for data you build yourself.
Resource compute(String uniqueId, Supplier<ResourceData> dataSupplier, Consumer<Resource> onCreate)
Returns a handle on the data cached under uniqueId, creating it with dataSupplier when the cache does not have it, and calls onCreate with the handle when the data was created rather than found in the cache.
remove
Section titled “remove”this remove(ResourceData data) fluent
Removes data from the cache, under the id it was cached with, when the cache still holds it.
reload
Section titled “reload”this reload() fluent
Removes from the cache every data that this builder put there and that is still cached, so the next of reads the files again.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
