File tree Expand file tree Collapse file tree
java/org/apache/commons/cli
test/org/apache/commons/cli Expand file tree Collapse file tree Original file line number Diff line number Diff line change 132132
133133 <dependencies >
134134
135- <!-- used in TypeHandler -->
136- <dependency >
137- <groupId >commons-lang</groupId >
138- <artifactId >commons-lang</artifactId >
139- <version >2.1</version >
140- </dependency >
141-
142135 <!-- used for unit tests -->
143136 <dependency >
144137 <groupId >junit</groupId >
Original file line number Diff line number Diff line change 2727 * <tr><td>b@</td><td>-b [classname]</td></tr>
2828 * <tr><td>c></td><td>-c [filename]</td></tr>
2929 * <tr><td>d+</td><td>-d [classname] (creates object via empty contructor)</td></tr>
30- * <tr><td>e%</td><td>-e [number] (creates Number instance)</td></tr>
30+ * <tr><td>e%</td><td>-e [number] (creates Double/Long instance depeding on existing of a '.' )</td></tr>
3131 * <tr><td>f/</td><td>-f [url]</td></tr>
3232 * <tr><td>g:</td><td>-g [string]</td></tr>
3333 * </table>
Original file line number Diff line number Diff line change 2222
2323import java .util .Date ;
2424
25- import org .apache .commons .lang .math .NumberUtils ;
26-
2725/**
2826 * This is a temporary implementation. TypeHandler will handle the
2927 * pluggableness of OptionTypes and it will direct all of these types
@@ -149,26 +147,35 @@ public static Object createObject(String str)
149147 }
150148
151149 /**
152- * <p>Create a number from a String.</p>
150+ * <p>Create a number from a String. If a . is present, it creates a
151+ * Double, otherwise a Long. </p>
153152 *
154153 * @param str the value
155154 * @return the number represented by <code>str</code>, if <code>str</code>
156155 * is not a number, null is returned.
157156 */
158157 public static Number createNumber (String str )
159158 {
160- // Needs to be able to create
161159 try
162160 {
163- // do searching for decimal point etc, but atm just make an Integer
164- return NumberUtils .createNumber (str );
161+ if ( str != null )
162+ {
163+ if ( str .indexOf ('.' ) != -1 )
164+ {
165+ return Double .valueOf (str );
166+ }
167+ else
168+ {
169+ return Long .valueOf (str );
170+ }
171+ }
165172 }
166173 catch (NumberFormatException nfe )
167174 {
168175 System .err .println (nfe .getMessage ());
169-
170- return null ;
171176 }
177+
178+ return null ;
172179 }
173180
174181 /**
@@ -254,4 +261,4 @@ public static File[] createFiles(String str)
254261 // return FileW.findFiles(str);
255262 return null ;
256263 }
257- }
264+ }
Original file line number Diff line number Diff line change @@ -67,8 +67,8 @@ public void testSimplePattern()
6767 assertEquals ("file flag e" , new java .io .File ("build.xml" ), line .getOptionObject ('e' ));
6868 assertEquals ("class flag f" , java .util .Calendar .class , line .getOptionObject ("f" ));
6969 assertEquals ("class flag f" , java .util .Calendar .class , line .getOptionObject ('f' ));
70- assertEquals ("number flag n" , new Float (4.5 ), line .getOptionObject ("n" ));
71- assertEquals ("number flag n" , new Float (4.5 ), line .getOptionObject ('n' ));
70+ assertEquals ("number flag n" , new Double (4.5 ), line .getOptionObject ("n" ));
71+ assertEquals ("number flag n" , new Double (4.5 ), line .getOptionObject ('n' ));
7272 assertEquals ("url flag t" , new java .net .URL ("http://jakarta.apache.org/" ), line .getOptionObject ("t" ));
7373 assertEquals ("url flag t" , new java .net .URL ("http://jakarta.apache.org/" ), line .getOptionObject ('t' ));
7474 /// DATES NOT SUPPORTED YET.
You can’t perform that action at this time.
0 commit comments