Skip to content

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.

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.

ReturnsSignatureSummary
ResourceBuildercreate() factoryCreates a builder with the shared memory cache and linear filtering.

ReturnsSignatureSummary
ResourcePropertiesgetProperties()Returns a copy of the default settings that each handle starts with.
List<ResourceBuilder>getBuilders() staticReturns every builder still in use, as a new list.
IResourceCachegetCache()Returns the cache of the builder, or null when it caches nothing.
ReturnsSignatureSummary
ResourceBuildercache(IResourceCache cache)Returns a builder that caches in cache; null caches nothing, so each of decodes the input again.
ResourceBuilderinterpolation(TextureFilter interpolation)Returns a builder whose resources are filtered with interpolation.
ResourceBuilderlinear()Returns a builder whose resources are filtered smoothly.
ResourceBuildernearest()Returns a builder whose resources keep their pixels sharp.
ResourceBuildermipmap(boolean mipmap)Returns a builder whose resources always (true) or never (false) get mipmaps.
ResourceBuildertextureCoords(double u, double v, double width, double height)Returns a builder whose resources draw the region at u, v of width × height pixels.
Resourceof(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.
Resourcecompute(String uniqueId, Supplier dataSupplier)Returns a handle on the data cached under uniqueId, creating it with dataSupplier when the cache does not have it.
Resourcecompute(String uniqueId, Supplier dataSupplier, Consumer 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.
thisremove(ResourceData data) fluentRemoves data from the cache, under the id it was cached with, when the cache still holds it.
thisreload() fluentRemoves from the cache every data that this builder put there and that is still cached, so the next of reads the files again.

ResourceBuilder create() factory

Creates a builder with the shared memory cache and linear filtering.

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.

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. A path found nowhere gives a failed resource; an input of a type that nothing knows throws IllegalArgumentException.

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.

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.


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

Report a problem with this page