Class AbstractPatternFilter<T>
- java.lang.Object
-
- org.codehaus.mojo.jaxb2.shared.filters.AbstractFilter<T>
-
- org.codehaus.mojo.jaxb2.shared.filters.pattern.AbstractPatternFilter<T>
-
- All Implemented Interfaces:
Filter<T>
- Direct Known Subclasses:
PatternFileFilter
,PatternURLFilter
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.
- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
acceptCandidateOnPatternMatch
private StringConverter<T>
converter
private java.lang.String
patternPrefix
private java.util.List<java.lang.String>
patterns
private java.util.List<java.util.regex.Pattern>
regularExpressions
-
Fields inherited from class org.codehaus.mojo.jaxb2.shared.filters.AbstractFilter
log, TOSTRING_INDENT
-
-
Constructor Summary
Constructors Constructor Description AbstractPatternFilter()
DI-friendly constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.util.List<java.util.regex.Pattern>
convert(java.util.List<java.lang.String> patternStrings, java.lang.String prepend)
Collects a List containingjava.text.Pattern
objects by concatenatingprepend + current_pattern_string
and Pattern-compiling the result.protected java.lang.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 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.void
setPatternPrefix(java.lang.String patternPrefix)
Assigns a prefix to be prepended to any patterns submitted to this AbstractPatternFilter.void
setPatterns(java.util.List<java.lang.String> patterns)
Injects a List of patterns complying with the Java RegexpPattern
specification.java.lang.String
toString()
-
Methods inherited from class org.codehaus.mojo.jaxb2.shared.filters.AbstractFilter
accept, addDelayedLogMessage, initialize, isInitialized, onNullCandidate, setProcessNullValues, validateDiSetterCalledBeforeInitialization
-
-
-
-
Field Detail
-
acceptCandidateOnPatternMatch
private boolean acceptCandidateOnPatternMatch
-
converter
private StringConverter<T> converter
-
regularExpressions
private java.util.List<java.util.regex.Pattern> regularExpressions
-
patternPrefix
private java.lang.String patternPrefix
-
patterns
private java.util.List<java.lang.String> patterns
-
-
Method Detail
-
setPatternPrefix
public final void setPatternPrefix(java.lang.String patternPrefix)
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:
convert(java.util.List, String)
-
setPatterns
public void setPatterns(java.util.List<java.lang.String> patterns)
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:
convert(java.util.List, String)
,setPatternPrefix(String)
-
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.
-
setConverter
public void setConverter(StringConverter<T> converter)
Assigns the StringConverter used to convert T-type objects to Strings. This StringConverter is used to acquire input comparison values for all Patterns to T-object candidates.- Parameters:
converter
- The StringConverter used to convert T-type objects to Strings which should be matched by all supplied Patterns to T-object candidates.
-
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:
patterns
-
onCandidate
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:
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
protected java.lang.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.
- Parameters:
nonNullT
- A non-null T object.- Returns:
- A string to be converted.
-
convert
public static java.util.List<java.util.regex.Pattern> convert(java.util.List<java.lang.String> patternStrings, java.lang.String prepend)
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
public java.lang.String toString()
- Overrides:
toString
in classAbstractFilter<T>
-
-