1
|
package eu.dnetlib.data.mapreduce.hbase.dedup.kv;
|
2
|
|
3
|
import java.io.DataInput;
|
4
|
import java.io.DataOutput;
|
5
|
import java.io.IOException;
|
6
|
|
7
|
import com.google.common.collect.ComparisonChain;
|
8
|
import org.apache.hadoop.io.IntWritable;
|
9
|
import org.apache.hadoop.io.Text;
|
10
|
import org.apache.hadoop.io.WritableComparable;
|
11
|
|
12
|
/**
|
13
|
* Created by claudio on 13/03/2017.
|
14
|
*/
|
15
|
public class DNGFKey implements WritableComparable<DNGFKey> {
|
16
|
|
17
|
public final static int MERGES_REL = 0;
|
18
|
public final static int OTHER_REL = 1;
|
19
|
|
20
|
private IntWritable keyType;
|
21
|
|
22
|
private Text id;
|
23
|
|
24
|
public DNGFKey() {}
|
25
|
|
26
|
public DNGFKey(final int keyType, final String id) {
|
27
|
this.id = new Text(id);
|
28
|
this.keyType = new IntWritable(keyType);
|
29
|
}
|
30
|
|
31
|
public static DNGFKey create(final int keyType, final String id) {
|
32
|
return new DNGFKey(keyType, id);
|
33
|
}
|
34
|
|
35
|
public static DNGFKey mergesRel(final String id) {
|
36
|
return new DNGFKey(MERGES_REL, id);
|
37
|
}
|
38
|
|
39
|
public static DNGFKey otherRel(final String id) {
|
40
|
return new DNGFKey(OTHER_REL, id);
|
41
|
}
|
42
|
|
43
|
public Text getId() {
|
44
|
return id;
|
45
|
}
|
46
|
|
47
|
public void setId(final Text id) {
|
48
|
this.id = id;
|
49
|
}
|
50
|
|
51
|
public IntWritable getKeyType() {
|
52
|
return keyType;
|
53
|
}
|
54
|
|
55
|
public void setKeyType(final IntWritable keyType) {
|
56
|
this.keyType = keyType;
|
57
|
}
|
58
|
|
59
|
@Override
|
60
|
public int compareTo(final DNGFKey o) {
|
61
|
return ComparisonChain.start()
|
62
|
.compare(getKeyType(), o.getKeyType())
|
63
|
.compare(getId(), o.getId())
|
64
|
.result();
|
65
|
}
|
66
|
|
67
|
@Override
|
68
|
public void write(final DataOutput out) throws IOException {
|
69
|
keyType.write(out);
|
70
|
id.write(out);
|
71
|
}
|
72
|
|
73
|
@Override
|
74
|
public void readFields(final DataInput in) throws IOException {
|
75
|
keyType = new IntWritable();
|
76
|
keyType.readFields(in);
|
77
|
id = new Text();
|
78
|
id.readFields(in);
|
79
|
}
|
80
|
|
81
|
@Override
|
82
|
public String toString() {
|
83
|
return (new StringBuilder())
|
84
|
.append('{')
|
85
|
.append(getKeyType().get())
|
86
|
.append(',')
|
87
|
.append(getId())
|
88
|
.append('}')
|
89
|
.toString();
|
90
|
}
|
91
|
}
|