Class Recognizer
- java.lang.Object
-
- org.glassfish.pfl.basic.tools.file.Recognizer
-
- All Implemented Interfaces:
java.util.function.Predicate<FileWrapper>,UnaryPredicate<FileWrapper>,Scanner.Action
public class Recognizer extends java.lang.Object implements Scanner.Action
Recognizes files according to patterns, and performs actions accordingly.
-
-
Field Summary
Fields Modifier and Type Field Description private Scanner.ActiondefaultActionprivate booleandryRunprivate java.util.Map<java.lang.String,Scanner.Action>nameActionsprivate Scanner.ActionshellScriptActionprivate java.util.Map<java.lang.String,Scanner.Action>suffixActionsprivate intverbose
-
Constructor Summary
Constructors Constructor Description Recognizer(int verbose, boolean dryRun)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddKnownName(java.lang.String name, Scanner.Action action)voidaddKnownSuffix(java.lang.String suffix, Scanner.Action action)voiddump()booleanevaluate(FileWrapper file)Apply the action that matches the classification of this file.voidsetDefaultAction(Scanner.Action action)This defines the default action.voidsetShellScriptAction(Scanner.Action action)If set, this defines the action taken for text files that start with the patter "#!", which is the standard for all *nix shell scripts.java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.glassfish.pfl.basic.func.UnaryPredicate
test
-
-
-
-
Field Detail
-
verbose
private final int verbose
-
dryRun
private final boolean dryRun
-
nameActions
private final java.util.Map<java.lang.String,Scanner.Action> nameActions
-
suffixActions
private final java.util.Map<java.lang.String,Scanner.Action> suffixActions
-
shellScriptAction
private Scanner.Action shellScriptAction
-
defaultAction
private Scanner.Action defaultAction
-
-
Method Detail
-
dump
public void dump()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
addKnownName
public void addKnownName(java.lang.String name, Scanner.Action action)
-
addKnownSuffix
public void addKnownSuffix(java.lang.String suffix, Scanner.Action action)
-
setShellScriptAction
public void setShellScriptAction(Scanner.Action action)
If set, this defines the action taken for text files that start with the patter "#!", which is the standard for all *nix shell scripts. If not set, such files are handled by the default action (if not otherwise handled by name or suffix match.- Parameters:
action- The action to perform on shell scripts.
-
setDefaultAction
public void setDefaultAction(Scanner.Action action)
This defines the default action. The standard default action prints a message identifying the File that was not processed, and returns false. This allows overriding the default action.- Parameters:
action- The default action is nothing else matches.
-
evaluate
public boolean evaluate(FileWrapper file)
Apply the action that matches the classification of this file. Returns the result of that action.- Specified by:
evaluatein interfaceUnaryPredicate<FileWrapper>- Parameters:
file- The file to act upon.- Returns:
- result of matching action.
-
-