1
|
package eu.dnetlib.data.mapreduce.util;
|
2
|
|
3
|
import eu.dnetlib.data.proto.TypeProtos.Type;
|
4
|
import org.apache.commons.lang3.StringUtils;
|
5
|
import org.apache.commons.logging.Log;
|
6
|
import org.apache.commons.logging.LogFactory;
|
7
|
|
8
|
public class DNGFRowKeyDecoder {
|
9
|
|
10
|
public final static String ID_REGEX = "^[0-9][0-9]\\|.{12}::[a-zA-Z0-9]{32}$";
|
11
|
/**
|
12
|
* logger.
|
13
|
*/
|
14
|
private static final Log log = LogFactory.getLog(DNGFRowKeyDecoder.class); // NOPMD by marko on 11/24/08 5:02 PM
|
15
|
private static final String SEPARATOR = "|";
|
16
|
private String key;
|
17
|
|
18
|
private Type type = null;
|
19
|
|
20
|
private String id = null;
|
21
|
|
22
|
private DNGFRowKeyDecoder(final String key) throws IllegalArgumentException {
|
23
|
this.key = key;
|
24
|
|
25
|
if (!key.matches(ID_REGEX)) {
|
26
|
String msg = "invalid key: '" + key + "'";
|
27
|
log.error(msg);
|
28
|
throw new IllegalArgumentException(msg);
|
29
|
}
|
30
|
|
31
|
int tag = Integer.parseInt(StringUtils.substringBefore(key, SEPARATOR));
|
32
|
this.type = Type.valueOf(tag);
|
33
|
this.id = StringUtils.substringAfter(key, SEPARATOR);
|
34
|
|
35
|
// System.out.println(OafRowTypeDecoder.class.getName() +" decoded key: " + split);
|
36
|
}
|
37
|
|
38
|
public static DNGFRowKeyDecoder decode(final byte[] key) throws IllegalArgumentException {
|
39
|
return new DNGFRowKeyDecoder(new String(key));
|
40
|
}
|
41
|
|
42
|
public static DNGFRowKeyDecoder decode(final String key) throws IllegalArgumentException {
|
43
|
return new DNGFRowKeyDecoder(key);
|
44
|
}
|
45
|
|
46
|
public String getKey() {
|
47
|
return key;
|
48
|
}
|
49
|
|
50
|
public Type getType() {
|
51
|
return type;
|
52
|
}
|
53
|
|
54
|
public String getId() {
|
55
|
return id;
|
56
|
}
|
57
|
}
|