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