-
Notifications
You must be signed in to change notification settings - Fork 0
Implementing your own predicates
Esta Nagy edited this page Jul 1, 2020
·
3 revisions
Predicates are the ultimate decision-makers. They can test whatever logical expression you configure them to test based on the input you throw at them.
Please check out the following list of simple steps to implement a new predicate:
- Create a class for your predicate implementing the Predicate interface using Object as type parameter
- Create a constructor using only the supported parameter types as parameters
- Annotate your constructor with @NamedPredicate
- Annotate all of your constructor parameters as defined here
- Implement the
test(Object)
method defined by the interface. The implementation should make some type checks as conversion is not always possible despite the best of our intentions. - Register your predicate using FunctionRegistry#registerPredicateClass(Class)
- Make sure to add your predicate to the #/definitions/predicateTypes/definitions node of our JSON Schema
- Add a new definition similarly to the examples already in there
- Register the type predicate to the definition of the anyPredicate definition by
- Adding the name to the enum containing all the names
- Adding a new object to the list similar to this:
{ "if": { "properties": { "name": { "const": "allMatch" } } }, "then": { "$ref": "#/definitions/predicateTypes/definitions/predicateAllMatch" } }
- Let's put it to the test (pun intended)!