KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > util > NumberUtils


1 /*
2  * $Id: NumberUtils.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.util;
12
13 /**
14  * <code>NumberUtils</code> contains useful methods for manipulating numbers.
15  */

16 // @ThreadSafe
17
public class NumberUtils extends org.apache.commons.lang.math.NumberUtils
18 {
19
20     public static long toLong(Object JavaDoc obj)
21     {
22         if (obj == null)
23         {
24             throw new IllegalArgumentException JavaDoc("Unable to convert null object to long");
25         }
26         else if (obj instanceof String JavaDoc)
27         {
28             return toLong((String JavaDoc)obj);
29         }
30         else if (obj instanceof Number JavaDoc)
31         {
32             return ((Number JavaDoc)obj).longValue();
33         }
34         else
35         {
36             throw new IllegalArgumentException JavaDoc("Unable to convert object of type: "
37                                                + obj.getClass().getName() + " to long.");
38         }
39     }
40
41 }
42
Popular Tags