Exemplo n.º 1
0
  public static void main(String[] args) {
    Date start = new Date();
    if (args.length < 3) {
      System.out.println("Wrong number of arguments:\n" + USAGE);
      return;
    }

    // get # threads
    int tc = Integer.parseInt(args[0]);
    String outfile = args[1];

    // make a threadsafe queue of all files to process
    ConcurrentLinkedQueue<String> files = new ConcurrentLinkedQueue<String>();
    for (int i = 2; i < args.length; i++) {
      files.add(args[i]);
    }

    // hastable for results
    Hashtable<String, Integer> results = new Hashtable<String, Integer>(HASH_SIZE, LF);

    // spin up the threads
    Thread[] workers = new Thread[tc];
    for (int i = 0; i < tc; i++) {
      workers[i] = new Worker(files, results);
      workers[i].start();
    }

    // wait for them to finish
    try {
      for (int i = 0; i < tc; i++) {
        workers[i].join();
      }
    } catch (Exception e) {
      System.out.println("Caught Exception: " + e.getMessage());
    }

    // terminal output
    Date end = new Date();
    System.out.println(end.getTime() - start.getTime() + " total milliseconds");
    System.out.println(results.size() + " unique words");

    // sort results for easy comparison/verification
    List<Map.Entry<String, Integer>> sorted_results =
        new ArrayList<Map.Entry<String, Integer>>(results.entrySet());
    Collections.sort(sorted_results, new KeyComp());
    // file output
    try {
      PrintStream out = new PrintStream(outfile);
      for (int i = 0; i < sorted_results.size(); i++) {
        out.println(sorted_results.get(i).getKey() + "\t" + sorted_results.get(i).getValue());
      }
    } catch (Exception e) {
      System.out.println("Caught Exception: " + e.getMessage());
    }
  }
Exemplo n.º 2
0
  private static boolean compareDateStrings(
      String value1, String value2, String operator, String pattern) {
    if (value1 == null || value2 == null) {
      return false;
    }

    String datePattern = pattern;

    if (pattern == null) {
      datePattern = "yyyy-MM-dd HH:mm:ss.S";
    }
    long time1;
    long time2;

    DateFormat dateFormat = new SimpleDateFormat(datePattern);
    try {
      Date date1 = dateFormat.parse(value1);
      Date date2 = dateFormat.parse(value2);
      time1 = date1.getTime();
      time2 = date2.getTime();
    } catch (ParseException pe) {
      return false;
    }

    if ("=".equals(operator)) {
      return time1 == time2;
    } else if (">".equals(operator)) {
      return time1 > time2;
    } else if ("<".equals(operator)) {
      return time1 < time2;
    } else if (">=".equals(operator)) {
      return time1 >= time2;
    } else if ("<=".equals(operator)) {
      return time1 <= time2;
    }
    return false;
  }
Exemplo n.º 3
0
 protected int putDate(String name, Date d) {
   int start = _buf.position();
   _put(DATE, name);
   _buf.putLong(d.getTime());
   return _buf.position() - start;
 }
Exemplo n.º 4
0
 protected void putDate(String name, Date d) {
   _put(DATE, name);
   _buf.writeLong(d.getTime());
 }