Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.internal.opt/share/classes/jdk/internal/joptsimple/OptionSpec.java
40948 views
1
/*
2
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
/*
27
* This file is available under and governed by the GNU General Public
28
* License version 2 only, as published by the Free Software Foundation.
29
* However, the following notice accompanied the original version of this
30
* file:
31
*
32
* The MIT License
33
*
34
* Copyright (c) 2004-2015 Paul R. Holser, Jr.
35
*
36
* Permission is hereby granted, free of charge, to any person obtaining
37
* a copy of this software and associated documentation files (the
38
* "Software"), to deal in the Software without restriction, including
39
* without limitation the rights to use, copy, modify, merge, publish,
40
* distribute, sublicense, and/or sell copies of the Software, and to
41
* permit persons to whom the Software is furnished to do so, subject to
42
* the following conditions:
43
*
44
* The above copyright notice and this permission notice shall be
45
* included in all copies or substantial portions of the Software.
46
*
47
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
51
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
52
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
53
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
54
*/
55
56
package jdk.internal.joptsimple;
57
58
import java.util.List;
59
60
/**
61
* Describes options that an option parser recognizes.
62
*
63
* <p>Instances of this interface are returned by the "fluent interface" methods to allow retrieval of option arguments
64
* in a type-safe manner. Here's an example:</p>
65
*
66
* <pre><code>
67
* OptionParser parser = new OptionParser();
68
* <strong>OptionSpec&lt;Integer&gt;</strong> count =
69
* parser.accepts( "count" ).withRequiredArg().ofType( Integer.class );
70
* OptionSet options = parser.parse( "--count", "2" );
71
* assert options.has( count );
72
* int countValue = options.valueOf( count );
73
* assert countValue == count.value( options );
74
* List&lt;Integer&gt; countValues = options.valuesOf( count );
75
* assert countValues.equals( count.values( options ) );
76
* </code></pre>
77
*
78
* @param <V> represents the type of the arguments this option accepts
79
* @author <a href="mailto:[email protected]">Paul Holser</a>
80
*/
81
public interface OptionSpec<V> {
82
/**
83
* Gives any arguments associated with the given option in the given set of detected options.
84
*
85
* <p>Specifying a {@linkplain ArgumentAcceptingOptionSpec#defaultsTo(Object, Object[]) default argument value}
86
* for this option will cause this method to return that default value even if this option was not detected on the
87
* command line, or if this option can take an optional argument but did not have one on the command line.</p>
88
*
89
* @param detectedOptions the detected options to search in
90
* @return the arguments associated with this option; an empty list if no such arguments are present, or if this
91
* option was not detected
92
* @throws OptionException if there is a problem converting this option's arguments to the desired type; for
93
* example, if the type does not implement a correct conversion constructor or method
94
* @throws NullPointerException if {@code detectedOptions} is {@code null}
95
* @see OptionSet#valuesOf(OptionSpec)
96
*/
97
List<V> values( OptionSet detectedOptions );
98
99
/**
100
* Gives the argument associated with the given option in the given set of detected options.
101
*
102
* <p>Specifying a {@linkplain ArgumentAcceptingOptionSpec#defaultsTo(Object, Object[]) default argument value}
103
* for this option will cause this method to return that default value even if this option was not detected on the
104
* command line, or if this option can take an optional argument but did not have one on the command line.</p>
105
*
106
* @param detectedOptions the detected options to search in
107
* @return the argument of the this option; {@code null} if no argument is present, or that option was not detected
108
* @throws OptionException if more than one argument was detected for the option
109
* @throws NullPointerException if {@code detectedOptions} is {@code null}
110
* @throws ClassCastException if the arguments of this option are not of the expected type
111
* @see OptionSet#valueOf(OptionSpec)
112
*/
113
V value( OptionSet detectedOptions );
114
115
/**
116
* @return the string representations of this option
117
*/
118
List<String> options();
119
120
/**
121
* Tells whether this option is designated as a "help" option. The presence of a "help" option on a command line
122
* means that missing "required" options will not cause parsing to fail.
123
*
124
* @return whether this option is designated as a "help" option
125
*/
126
boolean isForHelp();
127
}
128
129