public class StringPatternCollection extends AStringFilter implements IJSONConvertible
Attention: Since version 1.1 of this class there is an incompatibility
to its predecessors.
It now creates StringPattern objects that match '*' to empty string.
That is, the pattern "Tom*" now matches string "Tom" which it doesn't
before version 1.1.
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
DEFAULT_PATTERN_SEPARATOR |
JSON_ARRAY_END, JSON_ARRAY_START, JSON_ELEMENT_SEPARATOR, JSON_LITERAL_FALSE, JSON_LITERAL_NULL, JSON_LITERAL_TRUE, JSON_OBJECT_END, JSON_OBJECT_START, JSON_PAIR_SEPARATOR, JSON_STRING_DELIMITER, JSON_STRING_ESCAPE
ALL, NONE
Constructor and Description |
---|
StringPatternCollection()
Initialize the new instance with default values.
|
StringPatternCollection(java.util.Collection<java.lang.String> strPatterns)
Initialize the new instance with a collection of patterns.
|
StringPatternCollection(java.lang.String... strPatterns)
Initialize the new instance with a pattern array.
|
StringPatternCollection(StringPattern pattern)
Initialize the new instance with one pattern.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String pattern)
Adds the given pattern as pattern to the collection of patterns,
if it is not yet there.
|
void |
add(StringPattern aPattern)
Adds the given pattern to the collection of patterns,
if it is not yet there
|
void |
addPatterns(java.util.Collection<java.lang.String> strPatterns)
Adds all patterns strings in the given collection.
|
void |
addPatterns(java.lang.String patternList)
Adds all patterns in the given string which must be separated by ';'.
|
void |
addPatterns(java.lang.String[] patternCollection)
Adds all patterns in the given array.
|
void |
addPatterns(StringPatternCollection patternCollection)
Adds all patterns from the given pattern collection.
|
void |
addPatterns(java.lang.String patternList,
java.lang.String separators)
Adds all patterns in the given string which must be separated by ';'.
|
void |
appendAsJSONString(java.lang.Appendable output)
The receiver of this method must append its internal state as JSON string
representation to the given buffer.
|
StringPatternCollection |
copy()
Returns a copy of this pattern collection.
|
static StringPatternCollection |
create(java.lang.String[] patterns,
boolean ignoreCase)
Returns a new instance with the given string patterns and the selection,
if case should be ignored when comparing characters.
|
static StringPatternCollection |
create(java.lang.String patterns,
boolean ignoreCase)
Returns a new instance with the given string patterns and the selection,
if case should be ignored when comparing characters.
|
protected java.lang.String |
getDefaultPatternSeparator()
Returns the default separators for patterns
|
protected java.lang.Boolean |
getIgnoreCase()
Returns whether or not the pattern matching ignores upper and lower case
Might return null if not specified.
|
protected java.util.Collection<StringPattern> |
getPatterns() |
java.lang.String[] |
getPatternStrings()
Returns an array with all pattern strings contained in this object.
|
boolean |
isEmpty()
Returns true if no pattern definition is currently in this collection
|
boolean |
matches(java.lang.String aString)
Returns true if the given string matches the filter otherwise false.
|
boolean |
matchesAll(java.lang.String probe)
Returns true if the given probe matches all patterns in this collection.
|
boolean |
matchesAny(java.lang.String probe)
Returns true, if the given probe matches any of the patterns.
|
boolean |
matchesNone(java.lang.String probe)
Returns true, if the given probe matches none of the patterns.
|
protected StringPattern |
newPattern(java.lang.String pattern)
Creates and returns a new pattern object out of the given string.
|
java.util.Collection<java.lang.String> |
reject(java.util.Collection<java.lang.String> strings)
Returns a collection containing all of the given strings that do NOT match
any pattern of this pattern collection.
|
java.lang.String[] |
reject(java.lang.String[] strings)
Returns an array containing all of the given strings that do NOT match
any pattern of this pattern collection.
|
boolean |
remove(StringPattern aPattern)
Removes the given pattern from the collection if it exists.
|
void |
reset()
Removes all patterns and starts with a new empty collection.
|
java.util.Collection<java.lang.String> |
select(java.util.Collection<java.lang.String> strings)
Returns an array containing all of the given strings that matches any
pattern of this pattern collection.
|
java.lang.String[] |
select(java.lang.String[] strings)
Returns an array containing all of the given strings that matches any
pattern of this pattern collection.
|
protected java.util.Collection<java.lang.String> |
selectOrReject(java.util.Collection<java.lang.String> strings,
boolean select)
If possible, the result collection is of the same type as the input collection.
|
protected java.lang.String[] |
selectOrReject(java.lang.String[] strings,
boolean select) |
void |
setIgnoreCase(boolean ignore)
Sets whether all the patterns inside this collection should ignore case or not.
|
protected void |
setIgnoreCase(java.lang.Boolean ignoreCase)
Sets whether the pattern matching should ignore case or not
|
protected void |
setPatterns(java.util.Collection<StringPattern> patterns) |
int |
size()
returns the number of patterns in this collection.
|
protected StringUtil |
str() |
java.lang.String |
toJSON()
Returns a JSON string representation of this object.
|
protected static final java.lang.String DEFAULT_PATTERN_SEPARATOR
public StringPatternCollection()
public StringPatternCollection(StringPattern pattern)
public StringPatternCollection(java.lang.String... strPatterns)
public StringPatternCollection(java.util.Collection<java.lang.String> strPatterns)
strPatterns
- A collection of String.public static StringPatternCollection create(java.lang.String patterns, boolean ignoreCase)
patterns
- The pattern definitions.ignoreCase
- Definition, if case sensitive character comparison or not.public static StringPatternCollection create(java.lang.String[] patterns, boolean ignoreCase)
patterns
- The pattern definitions.ignoreCase
- Definition, if case sensitive character comparison or not.public boolean matches(java.lang.String aString)
matches
in interface IObjectFilter<java.lang.String>
matches
in interface IStringFilter
aString
- Any string or even nullpublic boolean matchesAny(java.lang.String probe)
probe
- The string to match against all patternspublic boolean matchesNone(java.lang.String probe)
probe
- The string to check against all patternspublic boolean matchesAll(java.lang.String probe)
probe
- The string to check against all patternspublic java.lang.String[] select(java.lang.String[] strings)
strings
- The strings to be matched against this patternpublic java.lang.String[] reject(java.lang.String[] strings)
strings
- The strings to be matched against this patternpublic java.util.Collection<java.lang.String> select(java.util.Collection<java.lang.String> strings)
strings
- The strings to be matched against this patternpublic java.util.Collection<java.lang.String> reject(java.util.Collection<java.lang.String> strings)
strings
- The strings to be matched against this patternpublic void reset()
public void add(StringPattern aPattern)
aPattern
- The pattern to addpublic void addPatterns(java.lang.String patternList)
patternList
- A list of patterns separated by ';'public void addPatterns(java.lang.String patternList, java.lang.String separators)
public void addPatterns(java.util.Collection<java.lang.String> strPatterns)
strPatterns
- A collection of Stringpublic void addPatterns(StringPatternCollection patternCollection)
patternCollection
- A pattern collection like this onepublic void addPatterns(java.lang.String[] patternCollection)
public void add(java.lang.String pattern)
Since V1.1 the pattern internally created supports '*' matching empty strings (e.g. "AC" matches "A*C")!
pattern
- The pattern to addpublic boolean remove(StringPattern aPattern)
aPattern
- The pattern to removepublic int size()
public boolean isEmpty()
public java.lang.String[] getPatternStrings()
public StringPatternCollection copy()
public void setIgnoreCase(boolean ignore)
ignore
- true if pattern matching should be case insensitive from now onpublic void appendAsJSONString(java.lang.Appendable output)
IJSONConvertible
appendAsJSONString
in interface IJSONConvertible
output
- The output target to which to append the JSON string (must not be null).public java.lang.String toJSON()
toJSON
in interface IJSONConvertible
protected StringPattern newPattern(java.lang.String pattern)
protected java.lang.String[] selectOrReject(java.lang.String[] strings, boolean select)
protected java.util.Collection<java.lang.String> selectOrReject(java.util.Collection<java.lang.String> strings, boolean select)
protected java.lang.String getDefaultPatternSeparator()
addPatterns(String)
protected java.util.Collection<StringPattern> getPatterns()
protected void setPatterns(java.util.Collection<StringPattern> patterns)
protected java.lang.Boolean getIgnoreCase()
protected void setIgnoreCase(java.lang.Boolean ignoreCase)
protected StringUtil str()