Repository navigation
Expand file tree
/
Copy pathMyKeyPair.java
More file actions
84 lines (69 loc) · 1.58 KB
/
Copy pathMyKeyPair.java
File metadata and controls
84 lines (69 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package temperature;
import org.apache.hadoop.io.WritableComparable;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class MyKeyPair implements WritableComparable<MyKeyPair>
{
private int year;
private int temperature;
public int getTemperature()
{
return temperature;
}
public void setTemperature(int temperature)
{
this.temperature = temperature;
}
public int getYear()
{
return year;
}
public void setYear(int year)
{
this.year = year;
}
//重写三个方法
@Override
public int compareTo(MyKeyPair o)
{
int iRet = Integer.compare(year, o.getYear());
if (iRet != 0)
return iRet;
return Integer.compare(temperature, o.getTemperature());
}
/**
* 使用RPC协议读取二进制流,序列化过程
*
* @param out
* @throws IOException
*/
@Override
public void write(DataOutput out) throws IOException
{
out.writeInt(year);
out.writeInt(temperature);
}
/**
* 使用RPC协议读取二进制流,反序列化过程
*
* @param in
* @throws IOException
*/
@Override
public void readFields(DataInput in) throws IOException
{
this.year = in.readInt();
this.temperature = in.readInt();
}
@Override
public String toString()
{
return year + "\t" + temperature;
}
@Override
public int hashCode()
{
return new Integer(year + temperature).hashCode();
}
}