@Test public void convert2Int(){ System.out.println("START: convert2Int"); Assert.assertEquals(6,LibConvertNumberUtils.convert2Int(i,0)); Assert.assertEquals(8,LibConvertNumberUtils.convert2Int(l,0)); Assert.assertEquals(3,LibConvertNumberUtils.convert2Int(f,0)); Assert.assertEquals(9,LibConvertNumberUtils.convert2Int(d,0)); Assert.assertEquals(0,LibConvertNumberUtils.convert2Int(s1,0)); Assert.assertEquals(10,LibConvertNumberUtils.convert2Int(s2,0)); Assert.assertEquals(11,LibConvertNumberUtils.convert2Int(s3,0)); Assert.assertEquals(20,LibConvertNumberUtils.convert2Int(s4,0)); Assert.assertEquals(30,LibConvertNumberUtils.convert2Int(s5,0)); Assert.assertEquals(0,LibConvertNumberUtils.convert2Int(s6,0)); System.out.println("END: convert2Int"); }
public final static int convert2Int(Object value, int defaultValue) { if (value == null || "".equals(value.toString().trim())) { return defaultValue; } try { return Integer.parseInt(value.toString()); } catch (Exception e) { try { return Double.valueOf(value.toString()).intValue(); } catch (Exception e1) { return defaultValue; } } }
LibConvertNumberUtils { public final static int convert2Int(Object value, int defaultValue) { if (value == null || "".equals(value.toString().trim())) { return defaultValue; } try { return Integer.parseInt(value.toString()); } catch (Exception e) { try { return Double.valueOf(value.toString()).intValue(); } catch (Exception e1) { return defaultValue; } } } }
LibConvertNumberUtils { public final static int convert2Int(Object value, int defaultValue) { if (value == null || "".equals(value.toString().trim())) { return defaultValue; } try { return Integer.parseInt(value.toString()); } catch (Exception e) { try { return Double.valueOf(value.toString()).intValue(); } catch (Exception e1) { return defaultValue; } } }  }
LibConvertNumberUtils { public final static int convert2Int(Object value, int defaultValue) { if (value == null || "".equals(value.toString().trim())) { return defaultValue; } try { return Integer.parseInt(value.toString()); } catch (Exception e) { try { return Double.valueOf(value.toString()).intValue(); } catch (Exception e1) { return defaultValue; } } }  final static int convert2Int(Object value, int defaultValue); final static double convert2Double(Object value, double defaultValue); final static long convert2Long(Object value, long defaultValue); }
LibConvertNumberUtils { public final static int convert2Int(Object value, int defaultValue) { if (value == null || "".equals(value.toString().trim())) { return defaultValue; } try { return Integer.parseInt(value.toString()); } catch (Exception e) { try { return Double.valueOf(value.toString()).intValue(); } catch (Exception e1) { return defaultValue; } } }  final static int convert2Int(Object value, int defaultValue); final static double convert2Double(Object value, double defaultValue); final static long convert2Long(Object value, long defaultValue);  }