public NumberField(Form form, Parameter parameter) {
    super(form, parameter);

    Class<?> type = parameter.getValueType();

    if (Byte.class.equals(type)) {
      setConvertor(
          new Convertor<String>() {
            public Object convert(String text) throws Exception {
              return Byte.parseByte(text);
            }
          });
    } else if (Double.class.equals(type)) {
      setConvertor(
          new Convertor<String>() {
            public Object convert(String text) throws Exception {
              return Double.parseDouble(text);
            }
          });
    } else if (Float.class.equals(type)) {
      setConvertor(
          new Convertor<String>() {
            public Object convert(String text) throws Exception {
              return Float.parseFloat(text);
            }
          });
    } else if (Integer.class.equals(type)) {
      setConvertor(
          new Convertor<String>() {
            public Object convert(String text) throws Exception {
              return Integer.parseInt(text);
            }
          });
    } else if (Long.class.equals(type)) {
      setConvertor(
          new Convertor<String>() {
            public Object convert(String text) throws Exception {
              return Long.parseLong(text);
            }
          });
    } else if (Short.class.equals(type)) {
      setConvertor(
          new Convertor<String>() {
            public Object convert(String text) throws Exception {
              return Short.parseShort(text);
            }
          });
    }
  }
Beispiel #2
0
 public static void load() {
   if (FileHelper.isDirectoryExist(dataDir)) {
     DbBase.clearDatabase(Parameter.getInstance().getDbDatabase());
     total = progress = 0;
     try {
       String[] filenames = new File(dataDir).list();
       for (String filename : filenames) {
         total += FileHelper.countLines(dataDir + "/" + filename);
         DbBase.createTable(filename);
       }
       for (String filename : filenames) {
         load(filename);
       }
     } catch (IOException e) {
       e.printStackTrace();
     }
   } else {
     Log.error("can not find data directory");
   }
   total = progress = 0;
 }