(Object number)
| 2416 | /// |
| 2417 | /// an int value or an exception |
| 2418 | public static int toIntValue(Object number) { |
| 2419 | if (number == null) { |
| 2420 | return 0; |
| 2421 | } |
| 2422 | // we should convert this to use Number |
| 2423 | if (number instanceof Integer) { |
| 2424 | return ((Integer) number).intValue(); |
| 2425 | } |
| 2426 | if (number instanceof String) { |
| 2427 | String n = (String) number; |
| 2428 | if (n.length() == 0 || " ".equals(n)) { |
| 2429 | return 0; |
| 2430 | } |
| 2431 | return Integer.parseInt(n); |
| 2432 | } |
| 2433 | if (number instanceof Double) { |
| 2434 | return ((Double) number).intValue(); |
| 2435 | } |
| 2436 | if (number instanceof Float) { |
| 2437 | return ((Float) number).intValue(); |
| 2438 | } |
| 2439 | if (number instanceof Long) { |
| 2440 | return ((Long) number).intValue(); |
| 2441 | } |
| 2442 | /*if(number instanceof Short) { |
| 2443 | return ((Short)number).intValue(); |
| 2444 | } |
| 2445 | if(number instanceof Byte) { |
| 2446 | return ((Byte)number).intValue(); |
| 2447 | }*/ |
| 2448 | if (number instanceof Boolean) { |
| 2449 | Boolean b = (Boolean) number; |
| 2450 | if (b.booleanValue()) { |
| 2451 | return 1; |
| 2452 | } |
| 2453 | return 0; |
| 2454 | } |
| 2455 | throw new IllegalArgumentException("Not a number: " + number); |
| 2456 | } |
| 2457 | |
| 2458 | /// Returns the number object as a long |
| 2459 | /// |
no test coverage detected