@SuppressWarnings("rawtypes") public Object convert(Class destClass, Object srcObj) { // Boolean to Int not supported in apache common's int converter and this is why this class is req'd if (Boolean.class.isAssignableFrom(srcObj.getClass())) { boolean value = (Boolean)srcObj; return value ? 1 : 0; } else if (MappingUtils.isEnumType(srcObj.getClass())) { return ((Enum)srcObj).ordinal(); } else { return commonsConverter.convert(destClass, srcObj); } } }
long count = 0; for (int i = 0; i < 100000000; i++) { Integer o = (Integer) c.convert(Integer.class, data); count += o.hashCode();
public Object convert(Class destClass, Object srcObj) { // Boolean to Int not supported in apache common's int converter and // this is why this class is req'd if (Boolean.class.isAssignableFrom(srcObj.getClass())) { boolean value = (Boolean) srcObj; return (value ? 1 : 0); } else { return commonsConverter.convert(destClass, srcObj); } }
@SuppressWarnings("rawtypes") public Object convert(Class destClass, Object srcObj) { // Boolean to Int not supported in apache common's int converter and this is why this class is req'd if (Boolean.class.isAssignableFrom(srcObj.getClass())) { boolean value = (Boolean) srcObj; return (value ? 1 : 0); } else if (MappingUtils.isEnumType(srcObj.getClass())) { return ((Enum) srcObj).ordinal(); } else { return commonsConverter.convert(destClass, srcObj); } }
@SuppressWarnings("rawtypes") public Object convert(Class destClass, Object srcObj) { // Boolean to Int not supported in apache common's int converter and this is why this class is req'd if (Boolean.class.isAssignableFrom(srcObj.getClass())) { boolean value = (Boolean)srcObj; return value ? 1 : 0; } else if (MappingUtils.isEnumType(srcObj.getClass())) { return ((Enum)srcObj).ordinal(); } else { return commonsConverter.convert(destClass, srcObj); } } }
public Object convert(Class type, Object value) { String string = (String) value; // wipe out white space, converters would fail trying to // parse "153 " just because of the trailing space if(string != null) string = string.trim(); Number parsed = null; try { //first try integer parsed = (Number) new IntegerConverter().convert(Integer.class, string); } catch(Exception e) {} if ( parsed == null ) { //try double parsed = (Number) new DoubleConverter().convert(Double.class,string); } return parsed; }; };