src/jdk.internal.opt/share/classes/jdk/internal/joptsimple/NonOptionArgumentSpec.java
author jlahoda
Wed, 06 Jun 2018 15:36:29 +0200
changeset 50428 8c88df2e8a78
parent 47216 71c04702a3d5
permissions -rw-r--r--
8203891: Upgrade JOpt Simple to 5.0.4 Reviewed-by: alanb, chegar, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35377
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     1
/*
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     2
 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     4
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    10
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    15
 * accompanied this code).
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    16
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    20
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    23
 * questions.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    24
 */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    25
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    26
/*
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    27
 * This file is available under and governed by the GNU General Public
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    28
 * License version 2 only, as published by the Free Software Foundation.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    29
 * However, the following notice accompanied the original version of this
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    30
 * file:
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    31
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    32
 * The MIT License
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    33
 *
50428
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
    34
 * Copyright (c) 2004-2015 Paul R. Holser, Jr.
35377
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    35
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    36
 * Permission is hereby granted, free of charge, to any person obtaining
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    37
 * a copy of this software and associated documentation files (the
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    38
 * "Software"), to deal in the Software without restriction, including
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    39
 * without limitation the rights to use, copy, modify, merge, publish,
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    40
 * distribute, sublicense, and/or sell copies of the Software, and to
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    41
 * permit persons to whom the Software is furnished to do so, subject to
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    42
 * the following conditions:
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    43
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    44
 * The above copyright notice and this permission notice shall be
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    45
 * included in all copies or substantial portions of the Software.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    46
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    47
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    48
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    49
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    50
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    51
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    52
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    53
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    54
 */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    55
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    56
package jdk.internal.joptsimple;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    57
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    58
import java.util.List;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    59
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    60
import static java.util.Arrays.*;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    61
import static java.util.Collections.*;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    62
import static jdk.internal.joptsimple.internal.Reflection.*;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    63
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    64
/**
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    65
 * <p>Specification of a command line's non-option arguments.</p>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    66
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    67
 * <p>Instances are returned from {@link OptionParser} methods to allow the formation of parser directives as
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    68
 * sentences in a "fluent interface" language. For example:</p>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    69
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    70
 * <pre>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    71
 *   <code>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    72
 *   OptionParser parser = new OptionParser();
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    73
 *   parser.nonOptions( "files to be processed" ).<strong>ofType( File.class )</strong>;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    74
 *   </code>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    75
 * </pre>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    76
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    77
 * <p>If no methods are invoked on an instance of this class, then that instance's option will treat the non-option
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    78
 * arguments as {@link String}s.</p>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    79
 *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    80
 * @param <V> represents the type of the non-option arguments
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    81
 * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    82
 */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    83
