コード例 #1
0
  public static String getBestDateFormat(List<String> dateSamples) {
    String[] formats = DataTypeDetector.COMMON_DATE_FORMATS;

    ArrayList<FormatterHits> formatters = new ArrayList<FormatterHits>(formats.length);

    for (String format : formats) {
      formatters.add(new FormatterHits(format));
    }

    // try each common format on the sample, counting which one works
    for (String sample : dateSamples) {
      for (FormatterHits fh : formatters) {
        try {
          fh.getFormatter().parseDateTime(sample);
          fh.increment();
        } catch (IllegalArgumentException e) {
          // not a goo one, try the others
        }
      }
    }

    Collections.sort(formatters);
    if (formatters.get(0).getHits() > 0) {
      return formatters.get(0).getFormat();
    } else {
      return null;
    }
  }
コード例 #2
0
 public int compareTo(FormatterHits formatterHits) {
   return formatterHits.getHits().compareTo(hits);
 }