示例#1
0
 @Override
 protected Object primTransform(Object anObject) throws Exception {
   return format.parse((String) anObject);
 }
 protected Object convert(CsvFieldType fieldType, String string) {
   if (fieldType == null) {
     return string;
   }
   switch (fieldType) {
     case BOOLEAN:
       if (string.length() == 0) {
         return null;
       }
       return Boolean.parseBoolean(string);
     case BYTE:
       if (string.length() == 0) {
         return null;
       }
       return Byte.parseByte(string);
     case SHORT:
       if (string.length() == 0) {
         return null;
       }
       return Short.parseShort(string);
     case INT:
       if (string.length() == 0) {
         return null;
       }
       return Integer.parseInt(string);
     case LONG:
       if (string.length() == 0) {
         return null;
       }
       return Long.parseLong(string);
     case FLOAT:
       if (string.length() == 0) {
         return null;
       }
       return Float.parseFloat(string);
     case DOUBLE:
       if (string.length() == 0) {
         return null;
       }
       return Double.parseDouble(string);
     case DATE:
       if (string.length() == 0) {
         return null;
       }
       try {
         Date date = TIME_FORMAT_DATE.parse(string);
         return new java.sql.Date(date.getTime());
       } catch (ParseException e) {
         return null;
       }
     case TIME:
       if (string.length() == 0) {
         return null;
       }
       try {
         Date date = TIME_FORMAT_TIME.parse(string);
         return new java.sql.Time(date.getTime());
       } catch (ParseException e) {
         return null;
       }
     case TIMESTAMP:
       if (string.length() == 0) {
         return null;
       }
       try {
         Date date = TIME_FORMAT_TIMESTAMP.parse(string);
         return new java.sql.Timestamp(date.getTime());
       } catch (ParseException e) {
         return null;
       }
     case STRING:
     default:
       return string;
   }
 }