Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
courses:mapreduce-tutorial:step-27 [2012/01/28 18:57] straka |
courses:mapreduce-tutorial:step-27 [2012/01/28 20:02] straka |
||
---|---|---|---|
Line 10: | Line 10: | ||
<code java> | <code java> | ||
- | public | + | public class BERIntWritable implements Writable { |
private int value; | private int value; | ||
Line 40: | Line 40: | ||
} | } | ||
</ | </ | ||
+ | Remark: If the '' | ||
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:// | 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:// | ||
Line 75: | Line 76: | ||
public void setFirst(A first) { this.first = first; } | public void setFirst(A first) { this.first = first; } | ||
public void setSecond(B first) { this.second = second; } | public void setSecond(B first) { this.second = second; } | ||
+ | public String toString() { return String.format(" | ||
public PairWritable(A first, B second) { this.first = first; this.second = second; } | public PairWritable(A first, B second) { this.first = first; this.second = second; } | ||
} | } | ||
</ | </ | ||
+ | Remark: Remark: If the '' | ||
+ | |||
+ | We did not define '' | ||
+ | <code java> | ||
+ | public static class PairWritableComparable< | ||
+ | private A first; | ||
+ | private B second; | ||
+ | |||
+ | public void readFields(DataInput in) throws IOException { | ||
+ | first.readFields(in); | ||
+ | second.readFields(in); | ||
+ | } | ||
+ | |||
+ | public void write(DataOutput out) throws IOException { | ||
+ | first.write(out); | ||
+ | second.write(out); | ||
+ | } | ||
+ | |||
+ | public int compareTo(Object other) { | ||
+ | PairWritableComparable< | ||
+ | int cmpFirst = first.compareTo(otherPair.getFirst()); | ||
+ | if (cmpFirst < 0) return -1; | ||
+ | if (cmpFirst > 0) return 1; | ||
+ | return second.compareTo(otherPair.getSecond()); | ||
+ | } | ||
+ | |||
+ | public A getFirst() { return first; } | ||
+ | public B getSecond() { return second; } | ||
+ | public void setFirst(A first) { this.first = first; } | ||
+ | public void setSecond(B first) { this.second = second; } | ||
+ | public String toString() { return String.format(" | ||
+ | public PairWritableComparable(A first, B second) { this.first = first; this.second = second; } | ||
+ | } | ||
+ | </ | ||
+ | Remark: If the '' | ||