| Option.java |
1 /**
2 * Distribution License:
3 * JSword is free software; you can redistribute it and/or modify it under
4 * the terms of the GNU Lesser General Public License, version 2.1 or later
5 * as published by the Free Software Foundation. This program is distributed
6 * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
7 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 * See the GNU Lesser General Public License for more details.
9 *
10 * The License is available on the internet at:
11 * http://www.gnu.org/copyleft/lgpl.html
12 * or by writing to:
13 * Free Software Foundation, Inc.
14 * 59 Temple Place - Suite 330
15 * Boston, MA 02111-1307, USA
16 *
17 * © CrossWire Bible Society, 2008 - 2016
18 *
19 */
20 package org.crosswire.common.options;
21
22 /**
23 * An Option is representation of a single named parameter. An Option has a
24 * short, or a long name, or both.
25 * <p>
26 * It's inspiration was for command-line argument processing, but it can be used
27 * for any other purpose.
28 * </p>
29 * <ul>
30 * <li>An Option has a description, suitable for a usage statement.</li>
31 * <li>An Option's argument can be optional, required or unexpected. Default is
32 * NO_ARGUMENT.</li>
33 * <li>An Option can have an argument of a type. Default is DataType.BOOLEAN.</li>
34 * <li>An Option can have short name consisting of a single character.</li>
35 * <li>An Option can have a long name given by any string. What is allowed in
36 * the long name is dependent upon usage, but typically does not allow spaces.</li>
37 * <li>An Option can have a default value. Default is no default value.</li>
38 * </ul>
39 *
40 * @see gnu.lgpl.License The GNU Lesser General Public License for details.
41 * @author DM Smith
42 */
43 public class Option {
44 /**
45 * Create a BOOLEAN Option with a short name, having no default value.
46 *
47 * @param description
48 * the description
49 * @param shortName
50 * the short name
51 */
52 public Option(String description, char shortName) {
53 this(description, ArgumentType.NO_ARGUMENT, DataType.BOOLEAN, shortName, null, null);
54 }
55
56 /**
57 * Create a BOOLEAN Option with a long name, having no default value.
58 *
59 * @param description
60 * the description
61 * @param longName
62 * the long name
63 */
64 public Option(String description, String longName) {
65 this(description, ArgumentType.NO_ARGUMENT, DataType.BOOLEAN, '\u0000', longName, null);
66 }
67
68 /**
69 * Create a BOOLEAN Option with both short and long names, having no default
70 * value.
71 *
72 * @param description
73 * the description
74 * @param shortName
75 * the short name
76 * @param longName
77 * the long name
78 */
79 public Option(String description, char shortName, String longName) {
80 this(description, ArgumentType.NO_ARGUMENT, DataType.BOOLEAN, shortName, longName, null);
81 }
82
83 /**
84 * Create an Option with both short and long names of a given DataType
85 * having a default value.
86 *
87 * @param description
88 * the description
89 * @param shortName
90 * the short name
91 * @param longName
92 * the long name
93 * @param defaultValue
94 * the default value for this Option
95 */
96 public Option(String description, char shortName, String longName, String defaultValue) {
97 this(description, ArgumentType.NO_ARGUMENT, DataType.BOOLEAN, shortName, longName, defaultValue);
98 }
99
100 /**
101 * Create an Option with a short name, having no default value.
102 *
103 * @param description
104 * the description
105 * @param argumentType
106 * the type of the argument
107 * @param dataType
108 * the type of argument's data
109 * @param shortName
110 * the short name
111 */
112 public Option(String description, ArgumentType argumentType, DataType dataType, char shortName) {
113 this(description, argumentType, dataType, shortName, null, null);
114 }
115
116 /**
117 * Create an Option with a long name, having no default value.
118 *
119 * @param description
120 * the description
121 * @param argumentType
122 * the type of the argument
123 * @param dataType
124 * the type of argument's data
125 * @param longName
126 * the long name
127 */
128 public Option(String description, ArgumentType argumentType, DataType dataType, String longName) {
129 this(description, argumentType, dataType, '\u0000', longName, null);
130 }
131
132 /**
133 * Create an Option with both short and long names, having no default value.
134 *
135 * @param description
136 * the description
137 * @param argumentType
138 * the type of the argument
139 * @param dataType
140 * the type of argument's data
141 * @param shortName
142 * the short name
143 * @param longName
144 * the long name
145 */
146 public Option(String description, ArgumentType argumentType, DataType dataType, char shortName, String longName) {
147 this(description, argumentType, dataType, shortName, longName, null);
148 }
149
150 /**
151 * Create an Option with both short and long names of a given DataType
152 * having a default value.
153 *
154 * @param description
155 * the description
156 * @param argumentType
157 * the type of the argument
158 * @param dataType
159 * the type of argument's data
160 * @param shortName
161 * the short name
162 * @param longName
163 * the long name
164 * @param defaultValue
165 * the default value for this Option
166 */
167 public Option(String description, ArgumentType argumentType, DataType dataType, char shortName, String longName, String defaultValue) {
168 this.description = description;
169 this.argumentType = argumentType;
170 this.dataType = dataType;
171 this.shortName = shortName;
172 this.longName = longName;
173 this.defaultValue = defaultValue;
174 }
175
176 /**
177 * The description provides a brief explanation of the option.
178 *
179 * @return the description
180 */
181 public String getDescription() {
182 return description;
183 }
184
185 /**
186 * The short name of an Option is the single character by which this Option
187 * is known. If it is not set then there is no short name for this Option.
188 *
189 * @return the shortName
190 */
191 public char getShortName() {
192 return shortName;
193 }
194
195 /**
196 * The long name of an Option is the single character by which this Option
197 * is known. If it is not set then there is no long name for this Option.
198 *
199 * @return the longName
200 */
201 public String getLongName() {
202 return longName;
203 }
204
205 /**
206 * The ArgumentType indicates this Option's ability to use a following
207 * argument.
208 *
209 * @return the argumentType
210 */
211 public ArgumentType getArgumentType() {
212 return argumentType;
213 }
214
215 /**
216 * @return the dataType
217 */
218 public DataType getDataType() {
219 return dataType;
220 }
221
222 /**
223 * @return the defaultValue
224 */
225 public String getDefaultValue() {
226 return defaultValue;
227 }
228
229 private String description;
230 private char shortName;
231 private String longName;
232 private DataType dataType;
233 private ArgumentType argumentType;
234 private String defaultValue;
235 }
236