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