This class is a singleton. I'am not very good at thread-safety. Is this class thread-safe? Some methods are omitted, but they will used only from one thread. The methods listed here will be accessed from multiple threads simultaneously though.
public class TermsDto {
private final static MapSplitter mapSplitter = Splitter
.on(',').trimResults().omitEmptyStrings()
.withKeyValueSeparator(":");
private volatile double factorForOthers = 4;
private volatile Map<String, Double> factorForTermName =
new HashMap<String, Double>();
public void setFactorForOthers(double factorForOthers) {
this.factorForOthers = factorForOthers;
}
public void setFactorForTermNameMapping(String mapping) {
HashMap<String, Double> tempFactorForTermName =
new HashMap<String, Double>();
for (Map.Entry<String, String> entry :
mapSplitter.split(mapping).entrySet()) {
double factor = Double.parseDouble(entry.getValue());
tempFactorForTermName.put(entry.getKey(), factor);
}
factorForTermName = tempFactorForTermName;
}
}