hadoop 自定义TextPair和使用原理
1.hadoop TextPair组合键定义
package Temperature; import org.apache.hadoop.io.Text; import org.apache.hadoop.io.WritableComparable; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; public class TextPair implements WritableComparable<TextPair> { private Text first; private Text second; public TextPair() { set(new Text(),new Text());//基本类型int,long等可以不用初始化,但是对象类型变量一定要new,因为反序列化是要读取数据到first和second,会出现空指针引用的问题。 } public TextPair(String first, String second) { set(new Text(first),new Text(second)); } public TextPair(Text first, Text second) { set(first, second); } public void set(Text first, Text second) { this.first = first; this.second = second; } public Text getFirst() { return first; } public Text getSecond() { return second; } @Override public void write(DataOutput out)throws IOException { first.write(out); second.write(out); } @Override public void readFields(DataInput in)throws IOException { first.readFields(in); second.readFields(in); } @Override public int hashCode() { return first.hashCode() *163+ second.hashCode(); } @Override public boolean equals(Object o) { if(o instanceof TextPair) { TextPair tp = (TextPair) o; return first.equals(tp.first) && second.equals(tp.second); } return false; } @Override public String toString() { return first +"\t"+ second; } public int compareTo(TextPair tp) { int cmp = first.compareTo(tp.first); if(cmp !=0) { return cmp; } return second.compareTo(tp.second); } }
具体使用实例见我的下一篇博客
https://www.cnblogs.com/bclshuai/p/12319490.html
自己开发了一个股票智能分析软件,功能很强大,需要的点击下面的链接获取:
相关推荐
changjiang 2020-11-16
minerd 2020-10-28
WeiHHH 2020-09-23
Aleks 2020-08-19
WeiHHH 2020-08-17
飞鸿踏雪0 2020-07-26
tomli 2020-07-26
deyu 2020-07-21
strongyoung 2020-07-19
eternityzzy 2020-07-19
Elmo 2020-07-19
飞鸿踏雪0 2020-07-09
飞鸿踏雪0 2020-07-04
xieting 2020-07-04
WeiHHH 2020-06-28
genshengxiao 2020-06-26
Hhanwen 2020-06-25