public class GettersDynamicPerformerBuilder<T> extends AbstractDynamicPerformerBuilder<T,CompositeComparisonPerformer<T>>
Class provides functionality to build CompositeComparisonPerformer by streaming all the getter methods
in the specified class and filtering out the ones you want to include or exclude. All getter properties will
be automatically mapper by property keys. Result performer will contain delegating performers for each getter.
Getters are retrieved by the instance of the ClassPropertyExtractor with type GetterClassProperty.
By default - GettersExtractor class is used. But you can specify your own extractor - if necessary.
Note: that GettersExtractor by default treats as getters only methods with non-void return type
and no arguments, so any other methods will be ignored by default. Also all static methods are ignored at the very
beginning, so you don't have to filter them out manually.
Note: if you specified in the constructor actual class (not an interface) - it will also contain all the
'getters' from the ancestor Object class, including #hashCode(), #getClass(), and #clone(). They are not filtered
out by default, to support rare occasions when they might be required. But cuz most of the time they are not wanted
to be used - you can use constant field DEFAULT_METHODS. You can use method
addExcludingFilter(String) with this filter to exclude all getters from Object class.
Or even better you can use ComparisonPerformers.buildGetters(Class) to create a builder with this filter
already added (but be careful, and read documentation).
This builder doesn't allow to specify a delegate performer specifically for a property, so default
DynamicComparisonPerformer will be used for all the created properties.
There're three groups of filters, used by this class to filter getters:
Method is included in the result performer if it matched by all requirement filters, at least one including filter (if any present) and NOT matched by any excluding filter.
If there're any requirement filters, and at least one of them returned false - method is ignored.
If there're no requirement filters or all of them accepted method - it is sent to including filters.
If there're any including filters, and none of them returned true for a method - it is ignored.
If there're no including filters, or one of them returned true - it is sent to excluding filters.
If there're any excluding filters and any one of them returned true - method ignored.
If there're no excluding filters of none of them returned true - method is included.
So if no filters of any kind were specified - all extracted getters will be used.
This builder implements AbstractDynamicPerformerBuilder, so it provides all the
DynamicComparisonPerformer functionality. Check out documentation for the parent class.
Note: all created performers are recursive. Meaning that each created performer will delegate to itself for any field of the same type (or an extended type). Unless (!) any other delegate is registered for the type specified to the constructor.
| Modifier and Type | Class and Description |
|---|---|
static class |
GettersDynamicPerformerBuilder.PatternPredicate
Predicates created from a
Pattern instance or a string regex pattern, and used to match Method
instances. |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_METHODS
Regexp string that matches four methods:
clone
getClass
hashCode
toString
Field is implemented as a String so any of these four methods will be matched
even if overriden in a subclass.
|
| Constructor and Description |
|---|
GettersDynamicPerformerBuilder(java.lang.Class<T> type) |
GettersDynamicPerformerBuilder(java.lang.Class<T> type,
ClassPropertyExtractor<GetterClassProperty<?,?>> gettersExtractor) |
| Modifier and Type | Method and Description |
|---|---|
GettersDynamicPerformerBuilder<T> |
addExcludingFilter(java.util.function.Predicate<java.lang.reflect.Method> filter)
Specified filter will be stored in the set of excluding filters.
|
GettersDynamicPerformerBuilder<T> |
addExcludingFilter(java.lang.String pattern)
GettersDynamicPerformerBuilder.PatternPredicate is created from the specified string and
registered thru addExcludingFilter(Predicate) method. |
GettersDynamicPerformerBuilder<T> |
addFilter(java.util.function.Predicate<java.lang.reflect.Method> filter)
Specified filter will be stored in the set of including filters.
|
GettersDynamicPerformerBuilder<T> |
addFilter(java.lang.String pattern)
GettersDynamicPerformerBuilder.PatternPredicate is created from the specified string and
registered thru addFilter(Predicate) method. |
GettersDynamicPerformerBuilder<T> |
addRequirement(java.util.function.Predicate<java.lang.reflect.Method> filter)
Specified filter will be stored in the set of requirement filters.
|
CompositeComparisonPerformer<T> |
build(java.lang.String name) |
java.util.Set<java.util.function.Predicate<java.lang.reflect.Method>> |
getExcludingFilters()
Returns set of all excluding filters.
|
ClassPropertyExtractor<GetterClassProperty<?,?>> |
getGettersExtractor() |
java.util.Set<java.util.function.Predicate<java.lang.reflect.Method>> |
getIncludingFilters()
Returns set of all including filters.
|
java.util.Set<java.util.function.Predicate<java.lang.reflect.Method>> |
getRequirementFilters()
Returns set of all requirement filters.
|
configureDynamicPerformer, getDynamicPerformer, getTypepublic static final java.lang.String DEFAULT_METHODS
Field is implemented as a String so any of these four methods will be matched even if overriden in a subclass.
addExcludingFilter(String),
Constant Field Valuespublic GettersDynamicPerformerBuilder(java.lang.Class<T> type)
public GettersDynamicPerformerBuilder(java.lang.Class<T> type, ClassPropertyExtractor<GetterClassProperty<?,?>> gettersExtractor)
public ClassPropertyExtractor<GetterClassProperty<?,?>> getGettersExtractor()
public java.util.Set<java.util.function.Predicate<java.lang.reflect.Method>> getRequirementFilters()
public java.util.Set<java.util.function.Predicate<java.lang.reflect.Method>> getIncludingFilters()
public java.util.Set<java.util.function.Predicate<java.lang.reflect.Method>> getExcludingFilters()
public GettersDynamicPerformerBuilder<T> addFilter(java.lang.String pattern)
GettersDynamicPerformerBuilder.PatternPredicate is created from the specified string and
registered thru addFilter(Predicate) method.public GettersDynamicPerformerBuilder<T> addExcludingFilter(java.lang.String pattern)
GettersDynamicPerformerBuilder.PatternPredicate is created from the specified string and
registered thru addExcludingFilter(Predicate) method.DEFAULT_METHODSpublic GettersDynamicPerformerBuilder<T> addRequirement(java.util.function.Predicate<java.lang.reflect.Method> filter)
public GettersDynamicPerformerBuilder<T> addFilter(java.util.function.Predicate<java.lang.reflect.Method> filter)
public GettersDynamicPerformerBuilder<T> addExcludingFilter(java.util.function.Predicate<java.lang.reflect.Method> filter)
public CompositeComparisonPerformer<T> build(java.lang.String name)
build in class AbstractDynamicPerformerBuilder<T,CompositeComparisonPerformer<T>>