Class BlackAndWhitelistFilter

  • All Implemented Interfaces:
    Predicate<String>

    public class BlackAndWhitelistFilter
    extends Object
    implements Predicate<String>
    This class can be used for filtering string elements by using blacklists and/or whitelists.

    Tested elements are permitted if:

    • The whitelist is empty and the tested element does not match a blacklist entry.
    • The tested element matches an entry in the whitelist and does not match a blacklist entry.

    Once created, call test(String)} to know if a String is accepted by the filter.

    See Also:
    Pattern.compile(String)
    • Constructor Detail

      • BlackAndWhitelistFilter

        public BlackAndWhitelistFilter​(Collection<Pattern> regExpBlacklist,
                                       Collection<Pattern> regExpWhitelist)
        Creates a new BlackAndWhitelistFilter with provided collections.
        Parameters:
        regExpBlacklist - Regular expression Patterns representing this filter blacklist.
        regExpWhitelist - Regular expression Patterns representing this filter whitelist.
    • Method Detail

      • test

        public boolean test​(String string)
        Returns true if the provided string is accepted by this filter, false otherwise.

        A string value is excluded by the filter if the whitelist is non-empty and it is not in the whitelist, or if the string is in the blacklist.

        Specified by:
        test in interface Predicate<String>
        Parameters:
        string - The string to test.
        Returns:
        true if the provided String is accepted by this filter, false otherwise.