Skip to content

Commit d35f2fa

Browse files
committed
Removing the Commons Lang dependency. This removes certain obscure number formats as being parseable by the PatternOptionBuilder, but I suspect they don't matter.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/branches/cli-1.0.x@542140 13f79535-47bb-0310-9956-ffa450edef68
1 parent 85248e8 commit d35f2fa

4 files changed

Lines changed: 19 additions & 19 deletions

File tree

project.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@
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>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* <tr><td>b@</td><td>-b [classname]</td></tr>
2828
* <tr><td>c&gt;</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>

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
import 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+
}

src/test/org/apache/commons/cli/PatternOptionBuilderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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.

0 commit comments

Comments
 (0)