Package com.norconex.commons.lang.map
Class PropertyMatcher
java.lang.Object
com.norconex.commons.lang.map.PropertyMatcher
- All Implemented Interfaces:
Predicate<Properties>
Convenient way of matching values and/or fields (key)
in a given Properties.
- Since:
- 1.8.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionPropertyMatcher(TextMatcher fieldMatcher) A property matcher that will only match present fields, regardless of values.PropertyMatcher(TextMatcher fieldMatcher, TextMatcher valueMatcher) A property matcher matching both fields and values. -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets the field matcher (copy) ornullif the field matcher isnull.Gets the value matcher (copy) ornullif the value matcher isnull.inthashCode()match(Properties properties) Returns matching field/values in the givenProperties.booleanmatches(Properties properties) Tests whether this property matcher matches at least one value for the key in the givenProperties.replace(Properties properties, String replacement) Replaces all matching values of the matching keys in the givenPropertieswith the given replacement.booleantest(Properties properties) For compatibility withPredicate.toString()
-
Constructor Details
-
PropertyMatcher
A property matcher that will only match present fields, regardless of values. UsePropertyMatcher(TextMatcher, TextMatcher)to match both fields and values.- Parameters:
fieldMatcher- field matcher- Since:
- 2.0.0
-
PropertyMatcher
A property matcher matching both fields and values. Only a single value of multi-valued fields need to match to generate a positive match on values.
Either or both the field matcher and value matcher can be
null. Anullmatcher is equivalent to matching fields or value, respectively.- Parameters:
fieldMatcher- field matchervalueMatcher- value matcher- Since:
- 2.0.0
-
-
Method Details
-
getValueMatcher
Gets the value matcher (copy) ornullif the value matcher isnull.- Returns:
- value matcher
- Since:
- 2.0.0
-
getFieldMatcher
Gets the field matcher (copy) ornullif the field matcher isnull.- Returns:
- field matcher
- Since:
- 2.0.0
-
matches
Tests whether this property matcher matches at least one value for the key in the givenProperties. To get all matches instead, usematch(Properties).nulltext field or value matchers are considered to be matching all fields or values, respectively.- Parameters:
properties- the properties to look for a match- Returns:
trueif at least one value for the key matches the matcher's expression- See Also:
-
test
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
Returns matching field/values in the givenProperties. For multi-valued fields, only the matching values are returned.nulltext field or value matchers are considered to be matching all fields or values, respectively. 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
(never
null) - Since:
- 2.0.0
- See Also:
-
replace
Replaces all matching values of the matching keys in the givenPropertieswith the given replacement. If this property matcher has anullfield matcher, it will replace all matching values, for all fields. If it has anullvalue matcher, it will replace all values of matching fields. If both arenull, all values will be replaced for all keys.- 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
-
toString
-
equals
-
hashCode
public int hashCode()
-