- java.lang.Object
-
- Apache.CLI.PatternOptionBuilder
-
public class PatternOptionBuilder extends java.lang.Object
This Class-File has been copied, directly from the Apache Commons Software Foundation. Other than the minor, cosmetic changes (mentioned in the second-list below), this file is perfectly identical to the original that may be found on the Apache Website:apache.org
.- The suggested license for using this file may be read here:
Apache License
- The Source-Code Header for this file may be viewed here:
Source-File Header
- Partial contents of the
'site/resources/images'
directory:Resource Images
Notes about changes that have been made as a result of the import process:- Within all files, the original Package-Name declaration has been changed:
Original: package org.apache.commons.cli;
Updated: package Apache.CLI;
- All Classes and Class-Members (Methods, Fields, etc...) that were previously Annotated
with the
@Deprecated
Annotation have been summarily removed.
- Code Formattings and Styling has been heavily modified to conform to the Standard Java-HTML
Indentation & Styling Choices. The code itself remains identical, with only a few
squiggly-braces
'{' and '}'
being removed, for cosmetic reasons (and for lowering "Developer Stress" Levels)..
Allows Options to be created from a single String. The pattern contains various single character flags and via an optional punctuation character, their expected type.
Here is an Overview of PatternOptionBuilder patternsa -a flag b@ -b [class name] c> -c [file name] d+ -d [class name] (creates object via empty constructor) e% -e [number] (creates Double/Long instance depending on existing of a '.') f/ -f [URL] g: -g [string]
For example, the following allows command line flags of'-v -p string-value -f /dir/file'
.
The exclamation mark precede a mandatory option.
Options options = PatternOptionBuilder.parsePattern("vp:!f/");
Apache Commons To-Do:
TO-DO These need to break out toOptionType
and also to be pluggable.
Hi-Lited Source-Code:- View Here: Apache/CLI/PatternOptionBuilder.java
- Open New Browser-Tab: Apache/CLI/PatternOptionBuilder.java
File Size: 6,293 Bytes Line Count: 201 '\n' Characters Found
- The suggested license for using this file may be read here:
-
-
Field Summary
Fields Modifier and Type Field Description static Class<?>
CLASS_VALUE
Class classstatic Class<Date>
DATE_VALUE
Date classstatic Class<FileInputStream>
EXISTING_FILE_VALUE
FileInputStream classstatic Class<File>
FILE_VALUE
File classstatic Class<File[]>
FILES_VALUE
File array classstatic Class<Number>
NUMBER_VALUE
Number classstatic Class<Object>
OBJECT_VALUE
Object classstatic Class<String>
STRING_VALUE
String classstatic Class<URL>
URL_VALUE
URL class
-
Constructor Summary
Constructors Constructor Description PatternOptionBuilder()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Object
getValueClass(char ch)
Retrieve the class thatch
represents.static boolean
isValueCode(char ch)
Returns whetherch
is a value code, i.e.static Options
parsePattern(String pattern)
Returns theOptions
instance represented bypattern
.
-
-
-
Field Detail
-
STRING_VALUE
public static final java.lang.Class<java.lang.String> STRING_VALUE
String class
-
OBJECT_VALUE
public static final java.lang.Class<java.lang.Object> OBJECT_VALUE
Object class
-
NUMBER_VALUE
public static final java.lang.Class<java.lang.Number> NUMBER_VALUE
Number class
-
DATE_VALUE
public static final java.lang.Class<java.util.Date> DATE_VALUE
Date class
-
CLASS_VALUE
public static final java.lang.Class<?> CLASS_VALUE
Class class
-
EXISTING_FILE_VALUE
public static final java.lang.Class<java.io.FileInputStream> EXISTING_FILE_VALUE
FileInputStream class
-
FILE_VALUE
public static final java.lang.Class<java.io.File> FILE_VALUE
File class
-
FILES_VALUE
public static final java.lang.Class<java.io.File[]> FILES_VALUE
File array class
-
URL_VALUE
public static final java.lang.Class<java.net.URL> URL_VALUE
URL class
-
-
Constructor Detail
-
PatternOptionBuilder
public PatternOptionBuilder()
-
-
Method Detail
-
getValueClass
public static java.lang.Object getValueClass(char ch)
Retrieve the class thatch
represents.- Parameters:
ch
- the specified character- Returns:
- The class that
ch
represents - Code:
- Exact Method Body:
switch (ch) { case '@': return PatternOptionBuilder.OBJECT_VALUE; case ':': return PatternOptionBuilder.STRING_VALUE; case '%': return PatternOptionBuilder.NUMBER_VALUE; case '+': return PatternOptionBuilder.CLASS_VALUE; case '#': return PatternOptionBuilder.DATE_VALUE; case '<': return PatternOptionBuilder.EXISTING_FILE_VALUE; case '>': return PatternOptionBuilder.FILE_VALUE; case '*': return PatternOptionBuilder.FILES_VALUE; case '/': return PatternOptionBuilder.URL_VALUE; } return null;
-
isValueCode
public static boolean isValueCode(char ch)
Returns whetherch
is a value code, i.e. whether it represents a class in a pattern.- Parameters:
ch
- the specified character- Returns:
- true if
ch
is a value code, otherwise false. - Code:
- Exact Method Body:
return ch == '@' || ch == ':' || ch == '%' || ch == '+' || ch == '#' || ch == '<' || ch == '>' || ch == '*' || ch == '/' || ch == '!';
-
parsePattern
public static Options parsePattern(java.lang.String pattern)
Returns theOptions
instance represented bypattern
.- Parameters:
pattern
- the pattern string- Returns:
- The
Options
instance - Code:
- Exact Method Body:
char opt = ' '; boolean required = false; Class<?> type = null; final Options options = new Options(); for (int i = 0; i < pattern.length(); i++) { final char ch = pattern.charAt(i); // a value code comes after an option and specifies // details about it if (!isValueCode(ch)) { if (opt != ' ') { final Option option = Option .builder(String.valueOf(opt)) .hasArg(type != null) .required(required) .type(type) .build(); // we have a previous one to deal with options.addOption(option); required = false; type = null; } opt = ch; } else if (ch == '!') required = true; else type = (Class<?>) getValueClass(ch); } if (opt != ' ') { final Option option = Option .builder(String.valueOf(opt)) .hasArg(type != null) .required(required) .type(type) .build(); // we have a final one to deal with options.addOption(option); } return options;
-
-