Exemplo n.º 1
0
 @Override
 public int compareTo(StringTuple otherTuple) {
   int thisLength = length();
   int otherLength = otherTuple.length();
   int min = Math.min(thisLength, otherLength);
   for (int i = 0; i < min; i++) {
     int ret = this.tuple.get(i).compareTo(otherTuple.stringAt(i));
     if (ret != 0) {
       return ret;
     }
   }
   if (thisLength < otherLength) {
     return -1;
   } else if (thisLength > otherLength) {
     return 1;
   } else {
     return 0;
   }
 }
Exemplo n.º 2
0
  @Override
  protected void map(Text key, StringTuple value, final Context context)
      throws IOException, InterruptedException {
    HashMap<String, Long> wordCount = new HashMap<String, Long>();
    for (String word : value.getEntries()) {
      if (wordCount.containsKey(word)) {
        wordCount.put(word, wordCount.get(word) + 1);
      } else {
        wordCount.put(word, (long) 1);
      }
    }

    for (Entry<String, Long> entry : wordCount.entrySet()) {
      try {
        context.write(new Text(entry.getKey()), new LongWritable(entry.getValue()));
      } catch (IOException e) {
        context.getCounter("Exception", "Output IO Exception").increment(1);
      } catch (InterruptedException e) {
        context.getCounter("Exception", "Interrupted Exception").increment(1);
      }
    }
  }