Class MatchRules


  • public class MatchRules
    extends Object
    Immutable criteria for filtering constants based on their name and other settings for aggregation.
    • Method Detail

      • of

        public static MatchRules of()
        Specifies criteria for filtering constants based on their name and other settings. By default, the rules will match all names but won't visit the contents of constant collections.

        It should be noted that since all MatchRules instances are immutable, the same default instance is always returned by this method. Any additional criteria will construct entirely new instances.

        Returns:
        the default immutable rules instance
      • all

        public MatchRules all​(String... required)
        Appends required strings to the existing rules. A constant will only match this rule if its name contains all of the specified strings.
        Parameters:
        required - all the strings a constant name must contain in order to match
        Returns:
        new instance containing the amended rules or itself if no new rules are specified
      • any

        public MatchRules any​(String... optional)
        Appends optional strings to the existing rules. A constant will only match this rule if its name contains any (at least one) of the specified strings.
        Parameters:
        optional - strings a constant name is expected to contain at least one of in order to match
        Returns:
        new instance containing the amended rules or itself if no new rules are specified
      • not

        public MatchRules not​(String... excluded)
        Appends excluded strings to the existing rules. A constant will only match this rule if its name contains none of the specified strings.
        Parameters:
        excluded - all the strings a constant name must not contain in order to match
        Returns:
        new instance containing the amended rules or itself if no new rules are specified
      • collections

        public MatchRules collections​(boolean visit)
        Sets whether the contents contained within constant collections should be aggregated.
        Parameters:
        visit - true if collections should be visited or false to disable
        Returns:
        new instance containing the amended rules or itself if no new rules are specified
      • matches

        public boolean matches​(String name)
        Checks if the provided name matches the criteria contained within these rules.
        Parameters:
        name - the name to check
        Returns:
        true if the name matches, otherwise false
      • isAggregatingFromCollections

        public boolean isAggregatingFromCollections()
        Gets whether aggregating from the contents of constant collections is allowed by these rules or not.
        Returns:
        true if allowed, otherwise false
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object