public class NonOptionArgumentSpec<V> extends AbstractOptionSpec<V> {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    84
    static final String NAME = "[arguments]";
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    85
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    86
    private ValueConverter<V> converter;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    87
    private String argumentDescription = "";
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    88
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    89
    NonOptionArgumentSpec() {
50428
8c88df2e8a78 8203891: Upgrade JOpt Simple to 5.0.4
jlahoda
parents: 47216
diff changeset
    90
        this( "" );
35377
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    91
    }
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    92
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    93
    NonOptionArgumentSpec( String description ) {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    94
        super( asList( NAME ), description );
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    95
    }
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    96
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    97
    /**
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    98
     * <p>Specifies a type to which the non-option arguments are to be converted.</p>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
    99
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   100
     * <p>JOpt Simple accepts types that have either:</p>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   101
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   102
     * <ol>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   103
     *   <li>a public static method called {@code valueOf} which accepts a single argument of type {@link String}
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   104
     *   and whose return type is the same as the class on which the method is declared.  The {@code java.lang}
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   105
     *   primitive wrapper classes have such methods.</li>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   106
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   107
     *   <li>a public constructor which accepts a single argument of type {@link String}.</li>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   108
     * </ol>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   109
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   110
     * <p>This class converts arguments using those methods in that order; that is, {@code valueOf} would be invoked
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   111
     * before a one-{@link String}-arg constructor would.</p>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   112
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   113
     * <p>Invoking this method will trump any previous calls to this method or to
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   114
     * {@link #withValuesConvertedBy(ValueConverter)}.</p>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   115
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   116
     * @param <T> represents the runtime class of the desired option argument type
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   117
     * @param argumentType desired type of arguments to this spec's option
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   118
     * @return self, so that the caller can add clauses to the fluent interface sentence
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   119
     * @throws NullPointerException if the type is {@code null}
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   120
     * @throws IllegalArgumentException if the type does not have the standard conversion methods
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   121
     */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   122
    @SuppressWarnings( "unchecked" )
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   123
    public <T> NonOptionArgumentSpec<T> ofType( Class<T> argumentType ) {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   124
        converter = (ValueConverter<V>) findConverter( argumentType );
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   125
        return (NonOptionArgumentSpec<T>) this;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   126
    }
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   127
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   128
    /**
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   129
     * <p>Specifies a converter to use to translate non-option arguments into Java objects.  This is useful
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   130
     * when converting to types that do not have the requisite factory method or constructor for
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   131
     * {@link #ofType(Class)}.</p>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   132
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   133
     * <p>Invoking this method will trump any previous calls to this method or to {@link #ofType(Class)}.
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   134
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   135
     * @param <T> represents the runtime class of the desired non-option argument type
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   136
     * @param aConverter the converter to use
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   137
     * @return self, so that the caller can add clauses to the fluent interface sentence
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   138
     * @throws NullPointerException if the converter is {@code null}
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   139
     */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   140
    @SuppressWarnings( "unchecked" )
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   141
    public final <T> NonOptionArgumentSpec<T> withValuesConvertedBy( ValueConverter<T> aConverter ) {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   142
        if ( aConverter == null )
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   143
            throw new NullPointerException( "illegal null converter" );
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   144
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   145
        converter = (ValueConverter<V>) aConverter;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   146
        return (NonOptionArgumentSpec<T>) this;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   147
    }
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   148
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   149
    /**
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   150
     * <p>Specifies a description for the non-option arguments that this spec represents.  This description is used
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   151
     * when generating help information about the parser.</p>
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   152
     *
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   153
     * @param description describes the nature of the argument of this spec's option
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   154
     * @return self, so that the caller can add clauses to the fluent interface sentence
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   155
     */
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   156
    public NonOptionArgumentSpec<V> describedAs( String description ) {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   157
        argumentDescription = description;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   158
        return this;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   159
    }
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   160
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   161
    @Override
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   162
    protected final V convert( String argument ) {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   163
        return convertWith( converter, argument );
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   164
    }
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   165
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   166
    @Override
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   167
    void handleOption( OptionParser parser, ArgumentList arguments, OptionSet detectedOptions,
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   168
        String detectedArgument ) {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   169
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   170
        detectedOptions.addWithArgument( this, detectedArgument );
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   171
    }
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   172
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   173
    public List<?> defaultValues() {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   174
        return emptyList();
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   175
    }
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   176
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   177
    public boolean isRequired() {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   178
        return false;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   179
    }
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   180
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   181
    public boolean acceptsArguments() {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   182
        return false;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   183
    }
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   184
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   185
    public boolean requiresArgument() {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   186
        return false;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   187
    }
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   188
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   189
    public String argumentDescription() {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   190
        return argumentDescription;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   191
    }
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   192
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   193
    public String argumentTypeIndicator() {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   194
        return argumentTypeIndicatorFrom( converter );
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   195
    }
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   196
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   197
    public boolean representsNonOptions() {
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   198
        return true;
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   199
    }
462f93ab37f2 8148154: Integrate JOpt Simple for internal usage by JDK tools
chegar
parents:
diff changeset
   200
}