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