Class ClassMatcher

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.String>, java.util.Collection<java.lang.String>, java.util.Set<java.lang.String>

    public class ClassMatcher
    extends java.util.AbstractSet<java.lang.String>
    A matcher for classes based on package and/or location and/or module/

    Performs pattern matching of a class against a set of pattern entries. A class pattern is a string of one of the forms:

    • 'org.package.SomeClass' will match a specific class
    • 'org.package.' will match a specific package hierarchy
    • 'org.package.SomeClass$NestedClass ' will match a nested class exactly otherwise. Nested classes are matched by their containing class. (eg. org.example.MyClass matches org.example.MyClass$AnyNestedClass)
    • 'file:///some/location/' - A file system directory from which the class was loaded
    • 'file:///some/location.jar' - The URI of a jar file from which the class was loaded
    • 'jrt:/modulename' - A Java9 module name
    • Any of the above patterns preceded by '-' will exclude rather than include the match.
    When class is initialized from a classpath pattern string, entries in this string should be separated by ':' (semicolon) or ',' (comma).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(java.lang.String pattern)  
      boolean add​(java.lang.String... pattern)  
      protected boolean add​(ClassMatcher.Entry entry)  
      void clear()  
      boolean exclude​(java.lang.String name)  
      boolean exclude​(java.lang.String... name)  
      java.lang.String[] getExclusions()  
      java.lang.String[] getInclusions()  
      java.lang.String[] getPatterns()  
      boolean include​(java.lang.String name)  
      boolean include​(java.lang.String... name)  
      java.util.Iterator<java.lang.String> iterator()  
      boolean match​(java.lang.Class<?> clazz)
      Match the class name against the pattern
      boolean match​(java.lang.String name)
      Match the class name against the pattern
      boolean match​(java.lang.String name, java.net.URL url)  
      protected ClassMatcher.Entry newEntry​(java.lang.String pattern)  
      protected ClassMatcher.Entry newEntry​(java.lang.String name, boolean inclusive)  
      boolean remove​(java.lang.Object o)  
      int size()  
      • Methods inherited from class java.util.AbstractSet

        equals, hashCode, removeAll
      • Methods inherited from class java.util.AbstractCollection

        addAll, contains, containsAll, isEmpty, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        addAll, contains, containsAll, isEmpty, retainAll, spliterator, toArray, toArray
    • Constructor Detail

      • ClassMatcher

        public ClassMatcher()
      • ClassMatcher

        public ClassMatcher​(ClassMatcher patterns)
      • ClassMatcher

        public ClassMatcher​(java.lang.String... patterns)
      • ClassMatcher

        public ClassMatcher​(java.lang.String pattern)
    • Method Detail

      • include

        public boolean include​(java.lang.String name)
      • include

        public boolean include​(java.lang.String... name)
      • exclude

        public boolean exclude​(java.lang.String name)
      • exclude

        public boolean exclude​(java.lang.String... name)
      • add

        public boolean add​(java.lang.String pattern)
        Specified by:
        add in interface java.util.Collection<java.lang.String>
        Specified by:
        add in interface java.util.Set<java.lang.String>
        Overrides:
        add in class java.util.AbstractCollection<java.lang.String>
      • add

        public boolean add​(java.lang.String... pattern)
      • newEntry

        protected ClassMatcher.Entry newEntry​(java.lang.String name,
                                              boolean inclusive)
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<java.lang.String>
        Specified by:
        remove in interface java.util.Set<java.lang.String>
        Overrides:
        remove in class java.util.AbstractCollection<java.lang.String>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<java.lang.String>
        Specified by:
        clear in interface java.util.Set<java.lang.String>
        Overrides:
        clear in class java.util.AbstractCollection<java.lang.String>
      • iterator

        public java.util.Iterator<java.lang.String> iterator()
        Specified by:
        iterator in interface java.util.Collection<java.lang.String>
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.String>
        Specified by:
        iterator in interface java.util.Set<java.lang.String>
        Specified by:
        iterator in class java.util.AbstractCollection<java.lang.String>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<java.lang.String>
        Specified by:
        size in interface java.util.Set<java.lang.String>
        Specified by:
        size in class java.util.AbstractCollection<java.lang.String>
      • getPatterns

        public java.lang.String[] getPatterns()
        Returns:
        array of classpath patterns
      • getInclusions

        public java.lang.String[] getInclusions()
        Returns:
        array of inclusive classpath patterns
      • getExclusions

        public java.lang.String[] getExclusions()
        Returns:
        array of excluded classpath patterns (without '-' prefix)
      • match

        public boolean match​(java.lang.String name)
        Match the class name against the pattern
        Parameters:
        name - name of the class to match
        Returns:
        true if class matches the pattern
      • match

        public boolean match​(java.lang.Class<?> clazz)
        Match the class name against the pattern
        Parameters:
        clazz - A class to try to match
        Returns:
        true if class matches the pattern
      • match

        public boolean match​(java.lang.String name,
                             java.net.URL url)