package eu.dnetlib.openaire.vocabularies; import java.util.List; import java.util.Map; import com.google.common.collect.Maps; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Created by claudio on 15/09/2017. */ public class Vocabulary { private static final Log log = LogFactory.getLog(Vocabulary.class); private List terms; public Vocabulary() { } private static final Map byCode = Maps.newConcurrentMap(); public String getEnglishName(final String code) { if (byCode.isEmpty()) { hashByCode(); } final Term term = byCode.get(code); return term != null ? term.getEnglishName() : null; } public boolean hasCode(final String code) { return getEnglishName(code) != null; } private void hashByCode() { log.info("hashing vocabulary by code ..."); getTerms().forEach(term -> byCode.put(term.getCode(), term)); log.info("hashing vocabulary by code ... done!"); } public List getTerms() { return terms; } public void setTerms(final List terms) { this.terms = terms; } }