Class ConfigurableTransformation<T extends JobParameters>

All Implemented Interfaces:
Activatable, ActivatableLifecycleUser<T>, LifecycleUser<T>
Direct Known Subclasses:
SearchTerminals, WrapIdentifier

public class ConfigurableTransformation<T extends JobParameters> extends Transformation<T>
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 Details

    • ConfigurableTransformation

      public ConfigurableTransformation()
  • Method Details

    • swapSupplier

      protected <V> Supplier<V> swapSupplier(Supplier<V> currentSupplier, Supplier<V> newSupplier)
      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 property
      newSupplier - The new supplier to use
      Returns:
      The new current supplier
    • swapSupplier

      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.
      Type Parameters:
      V - The value type
      Parameters:
      currentSupplier - The current supplier of the configuration property
      newValue - The value to use in the new value supplier
      Returns:
      The new current supplier
    • removeSupplier

      protected void removeSupplier(Supplier<?> currentSupplier)
      Removes a supplier from the caching supplier list.
      Parameters:
      currentSupplier - The supplier to remove
    • addSupplier

      protected <V> Supplier<V> addSupplier(Supplier<V> supplier)
      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

      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. 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 base
      newPolicy - The new cache policy
      Returns:
      A supplier with the same internal supplier but the given cache policy
    • cachingSupplier

      protected <V> Supplier<V> cachingSupplier(CachePolicy cachePolicy, Supplier<V> newSupplier)
      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 use
      newSupplier - The supplier to use
      Returns:
      The new caching supplier
    • value

      protected <V> Supplier<V> value(V newValue)
      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

      protected <V> Supplier<V> once(Supplier<V> supplier)
      Makes sure the cache policy of the returned supplier is CachePolicy.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: Transformation
      An alternative reset method that is also called like LifecycleUser.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 of LifecycleUser.resetState() themselves.
      Overrides:
      triggerJobInternal in class Transformation<T extends JobParameters>