Project

General

Profile

1
package eu.dnetlib.openaire.exporter.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
	private static final Log log = LogFactory.getLog(Vocabulary.class);
16

    
17
	private List<Term> terms;
18

    
19
	public Vocabulary() {
20
	}
21

    
22
	private static Map<String, Term> byCode = Maps.newConcurrentMap();
23

    
24
	public String getEnglishName(final String code) {
25
		if (byCode.isEmpty()) {
26
			hashByCode();
27
		}
28
		final Term term = byCode.get(code);
29
		return term != null ? term.getEnglishName() : null;
30
	}
31

    
32
	public boolean hasCode(final String code) {
33
		return getEnglishName(code) != null;
34
	}
35

    
36
	private void hashByCode() {
37
		log.info("hashing vocabulary by code ...");
38
		getTerms().forEach(term -> {
39
			byCode.put(term.getCode(), term);
40
		});
41
		log.info("hashing vocabulary by code ... done!");
42
	}
43

    
44
	public List<Term> getTerms() {
45
		return terms;
46
	}
47

    
48
	public void setTerms(final List<Term> terms) {
49
		this.terms = terms;
50
	}
51
}
(3-3/3)