Skip to content

Commit 7e3bcff

Browse files
author
John Keyes
committed
javadoc and checkstyle fixes
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@129782 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5e98762 commit 7e3bcff

6 files changed

Lines changed: 185 additions & 41 deletions

File tree

project.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ maven.jarResources.basedir=${basedir}/src/java
1010

1111
# coding standards
1212

13+
maven.checkstyle.rcurly = ignore
1314
maven.checkstyle.lcurly.type = ignore
1415
maven.checkstyle.lcurly.method = ignore
1516
maven.checkstyle.lcurly.other = ignore

src/java/org/apache/commons/cli/CommandLine.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,19 @@ public boolean hasOption(String opt) {
108108
return options.containsKey( opt );
109109
}
110110

111+
/**
112+
* @param opt the name of the option
113+
* @return the type of opt
114+
*/
111115
public Object getOptionObject(String opt) {
112-
String[] result = (String[])options.get( opt );
116+
String res = getOptionValue( opt );
113117
Object type = types.get( opt );
114-
String res = result == null ? null : result[0];
115-
if(res == null) {
116-
return null;
117-
}
118-
return TypeHandler.createValue(res, type);
118+
return res == null ? null : TypeHandler.createValue(res, type);
119119
}
120120

121121
/** <p>Retrieve the argument, if any, of an option.</p>
122122
*
123-
* @param opt Short single-character name of the option
123+
* @param opt the name of the option
124124
* @return Value of the argument if option is set, and has an argument, else null.
125125
*/
126126
public String getOptionValue(String opt) {

src/java/org/apache/commons/cli/HelpFormatter.java

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,64 @@
11
/*
2-
* Copyright (C) The Apache Software Foundation. All rights reserved.
2+
* $Header: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli/CommandLine.java,v 1.4 2002/06/06 22:32:37 bayard Exp $
3+
* $Revision: 1.4 $
4+
* $Date: 2002/06/06 22:32:37 $
5+
*
6+
* ====================================================================
7+
*
8+
* The Apache Software License, Version 1.1
9+
*
10+
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
11+
* reserved.
12+
*
13+
* Redistribution and use in source and binary forms, with or without
14+
* modification, are permitted provided that the following conditions
15+
* are met:
16+
*
17+
* 1. Redistributions of source code must retain the above copyright
18+
* notice, this list of conditions and the following disclaimer.
19+
*
20+
* 2. Redistributions in binary form must reproduce the above copyright
21+
* notice, this list of conditions and the following disclaimer in
22+
* the documentation and/or other materials provided with the
23+
* distribution.
24+
*
25+
* 3. The end-user documentation included with the redistribution, if
26+
* any, must include the following acknowlegement:
27+
* "This product includes software developed by the
28+
* Apache Software Foundation (http://www.apache.org/)."
29+
* Alternately, this acknowlegement may appear in the software itself,
30+
* if and wherever such third-party acknowlegements normally appear.
31+
*
32+
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
33+
* Foundation" must not be used to endorse or promote products derived
34+
* from this software without prior written permission. For written
35+
* permission, please contact apache@apache.org.
36+
*
37+
* 5. Products derived from this software may not be called "Apache"
38+
* nor may "Apache" appear in their names without prior written
39+
* permission of the Apache Group.
40+
*
41+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
42+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44+
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
45+
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
48+
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
51+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52+
* SUCH DAMAGE.
53+
* ====================================================================
54+
*
55+
* This software consists of voluntary contributions made by many
56+
* individuals on behalf of the Apache Software Foundation. For more
57+
* information on the Apache Software Foundation, please see
58+
* <http://www.apache.org/>.
359
*
4-
* This software is published under the terms of the Apache Software License
5-
* version 1.1, a copy of which has been included with this distribution in
6-
* the LICENSE file.
7-
*
8-
* $Id: HelpFormatter.java,v 1.2 2002/05/17 11:44:32 jstrachan Exp $
960
*/
61+
1062
package org.apache.commons.cli;
1163

1264
import java.io.PrintWriter;

src/java/org/apache/commons/cli/Option.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,24 @@ public Option(String opt, String longOpt, boolean hasArg, String description,
192192
this.type = type;
193193
}
194194

195-
/** <p>Retrieve the single-character name of this Option</p>
195+
/** <p>Retrieve the name of this Option</p>
196196
*
197197
* <p>It is this character which can be used with
198198
* {@link CommandLine#hasOption(String opt)} and
199199
* {@link CommandLine#getOptionValue(String opt)} to check
200200
* for existence and argument.<p>
201201
*
202-
* @return Single character name of this option
202+
* @return The name of this option
203203
*/
204204
public String getOpt() {
205205
return this.opt;
206206
}
207207

208+
/**
209+
* <p>Retrieve the type of this Option</p>
210+
*
211+
* @return The type of this option
212+
*/
208213
public Object getType() {
209214
return this.type;
210215
}

src/java/org/apache/commons/cli/PatternOptionBuilder.java

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,36 @@ public class PatternOptionBuilder {
7272

7373
/// TODO: These need to break out to OptionType and also to be pluggable.
7474

75-
static public final Class STRING_VALUE = java.lang.String.class;
76-
static public final Class OBJECT_VALUE = java.lang.Object.class;
77-
static public final Class NUMBER_VALUE = java.lang.Number.class;
78-
static public final Class DATE_VALUE = java.util.Date.class;
79-
static public final Class CLASS_VALUE = java.lang.Class.class;
75+
/** String class */
76+
public static final Class STRING_VALUE = java.lang.String.class;
77+
/** Object class */
78+
public static final Class OBJECT_VALUE = java.lang.Object.class;
79+
/** Number class */
80+
public static final Class NUMBER_VALUE = java.lang.Number.class;
81+
/** Date class */
82+
public static final Class DATE_VALUE = java.util.Date.class;
83+
/** Class class */
84+
public static final Class CLASS_VALUE = java.lang.Class.class;
8085

8186
/// can we do this one??
8287
// is meant to check that the file exists, else it errors.
8388
// ie) it's for reading not writing.
84-
static public final Class EXISTING_FILE_VALUE = java.io.FileInputStream.class;
85-
static public final Class FILE_VALUE = java.io.File.class;
86-
static public final Class FILES_VALUE = java.io.File[].class;
87-
static public final Class URL_VALUE = java.net.URL.class;
89+
/** FileInputStream class */
90+
public static final Class EXISTING_FILE_VALUE = java.io.FileInputStream.class;
91+
/** File class */
92+
public static final Class FILE_VALUE = java.io.File.class;
93+
/** File array class */
94+
public static final Class FILES_VALUE = java.io.File[].class;
95+
/** URL class */
96+
public static final Class URL_VALUE = java.net.URL.class;
8897

89-
static public Object getValueClass(char ch) {
98+
/**
99+
* <p>Retrieve the class that <code>ch</code> represents.</p>
100+
*
101+
* @param ch the specified character
102+
* @return The class that <code>ch</code> represents
103+
*/
104+
public static Object getValueClass(char ch) {
90105
if (ch == '@') {
91106
return PatternOptionBuilder.OBJECT_VALUE;
92107
} else if (ch == ':') {
@@ -109,7 +124,14 @@ static public Object getValueClass(char ch) {
109124
return null;
110125
}
111126

112-
static public boolean isValueCode(char ch) {
127+
/**
128+
* <p>Returns whether <code>ch</code> is a value code, i.e.
129+
* whether it represents a class in a pattern.</p>
130+
*
131+
* @param ch the specified character
132+
* @return true if <code>ch</code> is a value code, otherwise false.
133+
*/
134+
public static boolean isValueCode(char ch) {
113135
if( (ch != '@') &&
114136
(ch != ':') &&
115137
(ch != '%') &&
@@ -126,7 +148,14 @@ static public boolean isValueCode(char ch) {
126148
return true;
127149
}
128150

129-
static public Options parsePattern(String pattern) {
151+
/**
152+
* <p>Returns the {@link Options} instance represented by
153+
* <code>pattern</code>.</p>
154+
*
155+
* @param pattern the pattern string
156+
* @return The {@link Options} instance
157+
*/
158+
public static Options parsePattern(String pattern) {
130159
int sz = pattern.length();
131160

132161
char opt = ' ';

src/java/org/apache/commons/cli/TypeHandler.java

Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,29 @@
7979
*/
8080
public class TypeHandler {
8181

82-
static public Object createValue(String str, Object obj) {
82+
/**
83+
* <p>Returns the <code>Object</code> of type <code>obj</code>
84+
* with the value of <code>str</code>.</p>
85+
*
86+
* @param str the command line value
87+
* @param obj the type of argument
88+
* @return The instance of <code>obj</code> initialised with
89+
* the value of <code>str</code>.
90+
*/
91+
public static Object createValue(String str, Object obj) {
8392
return createValue(str, (Class)obj);
8493
}
85-
static public Object createValue(String str, Class clazz) {
94+
95+
/**
96+
* <p>Returns the <code>Object</code> of type <code>clazz</code>
97+
* with the value of <code>str</code>.</p>
98+
*
99+
* @param str the command line value
100+
* @param clazz the type of argument
101+
* @return The instance of <code>clazz</code> initialised with
102+
* the value of <code>str</code>.
103+
*/
104+
public static Object createValue(String str, Class clazz) {
86105
if( PatternOptionBuilder.STRING_VALUE == clazz) {
87106
return str;
88107
} else
@@ -115,10 +134,12 @@ static public Object createValue(String str, Class clazz) {
115134
}
116135

117136
/**
118-
* Create an Object from the classname and empty constructor.
119-
* Returns null if it couldn't create the Object.
137+
* <p>Create an Object from the classname and empty constructor.</p>
138+
*
139+
* @param str the argument value
140+
* @return the initialised object, or null if it couldn't create the Object.
120141
*/
121-
static public Object createObject(String str) {
142+
public static Object createObject(String str) {
122143
Class cl = null;
123144
try {
124145
cl = Class.forName(str);
@@ -132,7 +153,7 @@ static public Object createObject(String str) {
132153
try {
133154
instance = cl.newInstance();
134155
} catch (InstantiationException cnfe) {
135-
System.err.println("InstantiationException; Unable to create: "+str);
156+
System.err.println("InstantiationException; Unable to create: "+str);
136157
return null;
137158
}
138159
catch (IllegalAccessException cnfe) {
@@ -144,9 +165,13 @@ static public Object createObject(String str) {
144165
}
145166

146167
/**
147-
* Create a number from a String.
148-
*/
149-
static public Number createNumber(String str) {
168+
* <p>Create a number from a String.</p>
169+
*
170+
* @param str the value
171+
* @return the number represented by <code>str</code>, if <code>str</code>
172+
* is not a number, null is returned.
173+
*/
174+
public static Number createNumber(String str) {
150175
// Needs to be able to create
151176
try {
152177
// do searching for decimal point etc, but atm just make an Integer
@@ -157,7 +182,13 @@ static public Number createNumber(String str) {
157182
}
158183
}
159184

160-
static public Class createClass(String str) {
185+
/**
186+
* <p>Returns the class whose name is <code>str</code>.</p>
187+
*
188+
* @param str the class name
189+
* @return The class if it is found, otherwise return null
190+
*/
191+
public static Class createClass(String str) {
161192
try {
162193
return Class.forName(str);
163194
} catch (ClassNotFoundException cnfe) {
@@ -166,15 +197,29 @@ static public Class createClass(String str) {
166197
}
167198
}
168199

169-
static public Date createDate(String str) {
200+
/**
201+
* <p>Returns the date represented by <code>str</code>.</p>
202+
*
203+
* @param str the date string
204+
* @return The date if <code>str</code> is a valid date string,
205+
* otherwise return null.
206+
*/
207+
public static Date createDate(String str) {
170208
Date date = null;
171209
if(date == null) {
172210
System.err.println("Unable to parse: "+str);
173211
}
174212
return date;
175213
}
176214

177-
static public URL createURL(String str) {
215+
/**
216+
* <p>Returns the URL represented by <code>str</code>.</p>
217+
*
218+
* @param str the URL string
219+
* @return The URL is <code>str</code> is well-formed, otherwise
220+
* return null.
221+
*/
222+
public static URL createURL(String str) {
178223
try {
179224
return new URL(str);
180225
} catch (MalformedURLException mue) {
@@ -183,11 +228,23 @@ static public URL createURL(String str) {
183228
}
184229
}
185230

186-
static public File createFile(String str) {
231+
/**
232+
* <p>Returns the File represented by <code>str</code>.</p>
233+
*
234+
* @param str the File location
235+
* @return The file represented by <code>str</code>.
236+
*/
237+
public static File createFile(String str) {
187238
return new File(str);
188239
}
189240

190-
static public File[] createFiles(String str) {
241+
/**
242+
* <p>Returns the File[] represented by <code>str</code>.</p>
243+
*
244+
* @param str the paths to the files
245+
* @return The File[] represented by <code>str</code>.
246+
*/
247+
public static File[] createFiles(String str) {
191248
// to implement/port:
192249
// return FileW.findFiles(str);
193250
return null;

0 commit comments

Comments
 (0)