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 Detail

      • log

        @Nonnull
        private org.slf4j.Logger log
        Logger.
    • Constructor Detail

      • CriterionPredicateRegistry

        public CriterionPredicateRegistry()
        Constructor.
    • Method Detail

      • 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.
        Parameters:
        criterion - the criterion to be evaluated
        Returns:
        an predicate instance representing the specified criterion's requirements
        Throws:
        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.
        Parameters:
        clazz - the Criterion class subtype to lookup
        Returns:
        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.
        Parameters:
        criterionClass - class subtype of Criterion
        predicateClass - the predicate class type
      • deregister

        public void deregister​(@Nonnull
                               Class<? extends Criterion> criterionClass)
        Deregister a criterion-evaluator mapping.
        Parameters:
        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.
        Parameters:
        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.
        Parameters:
        mappings - properties set where the key is the criterion class name, the value is the predicate class name