1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.util; |
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | 0 | public class NumberUtils extends org.apache.commons.lang.math.NumberUtils |
18 | |
{ |
19 | |
|
20 | |
public static long toLong(Object obj) |
21 | |
{ |
22 | 0 | if (obj == null) |
23 | |
{ |
24 | 0 | throw new IllegalArgumentException("Unable to convert null object to long"); |
25 | |
} |
26 | 0 | else if (obj instanceof String) |
27 | |
{ |
28 | 0 | return toLong((String) obj); |
29 | |
} |
30 | 0 | else if (obj instanceof Number) |
31 | |
{ |
32 | 0 | return ((Number) obj).longValue(); |
33 | |
} |
34 | |
else |
35 | |
{ |
36 | 0 | throw new IllegalArgumentException("Unable to convert object of type: " |
37 | |
+ obj.getClass().getName() + " to long."); |
38 | |
} |
39 | |
} |
40 | |
|
41 | |
public static int toInt(Object obj) |
42 | |
{ |
43 | 0 | if (obj == null) |
44 | |
{ |
45 | 0 | throw new IllegalArgumentException("Unable to convert null object to int"); |
46 | |
} |
47 | 0 | else if (obj instanceof String) |
48 | |
{ |
49 | 0 | return toInt((String) obj); |
50 | |
} |
51 | 0 | else if (obj instanceof Number) |
52 | |
{ |
53 | 0 | return ((Number) obj).intValue(); |
54 | |
} |
55 | |
else |
56 | |
{ |
57 | 0 | throw new IllegalArgumentException("Unable to convert object of type: " |
58 | |
+ obj.getClass().getName() + " to int."); |
59 | |
} |
60 | |
} |
61 | |
|
62 | |
} |