class ObjectMatcher extends java.lang.Object
An Object Matcher is a utility for determining whether or not an Object of a specified type matches a set of criteria configured via
DSL.
A matcher could implement actual equivalence, or it could ensure that an object is within a specified set of tolerance levels.
An object matcher is defined using a simple DSL:
All properties and property types defined in the configuration will be used as the basis of match comparison, all others will
be ignored.
ObjectMatcher matcher = ObjectMatcher.matcher(Person){* typeMatcher String, { v-> v != null }* propertyMatchers([
age: { v -> v > 18 && v < 40 },
employed: { v-> v }* ])
}*
boolean matches = matcher.matches(somePerson)
float score = matcher.score(somePerson)
Type Params | Return Type | Name and description |
---|---|---|
|
static ObjectMatcher |
matcher(java.lang.Class target, groovy.lang.Closure closure) Configures an ObjectMapper for the specified target type using the DSL. |
|
boolean |
matches(java.util.Map<java.lang.String, java.lang.Object> overrides = [:], java.lang.Object obj) Used to determine whether or not the specified object matches the configured criteria. |
|
ObjectMatcher |
propertyMatcher(java.lang.String name, java.lang.Object matcher) |
|
ObjectMatcher |
propertyMatchers(java.util.Map<java.lang.String, java.lang.Object> matchers) |
|
float |
score(java.util.Map<java.lang.String, java.lang.Object> overrides = [:], java.lang.Object obj) Used to calculate the match percentage for the specified object. |
|
ObjectMatcher |
typeMatcher(java.lang.Class type, java.lang.Object matcher) |
|
ObjectMatcher |
typeMatchers(java.util.Map<java.lang.Class, java.lang.Object> matchers, boolean clean = false) |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Configures an ObjectMapper for the specified target type using the DSL.
target
- the target typeclosure
- the DSL configuration closureUsed to determine whether or not the specified object matches the configured criteria. Configured match criteria may be overridden at runtime for this call by specifying the property name and criteria in the overrides map.
overrides
- an optional Map of property names to criteria closures which will override existing config with the same property nameobj
- the object being testedUsed to calculate the match percentage for the specified object. This percentage is based on the number of test criteria and the number of test criteria which are true.
overrides
- an optional Map of property names to criteria closures which will override existing config with the same property nameobj
- the object being tested