Class AbstractPatternFilter<T>
- All Implemented Interfaces:
Filter<T>
- Direct Known Subclasses:
PatternFileFilter
,PatternURLFilter
AbstractFilter implementation containing a Java Pattern which should be used to determine if candidate T objects match any of the supplied regularExpressions. Since Java regexp Patterns only match strings, a pluggable StringConverter is used to convert T-type objects to strings for the actual matching.
The structure of setter methods is provided to enable simpler configuration using the default Maven/Plexus dependency injection mechanism. The internal state of each AbstractPatternFilter is not intended to be changed after its creation.
- Since:
- 2.0
-
Field Summary
FieldsFields inherited from class org.codehaus.mojo.jaxb2.shared.filters.AbstractFilter
log, TOSTRING_INDENT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCollects a List containingjava.text.Pattern
objects by concatenatingprepend + current_pattern_string
and Pattern-compiling the result.protected String
Method implementation which converts a non-null T object to a String to be matched by the Java Regexp Pattern contained within this AbstractPatternFilter implementation.protected boolean
onCandidate
(T nonNullCandidate) Each nonNullCandidate is matched against all Patterns supplied to this AbstractPatternFilter.protected void
Compiles the List of Patterns used by this AbstractPatternFilter to match candidates.final void
setAcceptCandidateOnPatternMatch
(boolean acceptCandidateOnPatternMatch) Assigns theacceptCandidateOnPatternMatch
parameter which defines the function of this AbstractPatternFilter's accept method.void
setConverter
(StringConverter<T> converter) Assigns the StringConverter used to convert T-type objects to Strings.final void
setPatternPrefix
(String patternPrefix) Assigns a prefix to be prepended to any patterns submitted to this AbstractPatternFilter.void
setPatterns
(List<String> patterns) Injects a List of patterns complying with the Java RegexpPattern
specification.toString()
Methods inherited from class org.codehaus.mojo.jaxb2.shared.filters.AbstractFilter
accept, addDelayedLogMessage, initialize, isInitialized, onNullCandidate, setProcessNullValues, validateDiSetterCalledBeforeInitialization
-
Field Details
-
acceptCandidateOnPatternMatch
private boolean acceptCandidateOnPatternMatch -
converter
-
regularExpressions
-
patternPrefix
-
patterns
-
-
Constructor Details
-
AbstractPatternFilter
public AbstractPatternFilter()DI-friendly constructor.
-
-
Method Details
-
setPatternPrefix
Assigns a prefix to be prepended to any patterns submitted to this AbstractPatternFilter.- Parameters:
patternPrefix
- A prefix to be prepended to each pattern to render a Pattern. If a null argument is supplied, nothing will be prepended.- See Also:
-
setPatterns
Injects a List of patterns complying with the Java RegexpPattern
specification. Each injected pattern will be compiled to aPattern
by concatenating thepatternPrefix
string, given at construction time, to obtain the full regexp pattern. The resulting Patterns are matched for candidates normally in theonCandidate(Object)
method.- Parameters:
patterns
- The List of PatternStrings to compile.- See Also:
-
setAcceptCandidateOnPatternMatch
public final void setAcceptCandidateOnPatternMatch(boolean acceptCandidateOnPatternMatch) Assigns theacceptCandidateOnPatternMatch
parameter which defines the function of this AbstractPatternFilter's accept method.- Parameters:
acceptCandidateOnPatternMatch
- iftrue
, this AbstractPatternFilter will matchAtLeastOnce candidate objects that match at least one of the supplied regularExpressions. iffalse
, this AbstractPatternFilter will noFilterMatches candidates that match at least one of the supplied regularExpressions.
-
onInitialize
protected void onInitialize()Compiles the List of Patterns used by this AbstractPatternFilter to match candidates. If no patterns are supplied (by configuration or constructor call), no regularExpressions Pattern List will be created for use by this AbstractPatternFilter. Instead, some logging is emitted onto the console.- Overrides:
onInitialize
in classAbstractFilter<T>
- See Also:
-
onCandidate
Each nonNullCandidate is matched against all Patterns supplied to this AbstractPatternFilter. The match table of this AbstractPatternFilter on each candidate is as follows:
Truth table for the onCandidate method at least 1 filter matches acceptCandidateOnPatternMatch result true true true false true false true false false false false true Method that is invoked to determine if a candidate instance should be accepted or not.
- Specified by:
onCandidate
in classAbstractFilter<T>
- Parameters:
nonNullCandidate
- The candidate that should be tested for acceptance by this Filter. Never null.- Returns:
true
if the candidate is accepted by this Filter andfalse
otherwise.
-
convert
Method implementation which converts a non-null T object to a String to be matched by the Java Regexp Pattern contained within this AbstractPatternFilter implementation. Override for a non-standard conversion.
- Parameters:
nonNullT
- A non-null T object.- Returns:
- A string to be converted.
-
convert
Collects a List containingjava.text.Pattern
objects by concatenatingprepend + current_pattern_string
and Pattern-compiling the result.- Parameters:
patternStrings
- The List of PatternStrings to compile.prepend
- A string to prepend each pattern. If a null argument is supplied, nothing will be prepended.- Returns:
- a List containing
java.text.Pattern
objects by concatenatingprepend + current_pattern_string
and Pattern-compiling the result.
-
toString
- Overrides:
toString
in classAbstractFilter<T>
-