[ Skip to the content ]

Institute of Formal and Applied Linguistics Wiki


[ Back to the navigation ]

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
courses:mapreduce-tutorial:step-27 [2012/01/28 18:34]
straka
courses:mapreduce-tutorial:step-27 [2012/01/28 18:45]
straka
Line 33: Line 33:
   }   }
 </code> </code>
-Some accessory methods are also needed in order to work with the value:+Accessory methods ''get'' and ''set'' are needed in order to work with the value. Also we override ''toString'', which is used by Hadoop when writing to plain text files.
 <code java> <code java>
   public int get() { return value; }   public int get() { return value; }
   public void set(int value) { this.value = value; }   public void set(int value) { this.value = value; }
 +  public String toString() { return String.valueOf(value); }
 +}
 +</code>
 +
 +Such implementation can be used as a type of //values//. If we wanted to use it as a type of //keys//, we need to implement [[http://hadoop.apache.org/common/docs/r1.0.0/api/org/apache/hadoop/io/WritableComparable.html|WritableComparable]] instead of just ''Writable''. It is enough to add ''compareTo'' method to current implementation:
 +<code java>
 +  public class BERIntWritable implements WritableComparable {
 +  ... //Same as before
 +
 +  public int compareTo(Object other) {
 +    int otherValue = ((BERIntWritable)other).get();
 +    return value < otherValue ? -1 : (value == otherValue ? 0 : 1);
 +  }
 +}
 </code> </code>
  
 ===== PairWritable<A, B> ===== ===== PairWritable<A, B> =====
  

[ Back to the navigation ] [ Back to the content ]