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