Package com.norconex.commons.lang.map
Class PropertyMatcher
- java.lang.Object
-
- com.norconex.commons.lang.map.PropertyMatcher
-
- All Implemented Interfaces:
Predicate<Properties>
public final class PropertyMatcher extends Object implements Predicate<Properties>
Convenient way of matching values and/or fields (key) in a given
Properties.Null handling:
Since
Propertiesdoes not storenullvalues, anullpattern for the field or value matcher will instead match anything. IfPropertiesitself isnull, it is considered non-matching.- Since:
- 1.8.0
- Author:
- Pascal Essiembre
- See Also:
TextMatcher
-
-
Constructor Summary
Constructors Constructor Description PropertyMatcher(TextMatcher fieldMatcher)A property matcher matching empty ornullelements.PropertyMatcher(TextMatcher fieldMatcher, TextMatcher valueMatcher)Constructor.PropertyMatcher(String field)Deprecated.Since 2.0.0 usePropertyMatcher(TextMatcher, TextMatcher).PropertyMatcher(String field, String regex, boolean caseSensitive)Deprecated.Since 2.0.0 usePropertyMatcher(TextMatcher, TextMatcher).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanequals(Object other)TextMatchergetFieldMatcher()Gets the field matcher (copy).StringgetKey()Deprecated.Since 2.0.0 usegetFieldMatcher().StringgetRegex()Deprecated.Since 2.0.0 usegetValueMatcher().TextMatchergetValueMatcher()Gets the value matcher (copy).inthashCode()booleanisCaseSensitive()Deprecated.Since 2.0.0 usegetValueMatcher().static PropertyMatcherloadFromXML(XML xml)Propertiesmatch(Properties properties)Returns matching field/values in the givenProperties.booleanmatches(Properties properties)Tests whether this property valueMatcher matches at least one value for the key in the givenProperties.Propertiesreplace(Properties properties, String replacement)Replaces all matching values for the key in the givenPropertieswith the given replacement.static voidsaveToXML(XML xml, PropertyMatcher matcher)booleantest(Properties properties)For compatibility withPredicate.StringtoString()
-
-
-
Constructor Detail
-
PropertyMatcher
@Deprecated public PropertyMatcher(String field, String regex, boolean caseSensitive)
Deprecated.Since 2.0.0 usePropertyMatcher(TextMatcher, TextMatcher).Constructor.- Parameters:
field- properties keyregex- regular expressioncaseSensitive-trueif case sensitive
-
PropertyMatcher
@Deprecated public PropertyMatcher(String field)
Deprecated.Since 2.0.0 usePropertyMatcher(TextMatcher, TextMatcher).A property matcher matching empty ornullelements.- Parameters:
field- properties field name to match as-is
-
PropertyMatcher
public PropertyMatcher(TextMatcher fieldMatcher)
A property matcher matching empty ornullelements.- Parameters:
fieldMatcher- field match instructions- Since:
- 2.0.0
-
PropertyMatcher
public PropertyMatcher(TextMatcher fieldMatcher, TextMatcher valueMatcher)
Constructor.- Parameters:
fieldMatcher- field match instructionsvalueMatcher- value match instructions- Since:
- 2.0.0
-
-
Method Detail
-
getValueMatcher
public TextMatcher getValueMatcher()
Gets the value matcher (copy).- Returns:
- value matcher
- Since:
- 2.0.0
-
getFieldMatcher
public TextMatcher getFieldMatcher()
Gets the field matcher (copy).- Returns:
- field matcher
- Since:
- 2.0.0
-
getRegex
@Deprecated public String getRegex()
Deprecated.Since 2.0.0 usegetValueMatcher().Gets the expression.- Returns:
- the expression.
-
isCaseSensitive
@Deprecated public boolean isCaseSensitive()
Deprecated.Since 2.0.0 usegetValueMatcher().Gets whether this valueMatcher is case sensitive.- Returns:
- the expression.
-
getKey
@Deprecated public String getKey()
Deprecated.Since 2.0.0 usegetFieldMatcher().Gets the field name being matched.- Returns:
- the field name
-
matches
public boolean matches(Properties properties)
Tests whether this property valueMatcher matches at least one value for the key in the givenProperties. To get all matches instead, usematch(Properties)instead.- Parameters:
properties- the properties to look for a match- Returns:
trueif at least one value for the key matches the valueMatcher's expression- See Also:
match(Properties)
-
test
public boolean test(Properties properties)
For compatibility withPredicate. Same as invokingmatches(Properties).- Specified by:
testin interfacePredicate<Properties>- Parameters:
properties- the properties to look for a match- Returns:
trueif at least one value for the key matches the list of valueMatcher regular expressions
-
match
public Properties match(Properties properties)
Returns matching field/values in the givenProperties. To simply get whether there is a match instead, use the predicatetest(Properties)method instead.- Parameters:
properties- the properties to look for a match- Returns:
- a list of matching values, or an empty list
- Since:
- 2.0.0
- See Also:
test(Properties)
-
replace
public Properties replace(Properties properties, String replacement)
Replaces all matching values for the key in the givenPropertieswith the given replacement.- Parameters:
properties- the properties to look for a match and replacereplacement- text replacement- Returns:
- original fields/values that were replaced (or empty).
- Since:
- 2.0.0
-
loadFromXML
public static PropertyMatcher loadFromXML(XML xml)
-
saveToXML
public static void saveToXML(XML xml, PropertyMatcher matcher)
-
-