public abstract class AbstractPatternFilter<T> extends AbstractFilter<T>
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.
log, TOSTRING_INDENT
Constructor and Description |
---|
AbstractPatternFilter()
DI-friendly constructor.
|
Modifier and Type | Method and Description |
---|---|
static List<Pattern> |
convert(List<String> patternStrings,
String prepend)
Collects a List containing
java.text.Pattern objects by concatenating
prepend + current_pattern_string and Pattern-compiling the result. |
protected String |
convert(T nonNullT)
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 |
onInitialize()
Compiles the List of Patterns used by this AbstractPatternFilter to match candidates.
|
void |
setAcceptCandidateOnPatternMatch(boolean acceptCandidateOnPatternMatch)
Assigns the
acceptCandidateOnPatternMatch 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.
|
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 Regexp
Pattern specification. |
String |
toString() |
accept, addDelayedLogMessage, initialize, isInitialized, onNullCandidate, setProcessNullValues, validateDiSetterCalledBeforeInitialization
public final void setPatternPrefix(String patternPrefix)
patternPrefix
- A prefix to be prepended to each pattern to render a Pattern.
If a null argument is supplied, nothing will be prepended.convert(java.util.List, String)
public void setPatterns(List<String> patterns)
Pattern
specification.
Each injected pattern will be compiled to a Pattern
by concatenating the patternPrefix
string,
given at construction time, to obtain the full regexp pattern. The resulting Patterns are matched for
candidates normally in the onCandidate(Object)
method.patterns
- The List of PatternStrings to compile.convert(java.util.List, String)
,
setPatternPrefix(String)
public final void setAcceptCandidateOnPatternMatch(boolean acceptCandidateOnPatternMatch)
acceptCandidateOnPatternMatch
parameter which defines the function of this
AbstractPatternFilter's accept method.acceptCandidateOnPatternMatch
- if true
, this AbstractPatternFilter will matchAtLeastOnce
candidate objects that match at least one of the supplied
regularExpressions. if false
, this AbstractPatternFilter will
noFilterMatches candidates that match at least one of the supplied
regularExpressions.public void setConverter(StringConverter<T> converter)
converter
- The StringConverter used to convert T-type objects to Strings which should
be matched by all supplied Patterns to T-object candidates.protected void onInitialize()
onInitialize
in class AbstractFilter<T>
patterns
protected boolean onCandidate(T nonNullCandidate)
Each nonNullCandidate is matched against all Patterns supplied to this AbstractPatternFilter. The match table of this AbstractPatternFilter on each candidate is as follows:
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.
onCandidate
in class AbstractFilter<T>
nonNullCandidate
- The candidate that should be tested for acceptance by this Filter. Never null.true
if the candidate is accepted by this Filter and false
otherwise.protected String convert(T nonNullT)
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.
nonNullT
- A non-null T object.public static List<Pattern> convert(List<String> patternStrings, String prepend)
java.text.Pattern
objects by concatenating
prepend + current_pattern_string
and Pattern-compiling the result.patternStrings
- The List of PatternStrings to compile.prepend
- A string to prepend each pattern. If a null argument is supplied, nothing
will be prepended.java.text.Pattern
objects by concatenating
prepend + current_pattern_string
and Pattern-compiling the result.public String toString()
toString
in class AbstractFilter<T>
Copyright © 2005–2017 MojoHaus. All rights reserved.