Class CriterionPredicateRegistry<T>

Type Parameters:
T - the target type which the returned predicates evaluate

public class CriterionPredicateRegistry<T> extends Object
A registry which manages mappings from types of Criterion to types of Predicate which can evaluate that criterion's data against a particular target type.

Each predicate's implementation that is registered MUST implement a single-arg constructor which takes an instance of the Criterion to be evaluated. The predicate instance is instantiated reflectively based on this requirement.

  • Field Details

    • log

      @Nonnull private org.slf4j.Logger log
    • registry

      @Nonnull private Map<Class<? extends Criterion>,Class<? extends Predicate<T>>> registry
      Storage for the registry mappings.
  • Constructor Details

    • CriterionPredicateRegistry

      public CriterionPredicateRegistry()
  • Method Details

    • getPredicate

      @Nullable public Predicate<T> getPredicate(@Nonnull Criterion criterion) throws ResolverException
      Get an instance of Predicate which can evaluate the supplied criterion's requirements against a target of the specified type.
      criterion - the criterion to be evaluated
      an predicate instance representing the specified criterion's requirements
      ResolverException - thrown if there is an error reflectively instantiating a new instance of the predicate type based on class information stored in the registry
    • lookup

      @Nullable protected Class<? extends Predicate<T>> lookup(@Nonnull Class<? extends Criterion> clazz)
      Lookup the predicate class type which is registered for the specified Criterion class.
      clazz - the Criterion class subtype to lookup
      the registered predicate class type
    • register

      public void register(@Nonnull Class<? extends Criterion> criterionClass, @Nonnull Class<? extends Predicate<T>> predicateClass)
      Register a Predicate class for a criterion class.
      criterionClass - class subtype of Criterion
      predicateClass - the predicate class type
    • deregister

      public void deregister(@Nonnull Class<? extends Criterion> criterionClass)
      Deregister a criterion-evaluator mapping.
      criterionClass - class subtype of Criterion
    • clearRegistry

      public void clearRegistry()
      Clear all mappings from the registry.
    • loadMappings

      public void loadMappings(@Nonnull String classpathResource)
      Load criterion -> predicate mappings from a classpath resource.
      classpathResource - the classpath resource path from which to load mapping properites
    • loadMappings

      public void loadMappings(@Nonnull Properties mappings)
      Load a set of criterion -> predicate mappings from the supplied properties set.
      mappings - properties set where the key is the criterion class name, the value is the predicate class name