Class AcceptReject

java.lang.Object
nonapi.io.github.classgraph.scanspec.AcceptReject
Direct Known Subclasses:
AcceptReject.AcceptRejectPrefix, AcceptReject.AcceptRejectWholeString

public abstract class AcceptReject extends Object
A class storing accept or reject criteria.
  • Field Details

    • accept

      protected Set<String> accept
      Accepted items (whole-string match).
    • reject

      protected Set<String> reject
      Rejected items (whole-string match).
    • acceptPrefixesSet

      protected Set<String> acceptPrefixesSet
      Accepted items (prefix match), as a set.
    • acceptPrefixes

      protected List<String> acceptPrefixes
      Accepted items (prefix match), as a sorted list.
    • rejectPrefixes

      protected List<String> rejectPrefixes
      Rejected items (prefix match).
    • acceptGlobs

      protected Set<String> acceptGlobs
      Accept glob strings. (Serialized to JSON, for logging purposes.)
    • rejectGlobs

      protected Set<String> rejectGlobs
      Reject glob strings. (Serialized to JSON, for logging purposes.)
    • acceptPatterns

      protected transient List<Pattern> acceptPatterns
      Accept regexp patterns. (Not serialized to JSON.)
    • rejectPatterns

      protected transient List<Pattern> rejectPatterns
      Reject regexp patterns. (Not serialized to JSON.)
    • separatorChar

      protected char separatorChar
      The separator character.
  • Constructor Details

    • AcceptReject

      public AcceptReject()
      Deserialization constructor.
    • AcceptReject

      public AcceptReject(char separatorChar)
      Constructor for deserialization.
      Parameters:
      separatorChar - the separator char
  • Method Details

    • addToAccept

      public abstract void addToAccept(String str)
      Add to the accept.
      Parameters:
      str - The string to accept.
    • addToReject

      public abstract void addToReject(String str)
      Add to the reject.
      Parameters:
      str - The string to reject.
    • isAcceptedAndNotRejected

      public abstract boolean isAcceptedAndNotRejected(String str)
      Check if a string is accepted and not rejected.
      Parameters:
      str - The string to test.
      Returns:
      true if the string is accepted and not rejected.
    • isAccepted

      public abstract boolean isAccepted(String str)
      Check if a string is accepted.
      Parameters:
      str - The string to test.
      Returns:
      true if the string is accepted.
    • acceptHasPrefix

      public abstract boolean acceptHasPrefix(String str)
      Check if a string is a prefix of an accepted string.
      Parameters:
      str - The string to test.
      Returns:
      true if the string is a prefix of an accepted string.
    • isRejected

      public abstract boolean isRejected(String str)
      Check if a string is rejected.
      Parameters:
      str - The string to test.
      Returns:
      true if the string is rejected.
    • normalizePath

      public static String normalizePath(String path)
      Remove initial and final '/' characters, if any.
      Parameters:
      path - The path to normalize.
      Returns:
      The normalized path.
    • normalizePackageOrClassName

      public static String normalizePackageOrClassName(String packageOrClassName)
      Remove initial and final '.' characters, if any.
      Parameters:
      packageOrClassName - The package or class name.
      Returns:
      The normalized package or class name.
    • pathToPackageName

      public static String pathToPackageName(String path)
      Convert a path to a package name.
      Parameters:
      path - The path.
      Returns:
      The package name.
    • packageNameToPath

      public static String packageNameToPath(String packageName)
      Convert a package name to a path.
      Parameters:
      packageName - The package name.
      Returns:
      The path.
    • classNameToClassfilePath

      public static String classNameToClassfilePath(String className)
      Convert a class name to a classfile path.
      Parameters:
      className - The class name.
      Returns:
      The classfile path (including a ".class" suffix).
    • globToPattern

      public static Pattern globToPattern(String glob, boolean simpleGlob)
      Convert a spec with a '*' glob character into a regular expression.
      Parameters:
      glob - The glob string.
      simpleGlob - if true, handles simple globs: "*" matches zero or more characters (replaces "." with "\\.", "*" with ".*", then compiles a regular expression). If false, handles filesystem-style globs: "**" matches zero or more characters, "*" matches zero or more characters other than "/", "?" matches one character (replaces "." with "\\.", "**" with ".*", "*" with "[^/]*", and "?" with ".", then compiles a regular expression).
      Returns:
      The Pattern created from the glob string.
    • matchesPatternList

      private static boolean matchesPatternList(String str, List<Pattern> patterns)
      Check if a string matches one of the patterns in the provided list.
      Parameters:
      str - the string to test
      patterns - the patterns
      Returns:
      true, if successful
    • acceptIsEmpty

      public boolean acceptIsEmpty()
      Check if the accept is empty.
      Returns:
      true if there were no accept criteria added.
    • rejectIsEmpty

      public boolean rejectIsEmpty()
      Check if the reject is empty.
      Returns:
      true if there were no reject criteria added.
    • acceptAndRejectAreEmpty

      public boolean acceptAndRejectAreEmpty()
      Check if the accept and reject are empty.
      Returns:
      true if there were no accept or reject criteria added.
    • isSpecificallyAcceptedAndNotRejected

      public boolean isSpecificallyAcceptedAndNotRejected(String str)
      Check if a string is specifically accepted and not rejected.
      Parameters:
      str - The string to test.
      Returns:
      true if the requested string is specifically accepted and not rejected, i.e. will not return true if the accept is empty, or if the string is rejected.
    • isSpecificallyAccepted

      public boolean isSpecificallyAccepted(String str)
      Check if a string is specifically accepted.
      Parameters:
      str - The string to test.
      Returns:
      true if the requested string is specifically accepted, i.e. will not return true if the accept is empty.
    • sortPrefixes

      void sortPrefixes()
      Need to sort prefixes to ensure correct accept/reject evaluation (see Issue #167).
    • quoteList

      private static void quoteList(Collection<String> coll, StringBuilder buf)
      Quote list.
      Parameters:
      coll - the coll
      buf - the buf
    • toString

      public String toString()
      Overrides:
      toString in class Object