1
|
package eu.dnetlib.openaire.vocabularies;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.Map;
|
5
|
|
6
|
import com.google.common.collect.Maps;
|
7
|
import org.apache.commons.logging.Log;
|
8
|
import org.apache.commons.logging.LogFactory;
|
9
|
|
10
|
/**
|
11
|
* Created by claudio on 15/09/2017.
|
12
|
*/
|
13
|
public class Vocabulary {
|
14
|
|
15
|
|
16
|
private static final Log log = LogFactory.getLog(Vocabulary.class);
|
17
|
|
18
|
private List<Term> terms;
|
19
|
|
20
|
public Vocabulary() {
|
21
|
}
|
22
|
|
23
|
private static Map<String, Term> byCode = Maps.newConcurrentMap();
|
24
|
|
25
|
public String getEnglishName(final String code) {
|
26
|
if (byCode.isEmpty()) {
|
27
|
hashByCode();
|
28
|
}
|
29
|
final Term term = byCode.get(code);
|
30
|
return term != null ? term.getEnglishName() : null;
|
31
|
}
|
32
|
|
33
|
public boolean hasCode(final String code) {
|
34
|
return getEnglishName(code) != null;
|
35
|
}
|
36
|
|
37
|
private void hashByCode() {
|
38
|
log.info("hashing vocabulary by code ...");
|
39
|
getTerms().forEach(term -> byCode.put(term.getCode(), term));
|
40
|
log.info("hashing vocabulary by code ... done!");
|
41
|
}
|
42
|
|
43
|
public List<Term> getTerms() {
|
44
|
return terms;
|
45
|
}
|
46
|
|
47
|
public void setTerms(final List<Term> terms) {
|
48
|
this.terms = terms;
|
49
|
}
|
50
|
}
|