Class 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 Properties does not store null values, a null pattern for the field or value matcher will instead match anything. If Properties itself is null, it is considered non-matching.

    Since:
    1.8.0
    Author:
    Pascal Essiembre
    See Also:
    TextMatcher
    • Constructor Detail

      • PropertyMatcher

        public PropertyMatcher​(TextMatcher fieldMatcher)
        A property matcher matching empty or null elements.
        Parameters:
        fieldMatcher - field match instructions
        Since:
        2.0.0
      • PropertyMatcher

        public PropertyMatcher​(TextMatcher fieldMatcher,
                               TextMatcher valueMatcher)
        Constructor.
        Parameters:
        fieldMatcher - field match instructions
        valueMatcher - 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
      • isCaseSensitive

        @Deprecated
        public boolean isCaseSensitive()
        Deprecated.
        Since 2.0.0 use getValueMatcher().
        Gets whether this valueMatcher is case sensitive.
        Returns:
        the expression.
      • matches

        public boolean matches​(Properties properties)
        Tests whether this property valueMatcher matches at least one value for the key in the given Properties. To get all matches instead, use match(Properties) instead.
        Parameters:
        properties - the properties to look for a match
        Returns:
        true if at least one value for the key matches the valueMatcher's expression
        See Also:
        match(Properties)
      • test

        public boolean test​(Properties properties)
        For compatibility with Predicate. Same as invoking matches(Properties).
        Specified by:
        test in interface Predicate<Properties>
        Parameters:
        properties - the properties to look for a match
        Returns:
        true if 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 given Properties. To simply get whether there is a match instead, use the predicate test(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 given Properties with the given replacement.
        Parameters:
        properties - the properties to look for a match and replace
        replacement - text replacement
        Returns:
        original fields/values that were replaced (or empty).
        Since:
        2.0.0
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object