http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/OptionParser.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/OptionParser.java b/geode-joptsimple/src/main/java/joptsimple/OptionParser.java deleted file mode 100644 index 24165b8..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/OptionParser.java +++ /dev/null @@ -1,568 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; - -import joptsimple.internal.AbbreviationMap; -import joptsimple.util.KeyValuePair; - -import static java.util.Collections.*; - -import static joptsimple.OptionException.*; -import static joptsimple.OptionParserState.*; -import static joptsimple.ParserRules.*; - - - -/** - * <p>Parses command line arguments, using a syntax that attempts to take from the best of POSIX {@code getopt()} - * and GNU {@code getopt_long()}.</p> - * - * <p>This parser supports short options and long options.</p> - * - * <ul> - * <li><dfn>Short options</dfn> begin with a single hyphen ("<kbd>-</kbd>") followed by a single letter or digit, - * or question mark ("<kbd>?</kbd>"), or dot ("<kbd>.</kbd>").</li> - * - * <li>Short options can accept single arguments. The argument can be made required or optional. The option's - * argument can occur: - * <ul> - * <li>in the slot after the option, as in <kbd>-d /tmp</kbd></li> - * <li>right up against the option, as in <kbd>-d/tmp</kbd></li> - * <li>right up against the option separated by an equals sign (<kbd>"="</kbd>), as in <kbd>-d=/tmp</kbd></li> - * </ul> - * To specify <em>n</em> arguments for an option, specify the option <em>n</em> times, once for each argument, - * as in <kbd>-d /tmp -d /var -d /opt</kbd>; or, when using the - * {@linkplain ArgumentAcceptingOptionSpec#withValuesSeparatedBy(char) "separated values"} clause of the "fluent - * interface" (see below), give multiple values separated by a given character as a single argument to the - * option.</li> - * - * <li>Short options can be clustered, so that <kbd>-abc</kbd> is treated as <kbd>-a -b -c</kbd>. If a short option - * in the cluster can accept an argument, the remaining characters are interpreted as the argument for that - * option.</li> - * - * <li>An argument consisting only of two hyphens (<kbd>"--"</kbd>) signals that the remaining arguments are to be - * treated as non-options.</li> - * - * <li>An argument consisting only of a single hyphen is considered a non-option argument (though it can be an - * argument of an option). Many Unix programs treat single hyphens as stand-ins for the standard input or standard - * output streams.</li> - * - * <li><dfn>Long options</dfn> begin with two hyphens (<kbd>"--"</kbd>), followed by multiple letters, digits, - * hyphens, question marks, or dots. A hyphen cannot be the first character of a long option specification when - * configuring the parser.</li> - * - * <li>You can abbreviate long options, so long as the abbreviation is unique.</li> - * - * <li>Long options can accept single arguments. The argument can be made required or optional. The option's - * argument can occur: - * <ul> - * <li>in the slot after the option, as in <kbd>--directory /tmp</kbd></li> - * <li>right up against the option separated by an equals sign (<kbd>"="</kbd>), as in - * <kbd>--directory=/tmp</kbd> - * </ul> - * Specify multiple arguments for a long option in the same manner as for short options (see above).</li> - * - * <li>You can use a single hyphen (<kbd>"-"</kbd>) instead of a double hyphen (<kbd>"--"</kbd>) for a long - * option.</li> - * - * <li>The option <kbd>-W</kbd> is reserved. If you tell the parser to {@linkplain - * #recognizeAlternativeLongOptions(boolean) recognize alternative long options}, then it will treat, for example, - * <kbd>-W foo=bar</kbd> as the long option <kbd>foo</kbd> with argument <kbd>bar</kbd>, as though you had written - * <kbd>--foo=bar</kbd>.</li> - * - * <li>You can specify <kbd>-W</kbd> as a valid short option, or use it as an abbreviation for a long option, but - * {@linkplain #recognizeAlternativeLongOptions(boolean) recognizing alternative long options} will always supersede - * this behavior.</li> - * - * <li>You can specify a given short or long option multiple times on a single command line. The parser collects - * any arguments specified for those options as a list.</li> - * - * <li>If the parser detects an option whose argument is optional, and the next argument "looks like" an option, - * that argument is not treated as the argument to the option, but as a potentially valid option. If, on the other - * hand, the optional argument is typed as a derivative of {@link Number}, then that argument is treated as the - * negative number argument of the option, even if the parser recognizes the corresponding numeric option. - * For example: - * <pre><code> - * OptionParser parser = new OptionParser(); - * parser.accepts( "a" ).withOptionalArg().ofType( Integer.class ); - * parser.accepts( "2" ); - * OptionSet options = parser.parse( "-a", "-2" ); - * </code></pre> - * In this case, the option set contains <kbd>"a"</kbd> with argument <kbd>-2</kbd>, not both <kbd>"a"</kbd> and - * <kbd>"2"</kbd>. Swapping the elements in the <em>args</em> array gives the latter.</li> - * </ul> - * - * <p>There are two ways to tell the parser what options to recognize:</p> - * - * <ol> - * <li>A "fluent interface"-style API for specifying options, available since version 2. Sentences in this fluent - * interface language begin with a call to {@link #accepts(String) accepts} or {@link #acceptsAll(Collection) - * acceptsAll} methods; calls on the ensuing chain of objects describe whether the options can take an argument, - * whether the argument is required or optional, to what type arguments of the options should be converted if any, - * etc. Since version 3, these calls return an instance of {@link OptionSpec}, which can subsequently be used to - * retrieve the arguments of the associated option in a type-safe manner.</li> - * - * <li>Since version 1, a more concise way of specifying short options has been to use the special {@linkplain - * #OptionParser(String) constructor}. Arguments of options specified in this manner will be of type {@link String}. - * Here are the rules for the format of the specification strings this constructor accepts: - * - * <ul> - * <li>Any letter or digit is treated as an option character.</li> - * - * <li>An option character can be immediately followed by an asterisk (*) to indicate that the option is a - * "help" option.</li> - * - * <li>If an option character (with possible trailing asterisk) is followed by a single colon (<kbd>":"</kbd>), - * then the option requires an argument.</li> - * - * <li>If an option character (with possible trailing asterisk) is followed by two colons (<kbd>"::"</kbd>), - * then the option accepts an optional argument.</li> - * - * <li>Otherwise, the option character accepts no argument.</li> - * - * <li>If the option specification string begins with a plus sign (<kbd>"+"</kbd>), the parser will behave - * "POSIX-ly correct".</li> - * - * <li>If the option specification string contains the sequence <kbd>"W;"</kbd> (capital W followed by a - * semicolon), the parser will recognize the alternative form of long options.</li> - * </ul> - * </li> - * </ol> - * - * <p>Each of the options in a list of options given to {@link #acceptsAll(Collection) acceptsAll} is treated as a - * synonym of the others. For example: - * <pre> - * <code> - * OptionParser parser = new OptionParser(); - * parser.acceptsAll( asList( "w", "interactive", "confirmation" ) ); - * OptionSet options = parser.parse( "-w" ); - * </code> - * </pre> - * In this case, <code>options.{@link OptionSet#has(String) has}</code> would answer {@code true} when given arguments - * <kbd>"w"</kbd>, <kbd>"interactive"</kbd>, and <kbd>"confirmation"</kbd>. The {@link OptionSet} would give the same - * responses to these arguments for its other methods as well.</p> - * - * <p>By default, as with GNU {@code getopt()}, the parser allows intermixing of options and non-options. If, however, - * the parser has been created to be "POSIX-ly correct", then the first argument that does not look lexically like an - * option, and is not a required argument of a preceding option, signals the end of options. You can still bind - * optional arguments to their options using the abutting (for short options) or <kbd>=</kbd> syntax.</p> - * - * <p>Unlike GNU {@code getopt()}, this parser does not honor the environment variable {@code POSIXLY_CORRECT}. - * "POSIX-ly correct" parsers are configured by either:</p> - * - * <ol> - * <li>using the method {@link #posixlyCorrect(boolean)}, or</li> - * - * <li>using the {@linkplain #OptionParser(String) constructor} with an argument whose first character is a plus sign - * (<kbd>"+"</kbd>)</li> - * </ol> - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - * @author Nikhil Jadhav - * @see <a href="http://www.gnu.org/software/libc/manual">The GNU C Library</a> - */ -public class OptionParser { - - // GemFire Addition: to disable short option support - private boolean isShortOptionDisabled = false; - - private final AbbreviationMap<AbstractOptionSpec<?>> recognizedOptions; - private OptionParserState state; - private boolean posixlyCorrect; - private HelpFormatter helpFormatter = new BuiltinHelpFormatter(); - - /** - * Creates an option parser that initially recognizes no options, and does not exhibit "POSIX-ly correct" - * behavior. - */ - public OptionParser() { - recognizedOptions = new AbbreviationMap<AbstractOptionSpec<?>>(); - state = moreOptions( false ); - } - - /** - * Creates an option parser and configures it to recognize the short options specified in the given string. - * - * Arguments of options specified this way will be of type {@link String}. - * - * @param optionSpecification an option specification - * @throws NullPointerException if {@code optionSpecification} is {@code null} - * @throws OptionException if the option specification contains illegal characters or otherwise cannot be - * recognized - */ - public OptionParser( String optionSpecification ) { - this(); - - new OptionSpecTokenizer( optionSpecification ).configure( this ); - } - - /** - * Creates an option parser that initially recognizes no options, and does not exhibit "POSIX-ly correct" - * behavior. - * - * Short options can be enabled with setting disableShortOption to <code>false</code>. - * - * @param disableShortOption <code>true</code> to disable short options, <code>false</code> to enable - */ - public OptionParser( boolean disableShortOption ) { - this(); - this.isShortOptionDisabled = disableShortOption; - } - - /** - * Creates an option parser and configures it to recognize the short options specified in the given string. - * - * Arguments of options specified this way will be of type {@link String}. - * - * Short options can be enabled with setting disableShortOption to <code>false</code>. - * - * @param optionSpecification an option specification - * @param disableShortOption <code>true</code> to disable short options, <code>false</code> to enable those. - * @throws NullPointerException if {@code optionSpecification} is {@code null} - * @throws OptionException if the option specification contains illegal characters or otherwise cannot be - * recognized - */ - public OptionParser( String optionSpecification, boolean disableShortOption ) { - this(); - - new OptionSpecTokenizer( optionSpecification ).configure( this ); - this.isShortOptionDisabled = disableShortOption; - } - - /** - * <p>Tells the parser to recognize the given option.</p> - * - * <p>This method returns an instance of {@link OptionSpecBuilder} to allow the formation of parser directives - * as sentences in a fluent interface language. For example:</p> - * - * <pre><code> - * OptionParser parser = new OptionParser(); - * parser.<strong>accepts( "c" )</strong>.withRequiredArg().ofType( Integer.class ); - * </code></pre> - * - * <p>If no methods are invoked on the returned {@link OptionSpecBuilder}, then the parser treats the option as - * accepting no argument.</p> - * - * @param option the option to recognize - * @return an object that can be used to flesh out more detail about the option - * @throws OptionException if the option contains illegal characters - * @throws NullPointerException if the option is {@code null} - */ - public OptionSpecBuilder accepts( String option ) { - return acceptsAll( singletonList( option ) ); - } - - /** - * Tells the parser to recognize the given option. - * - * @see #accepts(String) - * @param option the option to recognize - * @param description a string that describes the purpose of the option. This is used when generating help - * information about the parser. - * @return an object that can be used to flesh out more detail about the option - * @throws OptionException if the option contains illegal characters - * @throws NullPointerException if the option is {@code null} - */ - public OptionSpecBuilder accepts( String option, String description ) { - return acceptsAll( singletonList( option ), description ); - } - - /** - * Tells the parser to recognize the given options, and treat them as synonymous. - * - * @see #accepts(String) - * @param options the options to recognize and treat as synonymous - * @return an object that can be used to flesh out more detail about the options - * @throws OptionException if any of the options contain illegal characters - * @throws NullPointerException if the option list or any of its elements are {@code null} - */ - public OptionSpecBuilder acceptsAll( Collection<String> options ) { - return acceptsAll( options, "" ); - } - - /** - * Tells the parser to recognize the given options, and treat them as synonymous. - * - * @see #acceptsAll(Collection) - * @param options the options to recognize and treat as synonymous - * @param description a string that describes the purpose of the option. This is used when generating help - * information about the parser. - * @return an object that can be used to flesh out more detail about the options - * @throws OptionException if any of the options contain illegal characters - * @throws NullPointerException if the option list or any of its elements are {@code null} - * @throws IllegalArgumentException if the option list is empty - */ - public OptionSpecBuilder acceptsAll( Collection<String> options, String description ) { - if ( options.isEmpty() ) - throw new IllegalArgumentException( "need at least one option" ); - - ensureLegalOptions( options ); - - return new OptionSpecBuilder( this, options, description ); - } - - /** - * Tells the parser whether or not to behave "POSIX-ly correct"-ly. - * - * @param setting {@code true} if the parser should behave "POSIX-ly correct"-ly - */ - public void posixlyCorrect( boolean setting ) { - posixlyCorrect = setting; - state = moreOptions( setting ); - } - - boolean posixlyCorrect() { - return posixlyCorrect; - } - - /** - * Tells the parser either to recognize or ignore <kbd>"-W"</kbd>-style long options. - * - * @param recognize {@code true} if the parser is to recognize the special style of long options - */ - public void recognizeAlternativeLongOptions( boolean recognize ) { - if ( recognize ) - recognize( new AlternativeLongOptionSpec() ); - else - recognizedOptions.remove( String.valueOf( RESERVED_FOR_EXTENSIONS ) ); - } - - void recognize( AbstractOptionSpec<?> spec ) { - recognizedOptions.putAll( spec.options(), spec ); - } - - /** - * Writes information about the options this parser recognizes to the given output sink. - * - * The output sink is flushed, but not closed. - * - * @param sink the sink to write information to - * @throws IOException if there is a problem writing to the sink - * @throws NullPointerException if {@code sink} is {@code null} - * @see #printHelpOn(Writer) - */ - public void printHelpOn( OutputStream sink ) throws IOException { - printHelpOn( new OutputStreamWriter( sink ) ); - } - - /** - * Writes information about the options this parser recognizes to the given output sink. - * - * The output sink is flushed, but not closed. - * - * @param sink the sink to write information to - * @throws IOException if there is a problem writing to the sink - * @throws NullPointerException if {@code sink} is {@code null} - * @see #printHelpOn(OutputStream) - */ - public void printHelpOn( Writer sink ) throws IOException { - sink.write( helpFormatter.format( recognizedOptions.toJavaUtilMap() ) ); - sink.flush(); - } - - /** - * Tells the parser to use the given formatter when asked to {@linkplain #printHelpOn(java.io.Writer) print help}. - * - * @param formatter the formatter to use for printing help - * @throws NullPointerException if the formatter is {@code null} - */ - public void formatHelpWith( HelpFormatter formatter ) { - if ( formatter == null ) - throw new NullPointerException(); - - helpFormatter = formatter; - } - - /** - * Parses the given command line arguments according to the option specifications given to the parser. - * - * @param arguments arguments to parse - * @return an {@link OptionSet} describing the parsed options, their arguments, and any non-option arguments found - * @throws OptionException if problems are detected while parsing - * @throws NullPointerException if the argument list is {@code null} - */ - public OptionSet parse( String... arguments ) { - ArgumentList argumentList = new ArgumentList( arguments ); - OptionSet detected = new OptionSet( defaultValues() ); - - while ( argumentList.hasMore() ) - state.handleArgument( this, argumentList, detected ); - - reset(); - - ensureRequiredOptions( detected ); - - return detected; - } - - private void ensureRequiredOptions( OptionSet options ) { - Collection<String> missingRequiredOptions = new HashSet<String>(); - for ( AbstractOptionSpec<?> each : recognizedOptions.toJavaUtilMap().values() ) { - if ( each.isRequired() && !options.has( each ) ) - missingRequiredOptions.addAll( each.options() ); - } - - boolean helpOptionPresent = false; - for ( AbstractOptionSpec<?> each : recognizedOptions.toJavaUtilMap().values() ) { - if ( each.isForHelp() ) { - helpOptionPresent = true; - break; - } - } - - if ( !missingRequiredOptions.isEmpty() && !helpOptionPresent ) - // GemFire Addition : Add options detected so far - throw new MissingRequiredOptionException( missingRequiredOptions, options ); - } - - void handleLongOptionToken( String candidate, ArgumentList arguments, OptionSet detected ) { - KeyValuePair optionAndArgument = parseLongOptionWithArgument( candidate ); - - if ( !isRecognized( optionAndArgument.key ) ) - // GemFire Addition : Add options detected so far - throw createUnrecognizedOptionException( optionAndArgument.key, detected ); - - AbstractOptionSpec<?> optionSpec = specFor( optionAndArgument.key ); - optionSpec.handleOption( this, arguments, detected, optionAndArgument.value ); - } - - void handleShortOptionToken( String candidate, ArgumentList arguments, OptionSet detected ) { - KeyValuePair optionAndArgument = parseShortOptionWithArgument( candidate ); - - if ( isRecognized( optionAndArgument.key ) ) { - specFor( optionAndArgument.key ).handleOption( this, arguments, detected, optionAndArgument.value ); - } - else - handleShortOptionCluster( candidate, arguments, detected ); - } - - private void handleShortOptionCluster( String candidate, ArgumentList arguments, OptionSet detected ) { - char[] options = extractShortOptionsFrom( candidate ); - // GemFire Addition : Add options detected so far - validateOptionCharacters( options, detected ); - - for ( int i = 0; i < options.length; i++ ) { - AbstractOptionSpec<?> optionSpec = specFor( options[ i ] ); - - if ( optionSpec.acceptsArguments() && options.length > i + 1 ) { - String detectedArgument = String.valueOf( options, i + 1, options.length - 1 - i ); - optionSpec.handleOption( this, arguments, detected, detectedArgument ); - break; - } - - optionSpec.handleOption( this, arguments, detected, null ); - } - } - - void noMoreOptions() { - state = OptionParserState.noMoreOptions(); - } - - /* - * GemFire Addition: following comment & changes in method - * This method has be modified to remove short option support - * - * @param argument - * - * @return boolean indicating whether it is an option token - */ - boolean looksLikeAnOption( String argument ) { - // GemFire Addition: Modified to support Gfsh at runtime - return ( !isShortOptionDisabled && isShortOptionToken( argument ) ) || isLongOptionToken( argument ); - } - - // GemFire Addition: to indicate whether short option support is disabled - public boolean isShortOptionDisabled() { - return isShortOptionDisabled; - } - - private boolean isRecognized( String option ) { - return recognizedOptions.contains( option ); - } - - private AbstractOptionSpec<?> specFor( char option ) { - return specFor( String.valueOf( option ) ); - } - - private AbstractOptionSpec<?> specFor( String option ) { - return recognizedOptions.get( option ); - } - - private void reset() { - state = moreOptions( posixlyCorrect ); - } - - private static char[] extractShortOptionsFrom( String argument ) { - char[] options = new char[ argument.length() - 1 ]; - argument.getChars( 1, argument.length(), options, 0 ); - - return options; - } - - /* - * GemFire Addition : following comment & changes in method - * Method signature has been changed to include the detected options - * - * The exception instantiation code has also been changed to take into account the change in expections. - */ - private void validateOptionCharacters( char[] options, OptionSet detected ) { - for ( char each : options ) { - String option = String.valueOf( each ); - - if ( !isRecognized( option ) ) - // GemFire Addition : Changed to include detected OptionSet - throw createUnrecognizedOptionException( option, detected ); - - if ( specFor( option ).acceptsArguments() ) - return; - } - } - - private static KeyValuePair parseLongOptionWithArgument( String argument ) { - return KeyValuePair.valueOf( argument.substring( 2 ) ); - } - - private static KeyValuePair parseShortOptionWithArgument( String argument ) { - return KeyValuePair.valueOf( argument.substring( 1 ) ); - } - - private Map<String, List<?>> defaultValues() { - Map<String, List<?>> defaults = new HashMap<String, List<?>>(); - for ( Map.Entry<String, AbstractOptionSpec<?>> each : recognizedOptions.toJavaUtilMap().entrySet() ) - defaults.put( each.getKey(), each.getValue().defaultValues() ); - return defaults; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/OptionParserState.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/OptionParserState.java b/geode-joptsimple/src/main/java/joptsimple/OptionParserState.java deleted file mode 100644 index 4cda973..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/OptionParserState.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import static joptsimple.ParserRules.*; - -/** - * Abstraction of parser state; mostly serves to model how a parser behaves depending on whether end-of-options - * has been detected. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - * @author Nikhil Jadhav - */ -abstract class OptionParserState { - static OptionParserState noMoreOptions() { - return new OptionParserState() { - @Override - protected void handleArgument( OptionParser parser, ArgumentList arguments, OptionSet detectedOptions ) { - detectedOptions.addNonOptionArgument( arguments.next() ); - } - }; - } - - /* GemFire Addition : following comment & changes in method - * This method has been modified to disable short option support and appropriately the case wherein only the option - * start token is specified. - */ - static OptionParserState moreOptions( final boolean posixlyCorrect ) { - return new OptionParserState() { - @Override - protected void handleArgument( OptionParser parser, ArgumentList arguments, OptionSet detectedOptions ) { - String candidate = arguments.next(); - if ( isOptionTerminator( candidate ) ) - parser.noMoreOptions(); - else if ( isLongOptionToken( candidate ) ) - parser.handleLongOptionToken( candidate, arguments, detectedOptions ); - // GemFire Addition : Check for Boolean property at runtime - else if ( !parser.isShortOptionDisabled() && isShortOptionToken( candidate ) ) - parser.handleShortOptionToken( candidate, arguments, detectedOptions ); - else { - if ( posixlyCorrect ) - parser.noMoreOptions(); - // Check whether the token is made up of only option start, - // then we do not have to consider it. - // GemFire Addition : Modified for Gfsh - if ( parser.isShortOptionDisabled() - && ( candidate.equals( "-" ) || candidate.equals( "--" ) ) ) { - // Do nothing - } else { - detectedOptions.addNonOptionArgument( candidate ); - } - } - } - }; - } - - protected abstract void handleArgument( OptionParser parser, ArgumentList arguments, OptionSet detectedOptions ); -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/OptionSet.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/OptionSet.java b/geode-joptsimple/src/main/java/joptsimple/OptionSet.java deleted file mode 100644 index eb0582e..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/OptionSet.java +++ /dev/null @@ -1,309 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.IdentityHashMap; -import java.util.List; -import java.util.Map; - -import static java.util.Collections.*; - -import static joptsimple.internal.Objects.*; - - -/** - * Representation of a group of detected command line options, their arguments, and non-option arguments. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public class OptionSet { - private final List<OptionSpec<?>> detectedSpecs; - private final Map<String, AbstractOptionSpec<?>> detectedOptions; - private final Map<AbstractOptionSpec<?>, List<String>> optionsToArguments; - private final List<String> nonOptionArguments; - private final Map<String, List<?>> defaultValues; - - /* - * Package-private because clients don't create these. - */ - OptionSet( Map<String, List<?>> defaults ) { - detectedSpecs = new ArrayList<OptionSpec<?>>(); - detectedOptions = new HashMap<String, AbstractOptionSpec<?>>(); - optionsToArguments = new IdentityHashMap<AbstractOptionSpec<?>, List<String>>(); - nonOptionArguments = new ArrayList<String>(); - defaultValues = new HashMap<String, List<?>>( defaults ); - } - - /** - * Tells whether any options were detected. - * - * @return {@code true} if any options were detected - */ - public boolean hasOptions() { - return !detectedOptions.isEmpty(); - } - - /** - * Tells whether the given option was detected. - * - * @param option the option to search for - * @return {@code true} if the option was detected - * @see #has(OptionSpec) - */ - public boolean has( String option ) { - return detectedOptions.containsKey( option ); - } - - /** - * Tells whether the given option was detected. - * - * <p>This method recognizes only instances of options returned from the fluent interface methods.</p> - * - * <p>Specifying a {@linkplain ArgumentAcceptingOptionSpec#defaultsTo(Object, Object[])} default argument value} - * for an option does not cause this method to return {@code true} if the option was not detected on the command - * line.</p> - * - * @param option the option to search for - * @return {@code true} if the option was detected - * @see #has(String) - */ - public boolean has( OptionSpec<?> option ) { - return optionsToArguments.containsKey( option ); - } - - /** - * Tells whether there are any arguments associated with the given option. - * - * @param option the option to search for - * @return {@code true} if the option was detected and at least one argument was detected for the option - * @see #hasArgument(OptionSpec) - */ - public boolean hasArgument( String option ) { - AbstractOptionSpec<?> spec = detectedOptions.get( option ); - return spec != null && hasArgument( spec ); - } - - /** - * Tells whether there are any arguments associated with the given option. - * - * <p>This method recognizes only instances of options returned from the fluent interface methods.</p> - * - * <p>Specifying a {@linkplain ArgumentAcceptingOptionSpec#defaultsTo(Object, Object[]) default argument value} - * for an option does not cause this method to return {@code true} if the option was not detected on the command - * line, or if the option can take an optional argument but did not have one on the command line.</p> - * - * @param option the option to search for - * @return {@code true} if the option was detected and at least one argument was detected for the option - * @throws NullPointerException if {@code option} is {@code null} - * @see #hasArgument(String) - */ - public boolean hasArgument( OptionSpec<?> option ) { - ensureNotNull( option ); - - List<String> values = optionsToArguments.get( option ); - return values != null && !values.isEmpty(); - } - - /** - * Gives the argument associated with the given option. If the option was given an argument type, the argument - * will take on that type; otherwise, it will be a {@link String}. - * - * <p>Specifying a {@linkplain ArgumentAcceptingOptionSpec#defaultsTo(Object, Object[]) default argument value} - * for an option will cause this method to return that default value even if the option was not detected on the - * command line, or if the option can take an optional argument but did not have one on the command line.</p> - * - * @param option the option to search for - * @return the argument of the given option; {@code null} if no argument is present, or that option was not - * detected - * @throws NullPointerException if {@code option} is {@code null} - * @throws OptionException if more than one argument was detected for the option - */ - public Object valueOf( String option ) { - ensureNotNull( option ); - - AbstractOptionSpec<?> spec = detectedOptions.get( option ); - if ( spec == null ) { - List<?> defaults = defaultValuesFor( option ); - return defaults.isEmpty() ? null : defaults.get( 0 ); - } - - return valueOf( spec ); - } - - /** - * Gives the argument associated with the given option. - * - * <p>This method recognizes only instances of options returned from the fluent interface methods.</p> - * - * @param <V> represents the type of the arguments the given option accepts - * @param option the option to search for - * @return the argument of the given option; {@code null} if no argument is present, or that option was not - * detected - * @throws OptionException if more than one argument was detected for the option - * @throws NullPointerException if {@code option} is {@code null} - * @throws ClassCastException if the arguments of this option are not of the expected type - */ - public <V> V valueOf( OptionSpec<V> option ) { - ensureNotNull( option ); - - List<V> values = valuesOf( option ); - switch ( values.size() ) { - case 0: - return null; - case 1: - return values.get( 0 ); - default: - throw new MultipleArgumentsForOptionException( option.options() ); - } - } - - /** - * <p>Gives any arguments associated with the given option. If the option was given an argument type, the - * arguments will take on that type; otherwise, they will be {@link String}s.</p> - * - * @param option the option to search for - * @return the arguments associated with the option, as a list of objects of the type given to the arguments; an - * empty list if no such arguments are present, or if the option was not detected - * @throws NullPointerException if {@code option} is {@code null} - */ - public List<?> valuesOf( String option ) { - ensureNotNull( option ); - - AbstractOptionSpec<?> spec = detectedOptions.get( option ); - return spec == null ? defaultValuesFor( option ) : valuesOf( spec ); - } - - /** - * <p>Gives any arguments associated with the given option. If the option was given an argument type, the - * arguments will take on that type; otherwise, they will be {@link String}s.</p> - * - * <p>This method recognizes only instances of options returned from the fluent interface methods.</p> - * - * @param <V> represents the type of the arguments the given option accepts - * @param option the option to search for - * @return the arguments associated with the option; an empty list if no such arguments are present, or if the - * option was not detected - * @throws NullPointerException if {@code option} is {@code null} - * @throws OptionException if there is a problem converting the option's arguments to the desired type; for - * example, if the type does not implement a correct conversion constructor or method - */ - public <V> List<V> valuesOf( OptionSpec<V> option ) { - ensureNotNull( option ); - - List<String> values = optionsToArguments.get( option ); - if ( values == null || values.isEmpty() ) - return defaultValueFor( option ); - - AbstractOptionSpec<V> spec = (AbstractOptionSpec<V>) option; - List<V> convertedValues = new ArrayList<V>(); - for ( String each : values ) - convertedValues.add( spec.convert( each ) ); - - return unmodifiableList( convertedValues ); - } - - /** - * Gives the set of options that were detected, in the form of {@linkplain OptionSpec}s, in the order in which the - * options were found on the command line. - * - * @return the set of detected command line options - */ - public List<OptionSpec<?>> specs() { - return unmodifiableList( detectedSpecs ); - } - - /** - * @return the detected non-option arguments - */ - public List<String> nonOptionArguments() { - return unmodifiableList( nonOptionArguments ); - } - - void add( AbstractOptionSpec<?> spec ) { - addWithArgument( spec, null ); - } - - void addWithArgument( AbstractOptionSpec<?> spec, String argument ) { - detectedSpecs.add( spec ); - - for ( String each : spec.options() ) - detectedOptions.put( each, spec ); - - List<String> optionArguments = optionsToArguments.get( spec ); - - if ( optionArguments == null ) { - optionArguments = new ArrayList<String>(); - optionsToArguments.put( spec, optionArguments ); - } - - if ( argument != null ) - optionArguments.add( argument ); - } - - void addNonOptionArgument( String argument ) { - nonOptionArguments.add( argument ); - } - - @Override - public boolean equals( Object that ) { - if ( this == that ) - return true; - - if ( that == null || !getClass().equals( that.getClass() ) ) - return false; - - OptionSet other = (OptionSet) that; - Map<AbstractOptionSpec<?>, List<String>> thisOptionsToArguments = - new HashMap<AbstractOptionSpec<?>, List<String>>( optionsToArguments ); - Map<AbstractOptionSpec<?>, List<String>> otherOptionsToArguments = - new HashMap<AbstractOptionSpec<?>, List<String>>( other.optionsToArguments ); - return detectedOptions.equals( other.detectedOptions ) - && thisOptionsToArguments.equals( otherOptionsToArguments ) - && nonOptionArguments.equals( other.nonOptionArguments() ); - } - - @Override - public int hashCode() { - Map<AbstractOptionSpec<?>, List<String>> thisOptionsToArguments = - new HashMap<AbstractOptionSpec<?>, List<String>>( optionsToArguments ); - return detectedOptions.hashCode() - ^ thisOptionsToArguments.hashCode() - ^ nonOptionArguments.hashCode(); - } - - private <V> List<V> defaultValuesFor( String option ) { - if ( defaultValues.containsKey( option ) ) - return (List<V>) defaultValues.get( option ); - - return emptyList(); - } - - private <V> List<V> defaultValueFor( OptionSpec<V> option ) { - return defaultValuesFor( option.options().iterator().next() ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/OptionSpec.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/OptionSpec.java b/geode-joptsimple/src/main/java/joptsimple/OptionSpec.java deleted file mode 100644 index 9f79a40..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/OptionSpec.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.Collection; -import java.util.List; - -/** - * Describes options that an option parser recognizes. - * - * <p>Instances of this interface are returned by the "fluent interface" methods to allow retrieval of option arguments - * in a type-safe manner. Here's an example:</p> - * - * <pre><code> - * OptionParser parser = new OptionParser(); - * <strong>OptionSpec<Integer></strong> count = - * parser.accepts( "count" ).withRequiredArg().ofType( Integer.class ); - * OptionSet options = parser.parse( "--count", "2" ); - * assert options.has( count ); - * int countValue = options.valueOf( count ); - * assert countValue == count.value( options ); - * List<Integer> countValues = options.valuesOf( count ); - * assert countValues.equals( count.values( options ) ); - * </code></pre> - * - * @param <V> represents the type of the arguments this option accepts - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public interface OptionSpec<V> { - /** - * Gives any arguments associated with the given option in the given set of detected options. - * - * <p>Specifying a {@linkplain ArgumentAcceptingOptionSpec#defaultsTo(Object, Object[]) default argument value} - * for this option will cause this method to return that default value even if this option was not detected on the - * command line, or if this option can take an optional argument but did not have one on the command line.</p> - * - * @param detectedOptions the detected options to search in - * @return the arguments associated with this option; an empty list if no such arguments are present, or if this - * option was not detected - * @throws OptionException if there is a problem converting this option's arguments to the desired type; for - * example, if the type does not implement a correct conversion constructor or method - * @throws NullPointerException if {@code detectedOptions} is {@code null} - * @see OptionSet#valuesOf(OptionSpec) - */ - List<V> values( OptionSet detectedOptions ); - - /** - * Gives the argument associated with the given option in the given set of detected options. - * - * <p>Specifying a {@linkplain ArgumentAcceptingOptionSpec#defaultsTo(Object, Object[]) default argument value} - * for this option will cause this method to return that default value even if this option was not detected on the - * command line, or if this option can take an optional argument but did not have one on the command line.</p> - * - * @param detectedOptions the detected options to search in - * @return the argument of the this option; {@code null} if no argument is present, or that option was not detected - * @throws OptionException if more than one argument was detected for the option - * @throws NullPointerException if {@code detectedOptions} is {@code null} - * @throws ClassCastException if the arguments of this option are not of the expected type - * @see OptionSet#valueOf(OptionSpec) - */ - V value( OptionSet detectedOptions ); - - /** - * @return the string representations of this option - */ - Collection<String> options(); - - /** - * Tells whether this option is designated as a "help" option. The presence of a "help" option on a command line - * means that missing "required" options will not cause parsing to fail. - * - * @return whether this option is designated as a "help" option - */ - boolean isForHelp(); -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/OptionSpecBuilder.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/OptionSpecBuilder.java b/geode-joptsimple/src/main/java/joptsimple/OptionSpecBuilder.java deleted file mode 100644 index ff3c99e..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/OptionSpecBuilder.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.Collection; - -/** - * Allows callers to specify whether a given option accepts arguments (required or optional). - * - * <p>Instances are returned from {@link OptionParser#accepts(String)} to allow the formation of parser directives as - * sentences in a "fluent interface" language. For example:</p> - * - * <pre><code> - * OptionParser parser = new OptionParser(); - * parser.accepts( "c" ).<strong>withRequiredArg()</strong>.ofType( Integer.class ); - * </code></pre> - * - * <p>If no methods are invoked on an instance of this class, then that instance's option will accept no argument.</p> - * - * <p>Note that you should not use the fluent interface clauses in a way that would defeat the typing of option - * arguments:</p> - * - * <pre><code> - * OptionParser parser = new OptionParser(); - * ArgumentAcceptingOptionSpec<String> optionC = - * parser.accepts( "c" ).withRequiredArg(); - * <strong>optionC.ofType( Integer.class ); // DON'T THROW AWAY THE TYPE!</strong> - * - * String value = parser.parse( "-c", "2" ).valueOf( optionC ); // ClassCastException - * </code></pre> - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public class OptionSpecBuilder extends NoArgumentOptionSpec { - private final OptionParser parser; - - OptionSpecBuilder( OptionParser parser, Collection<String> options, String description ) { - super( options, description ); - - this.parser = parser; - attachToParser(); - } - - private void attachToParser() { - parser.recognize( this ); - } - - /** - * Informs an option parser that this builder's option requires an argument. - * - * @return a specification for the option - */ - public ArgumentAcceptingOptionSpec<String> withRequiredArg() { - ArgumentAcceptingOptionSpec<String> newSpec = - new RequiredArgumentOptionSpec<String>( options(), description() ); - parser.recognize( newSpec ); - - return newSpec; - } - - /** - * Informs an option parser that this builder's option accepts an optional argument. - * - * @return a specification for the option - */ - public ArgumentAcceptingOptionSpec<String> withOptionalArg() { - ArgumentAcceptingOptionSpec<String> newSpec = - new OptionalArgumentOptionSpec<String>( options(), description() ); - parser.recognize( newSpec ); - - return newSpec; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/OptionSpecTokenizer.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/OptionSpecTokenizer.java b/geode-joptsimple/src/main/java/joptsimple/OptionSpecTokenizer.java deleted file mode 100644 index 0318db5..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/OptionSpecTokenizer.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.NoSuchElementException; - -import static joptsimple.ParserRules.*; - - -/** - * Tokenizes a short option specification string. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -class OptionSpecTokenizer { - private static final char POSIXLY_CORRECT_MARKER = '+'; - private static final char HELP_MARKER = '*'; - - private String specification; - private int index; - - OptionSpecTokenizer( String specification ) { - if ( specification == null ) - throw new NullPointerException( "null option specification" ); - - this.specification = specification; - } - - boolean hasMore() { - return index < specification.length(); - } - - AbstractOptionSpec<?> next() { - if ( !hasMore() ) - throw new NoSuchElementException(); - - - String optionCandidate = String.valueOf( specification.charAt( index ) ); - index++; - - AbstractOptionSpec<?> spec; - if ( RESERVED_FOR_EXTENSIONS.equals( optionCandidate ) ) { - spec = handleReservedForExtensionsToken(); - - if ( spec != null ) - return spec; - } - - ensureLegalOption( optionCandidate ); - - if ( hasMore() ) { - boolean forHelp = false; - if ( specification.charAt( index ) == HELP_MARKER ) { - forHelp = true; - ++index; - } - spec = hasMore() && specification.charAt( index ) == ':' - ? handleArgumentAcceptingOption( optionCandidate ) - : new NoArgumentOptionSpec( optionCandidate ); - if ( forHelp ) - spec.forHelp(); - } else - spec = new NoArgumentOptionSpec( optionCandidate ); - - return spec; - } - - void configure( OptionParser parser ) { - adjustForPosixlyCorrect( parser ); - - while ( hasMore() ) - parser.recognize( next() ); - } - - private void adjustForPosixlyCorrect( OptionParser parser ) { - if ( POSIXLY_CORRECT_MARKER == specification.charAt( 0 ) ) { - parser.posixlyCorrect( true ); - specification = specification.substring( 1 ); - } - } - - private AbstractOptionSpec<?> handleReservedForExtensionsToken() { - if ( !hasMore() ) - return new NoArgumentOptionSpec( RESERVED_FOR_EXTENSIONS ); - - if ( specification.charAt( index ) == ';' ) { - ++index; - return new AlternativeLongOptionSpec(); - } - - return null; - } - - private AbstractOptionSpec<?> handleArgumentAcceptingOption( String candidate ) { - index++; - - if ( hasMore() && specification.charAt( index ) == ':' ) { - index++; - return new OptionalArgumentOptionSpec<String>( candidate ); - } - - return new RequiredArgumentOptionSpec<String>( candidate ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/OptionalArgumentOptionSpec.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/OptionalArgumentOptionSpec.java b/geode-joptsimple/src/main/java/joptsimple/OptionalArgumentOptionSpec.java deleted file mode 100644 index 250ffd3..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/OptionalArgumentOptionSpec.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.Collection; - -/** - * Specification of an option that accepts an optional argument. - * - * @param <V> represents the type of the arguments this option accepts - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -class OptionalArgumentOptionSpec<V> extends ArgumentAcceptingOptionSpec<V> { - OptionalArgumentOptionSpec( String option ) { - super( option, false ); - } - - OptionalArgumentOptionSpec( Collection<String> options, String description ) { - super( options, false, description ); - } - - @Override - protected void detectOptionArgument( OptionParser parser, ArgumentList arguments, OptionSet detectedOptions ) { - if ( arguments.hasMore() ) { - String nextArgument = arguments.peek(); - - if ( !parser.looksLikeAnOption( nextArgument ) ) - handleOptionArgument( parser, detectedOptions, arguments ); - else if ( isArgumentOfNumberType() && canConvertArgument( nextArgument ) ) - addArguments( detectedOptions, arguments.next() ); - else - detectedOptions.add( this ); - } - else - detectedOptions.add( this ); - } - - private void handleOptionArgument( OptionParser parser, OptionSet detectedOptions, ArgumentList arguments ) { - if ( parser.posixlyCorrect() ) { - detectedOptions.add( this ); - parser.noMoreOptions(); - } - else - addArguments( detectedOptions, arguments.next() ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/ParserRules.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/ParserRules.java b/geode-joptsimple/src/main/java/joptsimple/ParserRules.java deleted file mode 100644 index da4906b..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/ParserRules.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.Collection; - -import static java.lang.Character.*; - -/** - * Can tell whether or not options are well-formed. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -final class ParserRules { - static final char HYPHEN_CHAR = '-'; - static final String HYPHEN = String.valueOf( HYPHEN_CHAR ); - static final String DOUBLE_HYPHEN = "--"; - static final String OPTION_TERMINATOR = DOUBLE_HYPHEN; - static final String RESERVED_FOR_EXTENSIONS = "W"; - - private ParserRules() { - throw new UnsupportedOperationException(); - } - - static boolean isShortOptionToken( String argument ) { - return argument.startsWith( HYPHEN ) - && !HYPHEN.equals( argument ) - && !isLongOptionToken( argument ); - } - - static boolean isLongOptionToken( String argument ) { - return argument.startsWith( DOUBLE_HYPHEN ) && !isOptionTerminator( argument ); - } - - static boolean isOptionTerminator( String argument ) { - return OPTION_TERMINATOR.equals( argument ); - } - - static void ensureLegalOption( String option ) { - if ( option.startsWith( HYPHEN ) ) - throw new IllegalOptionSpecificationException( String.valueOf( option ) ); - - for ( int i = 0; i < option.length(); ++i ) - ensureLegalOptionCharacter( option.charAt( i ) ); - } - - static void ensureLegalOptions( Collection<String> options ) { - for ( String each : options ) - ensureLegalOption( each ); - } - - private static void ensureLegalOptionCharacter( char option ) { - if ( !( isLetterOrDigit( option ) || isAllowedPunctuation( option ) ) ) - throw new IllegalOptionSpecificationException( String.valueOf( option ) ); - } - - private static boolean isAllowedPunctuation( char option ) { - String allowedPunctuation = "?." + HYPHEN_CHAR; - return allowedPunctuation.indexOf( option ) != -1; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/RequiredArgumentOptionSpec.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/RequiredArgumentOptionSpec.java b/geode-joptsimple/src/main/java/joptsimple/RequiredArgumentOptionSpec.java deleted file mode 100644 index 7baae72..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/RequiredArgumentOptionSpec.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import java.util.Collection; - -/** - * Specification of an option that accepts a required argument. - * - * @param <V> represents the type of the arguments this option accepts - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - * @author Nikhil Jadhav - */ -class RequiredArgumentOptionSpec<V> extends ArgumentAcceptingOptionSpec<V> { - RequiredArgumentOptionSpec( String option ) { - super( option, true ); - } - - RequiredArgumentOptionSpec( Collection<String> options, String description ) { - super( options, true, description ); - } - - @Override - protected void detectOptionArgument( OptionParser parser, ArgumentList arguments, OptionSet detectedOptions ) { - if ( !arguments.hasMore() ) - // GemFire Addition : Changed to include OptionSet - throw new OptionMissingRequiredArgumentException( options(), detectedOptions ); - - addArguments( detectedOptions, arguments.next() ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/UnrecognizedOptionException.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/UnrecognizedOptionException.java b/geode-joptsimple/src/main/java/joptsimple/UnrecognizedOptionException.java deleted file mode 100644 index 1d6f508..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/UnrecognizedOptionException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -import static java.util.Collections.*; - -/** - * Thrown when the option parser encounters an unrecognized option. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - * @author Nikhil Jadhav - */ -public class UnrecognizedOptionException extends OptionException { - private static final long serialVersionUID = -1L; - - UnrecognizedOptionException( String option ) { - super( singletonList( option ) ); - } - - // GemFire Addition : Added to include the detected options - UnrecognizedOptionException( String option, OptionSet detected ) { - super( singletonList( option ), detected ); - } - - @Override - public String getMessage() { - return singleOptionMessage() + " is not a recognized option"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/ValueConversionException.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/ValueConversionException.java b/geode-joptsimple/src/main/java/joptsimple/ValueConversionException.java deleted file mode 100644 index 282c5c4..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/ValueConversionException.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -/** - * Thrown by {@link ValueConverter}s when problems occur in converting string values to other Java types. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public class ValueConversionException extends RuntimeException { - private static final long serialVersionUID = -1L; - - /** - * Creates a new exception with the specified detail message. - * - * @param message the detail message - */ - public ValueConversionException( String message ) { - this( message, null ); - } - - /** - * Creates a new exception with the specified detail message and cause. - * - * @param message the detail message - * @param cause the original exception - */ - public ValueConversionException( String message, Throwable cause ) { - super( message, cause ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/ValueConverter.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/ValueConverter.java b/geode-joptsimple/src/main/java/joptsimple/ValueConverter.java deleted file mode 100644 index d90bef8..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/ValueConverter.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple; - -/** - * Instances of this interface are used to convert arguments of options into specific Java types. - * - * @param <V> constraint on the type of values being converted to - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public interface ValueConverter<V> { - /** - * Converts the given string value into a Java type. - * - * @param value the string to convert - * @return the converted value - * @throws ValueConversionException if a problem occurs while converting the value - */ - V convert( String value ); - - /** - * Gives the class of the type of values this converter converts to. - * - * @return the target class for conversion - */ - Class<V> valueType(); - - /** - * Gives a string that describes the pattern of the values this converter expects, if any. For example, a date - * converter can respond with a {@link java.text.SimpleDateFormat date format string}. - * - * @return a value pattern, or {@code null} if there's nothing interesting here - */ - String valuePattern(); -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/internal/AbbreviationMap.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/internal/AbbreviationMap.java b/geode-joptsimple/src/main/java/joptsimple/internal/AbbreviationMap.java deleted file mode 100644 index 35fad89..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/internal/AbbreviationMap.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple.internal; - -import java.util.Map; -import java.util.TreeMap; - -/** - * <p>A map whose keys are strings; when a key/value pair is added to the map, the longest unique abbreviations of that - * key are added as well, and associated with the value. Thus:</p> - * - * <pre> - * <code> - * abbreviations.put( "good", "bye" ); - * </code> - * </pre> - * - * <p>would make it such that you could retrieve the value {@code "bye"} from the map using the keys {@code "good"}, - * {@code "goo"}, {@code "go"}, and {@code "g"}. A subsequent invocation of:</p> - * <pre> - * <code> - * abbreviations.put( "go", "fish" ); - * </code> - * </pre> - * - * <p>would make it such that you could retrieve the value {@code "bye"} using the keys {@code "good"} and - * {@code "goo"}, and the value {@code "fish"} using the key {@code "go"}. The key {@code "g"} would yield - * {@code null}, since it would no longer be a unique abbreviation.</p> - * - * <p>The data structure is much like a "trie".</p> - * - * @param <V> a constraint on the types of the values in the map - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public class AbbreviationMap<V> { - private String key; - private V value; - private final Map<Character, AbbreviationMap<V>> children = new TreeMap<Character, AbbreviationMap<V>>(); - private int keysBeyond; - - /** - * <p>Tells whether the given key is in the map, or whether the given key is a unique - * abbreviation of a key that is in the map.</p> - * - * @param aKey key to look up - * @return {@code true} if {@code key} is present in the map - * @throws NullPointerException if {@code key} is {@code null} - */ - public boolean contains( String aKey ) { - return get( aKey ) != null; - } - - /** - * <p>Answers the value associated with the given key. The key can be a unique - * abbreviation of a key that is in the map. </p> - * - * @param aKey key to look up - * @return the value associated with {@code aKey}; or {@code null} if there is no - * such value or {@code aKey} is not a unique abbreviation of a key in the map - * @throws NullPointerException if {@code aKey} is {@code null} - */ - public V get( String aKey ) { - char[] chars = charsOf( aKey ); - - AbbreviationMap<V> child = this; - for ( char each : chars ) { - child = child.children.get( each ); - if ( child == null ) - return null; - } - - return child.value; - } - - /** - * <p>Associates a given value with a given key. If there was a previous - * association, the old value is replaced with the new one.</p> - * - * @param aKey key to create in the map - * @param newValue value to associate with the key - * @throws NullPointerException if {@code aKey} or {@code newValue} is {@code null} - * @throws IllegalArgumentException if {@code aKey} is a zero-length string - */ - public void put( String aKey, V newValue ) { - if ( newValue == null ) - throw new NullPointerException(); - if ( aKey.length() == 0 ) - throw new IllegalArgumentException(); - - char[] chars = charsOf( aKey ); - add( chars, newValue, 0, chars.length ); - } - - /** - * <p>Associates a given value with a given set of keys. If there was a previous - * association, the old value is replaced with the new one.</p> - * - * @param keys keys to create in the map - * @param newValue value to associate with the key - * @throws NullPointerException if {@code keys} or {@code newValue} is {@code null} - * @throws IllegalArgumentException if any of {@code keys} is a zero-length string - */ - public void putAll( Iterable<String> keys, V newValue ) { - for ( String each : keys ) - put( each, newValue ); - } - - private boolean add( char[] chars, V newValue, int offset, int length ) { - if ( offset == length ) { - value = newValue; - boolean wasAlreadyAKey = key != null; - key = new String( chars ); - return !wasAlreadyAKey; - } - - char nextChar = chars[ offset ]; - AbbreviationMap<V> child = children.get( nextChar ); - if ( child == null ) { - child = new AbbreviationMap<V>(); - children.put( nextChar, child ); - } - - boolean newKeyAdded = child.add( chars, newValue, offset + 1, length ); - - if ( newKeyAdded ) - ++keysBeyond; - - if ( key == null ) - value = keysBeyond > 1 ? null : newValue; - - return newKeyAdded; - } - - /** - * <p>If the map contains the given key, dissociates the key from its value.</p> - * - * @param aKey key to remove - * @throws NullPointerException if {@code aKey} is {@code null} - * @throws IllegalArgumentException if {@code aKey} is a zero-length string - */ - public void remove( String aKey ) { - if ( aKey.length() == 0 ) - throw new IllegalArgumentException(); - - char[] keyChars = charsOf( aKey ); - remove( keyChars, 0, keyChars.length ); - } - - private boolean remove( char[] aKey, int offset, int length ) { - if ( offset == length ) - return removeAtEndOfKey(); - - char nextChar = aKey[ offset ]; - AbbreviationMap<V> child = children.get( nextChar ); - if ( child == null || !child.remove( aKey, offset + 1, length ) ) - return false; - - --keysBeyond; - if ( child.keysBeyond == 0 ) - children.remove( nextChar ); - if ( keysBeyond == 1 && key == null ) - setValueToThatOfOnlyChild(); - - return true; - } - - private void setValueToThatOfOnlyChild() { - Map.Entry<Character, AbbreviationMap<V>> entry = children.entrySet().iterator().next(); - AbbreviationMap<V> onlyChild = entry.getValue(); - value = onlyChild.value; - } - - private boolean removeAtEndOfKey() { - if ( key == null ) - return false; - - key = null; - if ( keysBeyond == 1 ) - setValueToThatOfOnlyChild(); - else - value = null; - - return true; - } - - /** - * Gives a Java map representation of this abbreviation map. - * - * @return a Java map corresponding to this abbreviation map - */ - public Map<String, V> toJavaUtilMap() { - Map<String, V> mappings = new TreeMap<String, V>(); - addToMappings( mappings ); - return mappings; - } - - private void addToMappings( Map<String, V> mappings ) { - if ( key != null ) - mappings.put( key, value ); - - for ( AbbreviationMap<V> each : children.values() ) - each.addToMappings( mappings ); - } - - private static char[] charsOf( String aKey ) { - char[] chars = new char[ aKey.length() ]; - aKey.getChars( 0, aKey.length(), chars, 0 ); - return chars; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/internal/Classes.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/internal/Classes.java b/geode-joptsimple/src/main/java/joptsimple/internal/Classes.java deleted file mode 100644 index 89e0310..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/internal/Classes.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple.internal; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public final class Classes { - private static final Map<Class<?>, Class<?>> WRAPPERS = new HashMap<Class<?>, Class<?>>( 13 ); - - static { - WRAPPERS.put( boolean.class, Boolean.class ); - WRAPPERS.put( byte.class, Byte.class ); - WRAPPERS.put( char.class, Character.class ); - WRAPPERS.put( double.class, Double.class ); - WRAPPERS.put( float.class, Float.class ); - WRAPPERS.put( int.class, Integer.class ); - WRAPPERS.put( long.class, Long.class ); - WRAPPERS.put( short.class, Short.class ); - WRAPPERS.put( void.class, Void.class ); - } - - private Classes() { - throw new UnsupportedOperationException(); - } - - /** - * Gives the "short version" of the given class name. Somewhat naive to inner classes. - * - * @param className class name to chew on - * @return the short name of the class - */ - public static String shortNameOf( String className ) { - return className.substring( className.lastIndexOf( '.' ) + 1 ); - } - - /** - * Gives the primitive wrapper class for the given class. If the given class is not - * {@linkplain Class#isPrimitive() primitive}, returns the class itself. - * - * @param <T> generic class type - * @param clazz the class to check - * @return primitive wrapper type if {@code clazz} is primitive, otherwise {@code clazz} - */ - public static <T> Class<T> wrapperOf( Class<T> clazz ) { - return clazz.isPrimitive() ? (Class<T>) WRAPPERS.get( clazz ) : clazz; - } -}