Class AcceptReject
- java.lang.Object
-
- nonapi.io.github.classgraph.scanspec.AcceptReject
-
- Direct Known Subclasses:
AcceptReject.AcceptRejectPrefix,AcceptReject.AcceptRejectWholeString
public abstract class AcceptReject extends java.lang.ObjectA class storing accept or reject criteria.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAcceptReject.AcceptRejectLeafnameAccept/reject for leaf matches.static classAcceptReject.AcceptRejectPrefixAccept/reject for prefix strings.static classAcceptReject.AcceptRejectWholeStringAccept/reject for whole-strings matches.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<java.lang.String>acceptAccepted items (whole-string match).protected java.util.Set<java.lang.String>acceptGlobsAccept glob strings.protected java.util.List<java.util.regex.Pattern>acceptPatternsAccept regexp patterns.protected java.util.List<java.lang.String>acceptPrefixesAccepted items (prefix match), as a sorted list.protected java.util.Set<java.lang.String>acceptPrefixesSetAccepted items (prefix match), as a set.protected java.util.Set<java.lang.String>rejectRejected items (whole-string match).protected java.util.Set<java.lang.String>rejectGlobsReject glob strings.protected java.util.List<java.util.regex.Pattern>rejectPatternsReject regexp patterns.protected java.util.List<java.lang.String>rejectPrefixesRejected items (prefix match).protected charseparatorCharThe separator character.
-
Constructor Summary
Constructors Constructor Description AcceptReject()Deserialization constructor.AcceptReject(char separatorChar)Constructor for deserialization.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanacceptAndRejectAreEmpty()Check if the accept and reject are empty.abstract booleanacceptHasPrefix(java.lang.String str)Check if a string is a prefix of an accepted string.booleanacceptIsEmpty()Check if the accept is empty.abstract voidaddToAccept(java.lang.String str)Add to the accept.abstract voidaddToReject(java.lang.String str)Add to the reject.static java.lang.StringclassNameToClassfilePath(java.lang.String className)Convert a class name to a classfile path.static java.util.regex.PatternglobToPattern(java.lang.String glob, boolean simpleGlob)Convert a spec with a '*' glob character into a regular expression.abstract booleanisAccepted(java.lang.String str)Check if a string is accepted.abstract booleanisAcceptedAndNotRejected(java.lang.String str)Check if a string is accepted and not rejected.abstract booleanisRejected(java.lang.String str)Check if a string is rejected.booleanisSpecificallyAccepted(java.lang.String str)Check if a string is specifically accepted.booleanisSpecificallyAcceptedAndNotRejected(java.lang.String str)Check if a string is specifically accepted and not rejected.private static booleanmatchesPatternList(java.lang.String str, java.util.List<java.util.regex.Pattern> patterns)Check if a string matches one of the patterns in the provided list.static java.lang.StringnormalizePackageOrClassName(java.lang.String packageOrClassName)Remove initial and final '.' characters, if any.static java.lang.StringnormalizePath(java.lang.String path)Remove initial and final '/' characters, if any.static java.lang.StringpackageNameToPath(java.lang.String packageName)Convert a package name to a path.static java.lang.StringpathToPackageName(java.lang.String path)Convert a path to a package name.private static voidquoteList(java.util.Collection<java.lang.String> coll, java.lang.StringBuilder buf)Quote list.booleanrejectIsEmpty()Check if the reject is empty.(package private) voidsortPrefixes()Need to sort prefixes to ensure correct accept/reject evaluation (see Issue #167).java.lang.StringtoString()
-
-
-
Field Detail
-
accept
protected java.util.Set<java.lang.String> accept
Accepted items (whole-string match).
-
reject
protected java.util.Set<java.lang.String> reject
Rejected items (whole-string match).
-
acceptPrefixesSet
protected java.util.Set<java.lang.String> acceptPrefixesSet
Accepted items (prefix match), as a set.
-
acceptPrefixes
protected java.util.List<java.lang.String> acceptPrefixes
Accepted items (prefix match), as a sorted list.
-
rejectPrefixes
protected java.util.List<java.lang.String> rejectPrefixes
Rejected items (prefix match).
-
acceptGlobs
protected java.util.Set<java.lang.String> acceptGlobs
Accept glob strings. (Serialized to JSON, for logging purposes.)
-
rejectGlobs
protected java.util.Set<java.lang.String> rejectGlobs
Reject glob strings. (Serialized to JSON, for logging purposes.)
-
acceptPatterns
protected transient java.util.List<java.util.regex.Pattern> acceptPatterns
Accept regexp patterns. (Not serialized to JSON.)
-
rejectPatterns
protected transient java.util.List<java.util.regex.Pattern> rejectPatterns
Reject regexp patterns. (Not serialized to JSON.)
-
separatorChar
protected char separatorChar
The separator character.
-
-
Method Detail
-
addToAccept
public abstract void addToAccept(java.lang.String str)
Add to the accept.- Parameters:
str- The string to accept.
-
addToReject
public abstract void addToReject(java.lang.String str)
Add to the reject.- Parameters:
str- The string to reject.
-
isAcceptedAndNotRejected
public abstract boolean isAcceptedAndNotRejected(java.lang.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(java.lang.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(java.lang.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(java.lang.String str)
Check if a string is rejected.- Parameters:
str- The string to test.- Returns:
- true if the string is rejected.
-
normalizePath
public static java.lang.String normalizePath(java.lang.String path)
Remove initial and final '/' characters, if any.- Parameters:
path- The path to normalize.- Returns:
- The normalized path.
-
normalizePackageOrClassName
public static java.lang.String normalizePackageOrClassName(java.lang.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 java.lang.String pathToPackageName(java.lang.String path)
Convert a path to a package name.- Parameters:
path- The path.- Returns:
- The package name.
-
packageNameToPath
public static java.lang.String packageNameToPath(java.lang.String packageName)
Convert a package name to a path.- Parameters:
packageName- The package name.- Returns:
- The path.
-
classNameToClassfilePath
public static java.lang.String classNameToClassfilePath(java.lang.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 java.util.regex.Pattern globToPattern(java.lang.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(java.lang.String str, java.util.List<java.util.regex.Pattern> patterns)Check if a string matches one of the patterns in the provided list.- Parameters:
str- the string to testpatterns- 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(java.lang.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(java.lang.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(java.util.Collection<java.lang.String> coll, java.lang.StringBuilder buf)Quote list.- Parameters:
coll- the collbuf- the buf
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-