public class RenameWand extends Object
Modifier and Type | Field and Description |
---|---|
private static boolean |
automaticRename
parameter: automatically rename files/directories without prompting (default = false)
|
(package private) static File |
currentDirectory
current directory (absolute and canonical pathname)
|
(package private) static String |
currentDirectoryFullPathname
full pathname of the current directory (includes trailing separator)
|
(package private) static int |
currentDirectoryFullPathnameLength
length of the full pathname of the current directory
|
private static char |
defaultActionOnRenameOperationError
parameter: default action on rename operation error (default = '\0')
|
private static boolean |
ignoreWarnings
parameter: ignore warnings; do not pause (default = false)
|
private static char |
INTEGER_FILTER_INDICATOR_CHAR
constant: integer filter indicator character
|
private static boolean |
isWindowsOperatingSystem
true if this is a Windows OS, false otherwise
|
private static boolean |
matchLowerCase
parameter: match lower case name of the files/directories (default = false)
|
private static boolean |
matchRelativePathname
parameter: match relative pathname, not just the name, of the files/directories (default = false)
|
private static int |
numCaptureGroups
number of capture groups in source regex pattern
|
private static int |
numDirs
subdirectory counter
|
private static Pattern |
NUMERIC_PATTERN
constant: regex pattern for a numeric pattern, e.g. -123.45
Match groups: (1,"+" or "-"), (2,"123.45")
|
private static Map<String,Integer> |
OPERATOR_PRECEDENCE
operator precedence table for stack evaluation
|
private static String |
PLURAL_NOUN
plural noun for files/directories
|
private static Pattern |
POSITIVE_INTEGER_PATTERN
constant: regex pattern for a positive integer pattern, e.g. 42
|
private static String |
PROGRAM_TITLE
constant: program title
|
private static boolean |
recurseIntoSubdirectories
parameter: recurse into subdirectories (default = false)
|
private static Pattern |
REGISTER_NAME_PATTERN
constant: regex pattern for register names
|
(package private) static Map<String,Integer> |
registerNames
register names mapping (register name ---> capture group index)
|
private static boolean |
renameDirectories
parameter: true if renaming directories; false if renaming files (default = false)
|
private static int |
reportNumWarnings
statistic: number of warnings encountered
|
private static boolean |
simulateOnly
parameter: simulate only; do not actually rename files/directories (default = false)
|
private static String |
SINGULAR_NOUN
singular noun for file/directory
|
private static Pattern |
SOURCE_SPECIAL_CONSTRUCT_PATTERN
constant: regex pattern for special construct "
|
private static boolean |
sourcePatternIsReusable
true if the source pattern string is reusable for different files/directories; false otherwise
|
private static String |
sourcePatternString
parameter: source pattern string
|
private static char |
SPECIAL_CONSTRUCT_SEPARATOR_CHAR
constant: special construct separator character
|
(package private) static PrintWriter |
stderr
standard error
|
(package private) static PrintWriter |
stdout
standard output
|
private static char |
SUBSTRING_DELIMITER_CHAR
constant: substring delimiter character
|
private static char |
SUBSTRING_RANGE_CHAR
constant: substring range character
|
private static Pattern |
TARGET_SPECIAL_CONSTRUCT_PATTERN
constant: regex pattern for special construct "
|
private static String |
targetPatternString
parameter: target pattern string
|
Constructor and Description |
---|
RenameWand() |
Modifier and Type | Method and Description |
---|---|
private static EvaluationResult<String> |
evaluateSpecialConstruct(FileUnit[] files,
String specialConstruct)
Evaluate the given special construct for the given files/directories, and
return the results.
|
private static EvaluationResult<Void> |
evaluateStep(FileUnit[] files,
Deque<String> operators,
Deque<String[]> operands)
Evaluate a single step, given the operators and operands stacks, for the
given files/directories.
|
private static void |
evaluateTargetPattern(FileUnit[] matchedFiles)
Evaluate the target pattern for the given matched files/directories,
and store the results in the respective FileUnit's.
|
private static String |
getExceptionInformation(Exception e)
Get custom exception information string for the given exception.
|
private static Pattern |
getFileSourcePattern(FileUnit u)
Generate source regex pattern corresponding to the given file/directory.
|
private static List<FileUnit> |
getMatchCandidates()
Scan current directory to get candidate files/directories for matching.
|
private static int |
getNonNumericIndex(String[] args)
Return -1 if all the strings in the given array are numeric;
otherwise, return the index of a non-numeric string.
|
private static List<RenameFilePair> |
getRenameOperations(List<FileUnit> matchedFiles)
Determine sequence of rename operations to be performed, in order to rename
the given matched files/directories.
|
private static boolean |
isNumeric(String arg)
Return true if the given string is numeric; false otherwise.
|
static void |
main(String[] args)
Main entry point for the RenameWand program.
|
private static String |
padString(String in,
int len,
boolean isNumeric)
Pad the given string so that it is at least the specified number of
character long.
|
private static int |
performRenameOperations(List<RenameFilePair> renameOperations)
Perform rename operations on files/directories.
|
private static List<FileUnit> |
performSourcePatternMatching(List<FileUnit> matchCandidates)
Perform source pattern matching against the names of the candidate
files/directories, and return files/directories that match.
|
private static void |
printUsage()
Print out usage syntax, notes, and comments.
|
private static void |
processArguments(String[] args)
Process command-line arguments.
|
private static boolean |
promptUserOnRename(List<FileUnit> matchedFiles,
int numRenameOperations)
Print the matched files/directories and their target names, and
prompt the user on whether to proceed with the renaming operations.
|
private static void |
reportWarning(Object message)
Print a warning message and pause.
|
private static final String PROGRAM_TITLE
private static final char SPECIAL_CONSTRUCT_SEPARATOR_CHAR
private static final char SUBSTRING_RANGE_CHAR
private static final char SUBSTRING_DELIMITER_CHAR
private static final char INTEGER_FILTER_INDICATOR_CHAR
private static final Pattern REGISTER_NAME_PATTERN
private static final Pattern SOURCE_SPECIAL_CONSTRUCT_PATTERN
private static final Pattern TARGET_SPECIAL_CONSTRUCT_PATTERN
private static final Pattern NUMERIC_PATTERN
private static final Pattern POSITIVE_INTEGER_PATTERN
private static final Map<String,Integer> OPERATOR_PRECEDENCE
private static String SINGULAR_NOUN
private static String PLURAL_NOUN
static PrintWriter stdout
static PrintWriter stderr
private static boolean isWindowsOperatingSystem
static File currentDirectory
static String currentDirectoryFullPathname
static int currentDirectoryFullPathnameLength
static final Map<String,Integer> registerNames
private static int numCaptureGroups
private static boolean sourcePatternIsReusable
private static int numDirs
private static boolean simulateOnly
private static boolean ignoreWarnings
private static boolean recurseIntoSubdirectories
private static boolean automaticRename
private static boolean matchRelativePathname
private static boolean matchLowerCase
private static boolean renameDirectories
private static char defaultActionOnRenameOperationError
private static String sourcePatternString
private static String targetPatternString
private static int reportNumWarnings
public RenameWand()
public static void main(String[] args)
args
- Command-line argument stringsprivate static void processArguments(String[] args)
args
- Command-line argument stringsprivate static List<FileUnit> getMatchCandidates()
private static List<FileUnit> performSourcePatternMatching(List<FileUnit> matchCandidates)
matchCandidates
- Candidate files/directoriesprivate static Pattern getFileSourcePattern(FileUnit u)
u
- File/directory for which to generate source regex patternprivate static void evaluateTargetPattern(FileUnit[] matchedFiles)
matchedFiles
- Matched files/directories for which to evaluate the target patternprivate static EvaluationResult<String> evaluateSpecialConstruct(FileUnit[] files, String specialConstruct)
file
- Files/directories for which to evaluate the given special constructspecialConstruct
- Special construct stringprivate static EvaluationResult<Void> evaluateStep(FileUnit[] files, Deque<String> operators, Deque<String[]> operands)
files
- Files/directories for which to evaluate the single stepoperators
- Operators stackoperands
- Operands stackprivate static List<RenameFilePair> getRenameOperations(List<FileUnit> matchedFiles)
matchedFiles
- Matched files/directories to be renamedprivate static boolean promptUserOnRename(List<FileUnit> matchedFiles, int numRenameOperations)
matchedFiles
- Matched files to be renamednumRenameOperations
- Number of rename operations to be performedprivate static int performRenameOperations(List<RenameFilePair> renameOperations)
renameOperations
- Sequence of rename operations to be performedprivate static String padString(String in, int len, boolean isNumeric)
in
- String to be paddedlen
- Desired length of padded stringisNumeric
- Indicates if given string is to be treated as numericprivate static boolean isNumeric(String arg)
arg
- String to be testedprivate static int getNonNumericIndex(String[] args)
arg
- Strings to be testedprivate static void reportWarning(Object message)
message
- Warning message to be printed on issuing the warningprivate static String getExceptionInformation(Exception e)
e
- Exception for which to generate the custom exception information stringprivate static void printUsage()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses