Class RegexNamespace

  • All Implemented Interfaces:
    Namespace

    public class RegexNamespace
    extends java.lang.Object
    implements Namespace

    The RegexNamespace matches a subject based on one or more regex patterns.

     

    Regex is an abbreviation for "regular expression". Regular expression libraries provide rich string matching capabilities based upon string patterns ("regular expressions"). Different regular expression libraries vary in their syntax and functionality. This class uses the library provided by the Java Pattern class.

     

    RegexNamespace can contain include regex patterns and exclude patterns. A subject matches a RegexNamespace if it matches at least one of the namespace's include regex patterns and does not match any of its exclude patterns.

    • Constructor Summary

      Constructors 
      Constructor Description
      RegexNamespace()
      Initializes an empty new instance of the RegexNamespace class.
      RegexNamespace​(java.lang.String includeRegex)
      Initializes a new instance of the RegexNamespace class with an include regex pattern.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addExcludeRegex​(java.lang.String regex)
      Adds an exclude regex pattern to the namespace.
      void addIncludeRegex​(java.lang.String regex)
      Adds an include regex pattern to the namespace.
      boolean match​(java.lang.String subjectName)
      Tests a String to see if it falls within this Namespace.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • RegexNamespace

        public RegexNamespace()
        Initializes an empty new instance of the RegexNamespace class. This instance will match no subjects unless one or more regex patterns are first added to the instance via the addIncludeRegex(String) method.
      • RegexNamespace

        public RegexNamespace​(java.lang.String includeRegex)
        Initializes a new instance of the RegexNamespace class with an include regex pattern.
        Parameters:
        includeRegex - A regex defining an include pattern.
    • Method Detail

      • addIncludeRegex

        public void addIncludeRegex​(java.lang.String regex)
        Adds an include regex pattern to the namespace.
        Parameters:
        regex - A regex defining an include pattern.
      • addExcludeRegex

        public void addExcludeRegex​(java.lang.String regex)
        Adds an exclude regex pattern to the namespace.
        Parameters:
        regex - A regex defining an exclude pattern.
      • match

        public boolean match​(java.lang.String subjectName)

        Tests a String to see if it falls within this Namespace.

        Specified by:
        match in interface Namespace
        Parameters:
        subjectName - The string to be tested for matching.
        Returns:
        true if subject falls within this Namespace, false otherwise.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object