Skip to content

Commit

Permalink
implemented workaround for concurrent usage of the equivalenceTypes a…
Browse files Browse the repository at this point in the history
…nd equivalenceFeatures (Issue #13)
  • Loading branch information
slotties committed Oct 1, 2013
1 parent ede03ba commit 74c061b
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
* @author Stefan Lotties
Expand All @@ -42,8 +44,9 @@ public class UnifierConfiguration {
private final Map<String, List<String>> equivalenceFeatures;

public UnifierConfiguration() {
equivalenceTypes = new HashMap<>();
equivalenceFeatures = new HashMap<>();
// FIXME: workaround for issue #13
equivalenceTypes = new ConcurrentHashMap<>();
equivalenceFeatures = new ConcurrentHashMap<>();
}

/**
Expand All @@ -57,18 +60,22 @@ public UnifierConfiguration() {
*/
public final void setEquivalence(final String feature, final String type,
final Element elem) {
if (equivalenceTypes.containsKey(new EquivalenceTypeLocator(feature, type))) {

EquivalenceTypeLocator typeKey = new EquivalenceTypeLocator(feature, type);
if (equivalenceTypes.containsKey(typeKey)) {
return;
}
equivalenceTypes.put(new EquivalenceTypeLocator(feature, type), elem);
equivalenceTypes.put(typeKey, elem);

final List<String> lTypes;
if (equivalenceFeatures.containsKey(feature)) {
lTypes = equivalenceFeatures.get(feature);
} else {
lTypes = new ArrayList<>();
// FIXME: workaround for issue #13
lTypes = new CopyOnWriteArrayList<>();
equivalenceFeatures.put(feature, lTypes);
}
lTypes.add(type);
equivalenceFeatures.put(feature, lTypes);
}

public Map<String, List<String>> getEquivalenceFeatures() {
Expand Down

0 comments on commit 74c061b

Please sign in to comment.