Class WhiteBlackList
- java.lang.Object
-
- io.github.fastclasspathscanner.utils.WhiteBlackList
-
- Direct Known Subclasses:
WhiteBlackList.WhiteBlackListPrefix
,WhiteBlackList.WhiteBlackListWholeString
public abstract class WhiteBlackList extends Object
A class storing whitelist or blacklist criteria.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WhiteBlackList.WhiteBlackListLeafname
Whitelist/blacklist for prefix strings.static class
WhiteBlackList.WhiteBlackListPrefix
Whitelist/blacklist for prefix strings.static class
WhiteBlackList.WhiteBlackListWholeString
Whitelist/blacklist for whole-strings matches.
-
Field Summary
Fields Modifier and Type Field Description protected Set<String>
blacklist
Blacklisted items (whole-string match)protected Set<String>
blacklistGlobs
Blacklist glob strings.protected List<Pattern>
blacklistPatterns
Blacklist regexp patterns.protected List<String>
blacklistPrefixes
Blacklisted items (prefix match)protected Set<String>
whitelist
Whitelisted items (whole-string match)protected Set<String>
whitelistGlobs
Whitelist glob strings.protected List<Pattern>
whitelistPatterns
Whitelist regexp patterns.protected List<String>
whitelistPrefixes
Whitelisted items (prefix match)
-
Constructor Summary
Constructors Constructor Description WhiteBlackList()
Constructor for deserialization.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
addToBlacklist(String str)
Add to the blacklist.abstract void
addToWhitelist(String str)
Add to the whitelist.static String
classNameToClassfilePath(String className)
Convert a class name to a classfile path.static Pattern
globToPattern(String glob)
Convert a spec with a '*' glob character into a regular expression.abstract boolean
isBlacklisted(String str)
Check if the requested string is blacklisted.boolean
isSpecificallyWhitelisted(String str)
Check if the requested string is specifically whitelisted, i.e.boolean
isSpecificallyWhitelistedAndNotBlacklisted(String str)
Check if the requested string is specifically whitelisted and not blacklisted, i.e.abstract boolean
isWhitelisted(String str)
Check if the requested string is whitelisted.abstract boolean
isWhitelistedAndNotBlacklisted(String str)
Check if the requested string is whitelisted and not blacklisted.static String
normalizePackageOrClassName(String packageOrClassName)
Remove initial and final '.' characters, if any.static String
normalizePath(String path)
Remove initial and final '/' characters, if any.static String
packageNameToPath(String packageName)
Convert a package name to a path.static String
pathToPackageName(String path)
Convert a path to a package name.void
sortPrefixes()
Need to sort prefixes to ensure correct whitelist/blacklist evaluation (see Issue #167).String
toString()
abstract boolean
whitelistHasPrefix(String str)
Check if the requested string is a prefix of a whitelisted string.boolean
whitelistIsEmpty()
Returns true if there were no whitelist criteria added.
-
-
-
Field Detail
-
whitelistGlobs
protected Set<String> whitelistGlobs
Whitelist glob strings. (Serialized to JSON, for logging purposes.)
-
blacklistGlobs
protected Set<String> blacklistGlobs
Blacklist glob strings. (Serialized to JSON, for logging purposes.)
-
whitelistPatterns
protected transient List<Pattern> whitelistPatterns
Whitelist regexp patterns. (Not serialized to JSON.)
-
-
Method Detail
-
addToWhitelist
public abstract void addToWhitelist(String str)
Add to the whitelist.
-
addToBlacklist
public abstract void addToBlacklist(String str)
Add to the blacklist.
-
isWhitelistedAndNotBlacklisted
public abstract boolean isWhitelistedAndNotBlacklisted(String str)
Check if the requested string is whitelisted and not blacklisted.
-
isWhitelisted
public abstract boolean isWhitelisted(String str)
Check if the requested string is whitelisted.
-
whitelistHasPrefix
public abstract boolean whitelistHasPrefix(String str)
Check if the requested string is a prefix of a whitelisted string.
-
isBlacklisted
public abstract boolean isBlacklisted(String str)
Check if the requested string is blacklisted.
-
normalizePath
public static String normalizePath(String path)
Remove initial and final '/' characters, if any.
-
normalizePackageOrClassName
public static String normalizePackageOrClassName(String packageOrClassName)
Remove initial and final '.' characters, if any.
-
pathToPackageName
public static String pathToPackageName(String path)
Convert a path to a package name.
-
packageNameToPath
public static String packageNameToPath(String packageName)
Convert a package name to a path.
-
classNameToClassfilePath
public static String classNameToClassfilePath(String className)
Convert a class name to a classfile path.
-
globToPattern
public static Pattern globToPattern(String glob)
Convert a spec with a '*' glob character into a regular expression. Replaces "." with "\." and "*" with ".*", then compiles a regular expression.
-
whitelistIsEmpty
public boolean whitelistIsEmpty()
Returns true if there were no whitelist criteria added.
-
isSpecificallyWhitelistedAndNotBlacklisted
public boolean isSpecificallyWhitelistedAndNotBlacklisted(String str)
Check if the requested string is specifically whitelisted and not blacklisted, i.e. will not return true if the whitelist is empty.
-
isSpecificallyWhitelisted
public boolean isSpecificallyWhitelisted(String str)
Check if the requested string is specifically whitelisted, i.e. will not return true if the whitelist is empty.
-
sortPrefixes
public void sortPrefixes()
Need to sort prefixes to ensure correct whitelist/blacklist evaluation (see Issue #167).
-
-