Class ConfigurableTransformation<T extends JobParameters>
java.lang.Object
io.github.douira.glsl_transformer.transform.LifecycleUserImpl<T>
io.github.douira.glsl_transformer.transform.Transformation<T>
io.github.douira.glsl_transformer.core.ConfigurableTransformation<T>
- All Implemented Interfaces:
Activatable,ActivatableLifecycleUser<T>,LifecycleUser<T>
- Direct Known Subclasses:
SearchTerminals,WrapIdentifier
Extends a transformation with methods for making it easily configurable. The
intended structure for each configurable property of the core transformation
is as follows:
- The property foo as a field that holds a supplier that gives the actual
value of the property
- Public setters foo that accept a supplier, just a value (which is
then packaged into a ValueSupplier) or a new cache policy. If they are
caching setters they're registered in order to be notified of invalidation
events (new job parameters, new transformation job etc).
- An internal getter foo that returns the value generated by the supplier in
field foo and optionally applies something like an activation function.
- A protected getter getFoo method that creates default structures. This
method is to be overwritten by extending subclasses. It uses the internal
getters like bar and baz.
This class automatically keeps track of all caching suppliers in a list so
that it can notify them of cache invalidation events. For this reason, users
of the configuration scheme shouldn't set suppliers without using the methods
provided here.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <V> Supplier<V>addSupplier(Supplier<V> supplier)Adds a supplier to the caching supplier list if necessary.protected <V> Supplier<V>cachingSupplier(CachePolicy cachePolicy, Supplier<V> newSupplier)Creates a new caching supplier with the given cache policy and registers it.protected <V> Supplier<V>Makes sure the cache policy of the returned supplier isCachePolicy.ONCE.protected voidremoveSupplier(Supplier<?> currentSupplier)Removes a supplier from the caching supplier list.protected <V> Supplier<V>swapPolicy(Supplier<V> currentSupplier, CachePolicy newPolicy)Returns a supplier that uses the same internal supplier as the given current supplier but has a different cache policy.protected <V> Supplier<V>swapSupplier(Supplier<V> currentSupplier, Supplier<V> newSupplier)Swaps the current supplier of a configuration property with a new one.protected <V> Supplier<V>swapSupplier(Supplier<V> currentSupplier, V newValue)Swaps suppliers but instead of using a new supplier it creates a value supplier that doesn't have to be registered as a caching supplier.protected voidAn alternative reset method that is also called likeLifecycleUser.resetState()but should be used for core transformation internals.protected <V> Supplier<V>value(V newValue)Creates a new value supplier with the given value.Methods inherited from class io.github.douira.glsl_transformer.transform.Transformation
addDependency, addDependent, addEndDependent, addRootDependency, appendDependent, chainConcurrentDependency, chainConcurrentDependent, chainConcurrentSibling, chainDependency, chainDependent, prependDependency, repeat, repeatParallel, repeatSequential, setupGraphMethods inherited from class io.github.douira.glsl_transformer.transform.LifecycleUserImpl
activation, getPlanner, isActive, isInitialized, setInitialized, setPlannerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.douira.glsl_transformer.transform.LifecycleUser
getJobParameters, getLexer, getParser, getRootNode, init, initOnce, resetState
-
Constructor Details
-
ConfigurableTransformation
public ConfigurableTransformation()
-
-
Method Details
-
swapSupplier
Swaps the current supplier of a configuration property with a new one. This also updates the entry in the caching supplier list.- Type Parameters:
V- The value type- Parameters:
currentSupplier- The current supplier of the configuration propertynewSupplier- The new supplier to use- Returns:
- The new current supplier
-
swapSupplier
Swaps suppliers but instead of using a new supplier it creates a value supplier that doesn't have to be registered as a caching supplier.- Type Parameters:
V- The value type- Parameters:
currentSupplier- The current supplier of the configuration propertynewValue- The value to use in the new value supplier- Returns:
- The new current supplier
-
removeSupplier
Removes a supplier from the caching supplier list.- Parameters:
currentSupplier- The supplier to remove
-
addSupplier
Adds a supplier to the caching supplier list if necessary.- Type Parameters:
V- The value type- Parameters:
supplier- The supplier to possibly add- Returns:
- The given supplier
-
swapPolicy
Returns a supplier that uses the same internal supplier as the given current supplier but has a different cache policy. Edge cases that make this operation trivial are specially handled. This may simply cause an unwrapping of the given caching supplier or returning the same supplier as given if the cache policy is already the same.- Type Parameters:
V- The value type- Parameters:
currentSupplier- The current supplier to use as the basenewPolicy- The new cache policy- Returns:
- A supplier with the same internal supplier but the given cache policy
-
cachingSupplier
Creates a new caching supplier with the given cache policy and registers it.- Type Parameters:
V- The value type- Parameters:
cachePolicy- The cache policy to usenewSupplier- The supplier to use- Returns:
- The new caching supplier
-
value
Creates a new value supplier with the given value.- Type Parameters:
V- The value type- Parameters:
newValue- The value to use- Returns:
- The new value supplier
-
once
Makes sure the cache policy of the returned supplier isCachePolicy.ONCE. This is not the same as a value supplier since in this case the supplier may never be evaluated.- Type Parameters:
V- The value type- Parameters:
supplier- The supplier to use- Returns:
- The same supplier but with the cache policy set to
CachePolicy.ONCE
-
triggerJobInternal
protected void triggerJobInternal()Description copied from class:TransformationAn alternative reset method that is also called likeLifecycleUser.resetState()but should be used for core transformation internals. This is one so that users of core transformations don't have to remember to call the super implementation ofLifecycleUser.resetState()themselves.- Overrides:
triggerJobInternalin classTransformation<T extends JobParameters>
-