1 package org.simantics.scl.runtime.unification;
5 import org.simantics.scl.runtime.function.Function;
6 import org.simantics.scl.runtime.tuple.Tuple0;
8 import gnu.trove.map.hash.THashMap;
10 public class UMapUtils {
11 public static void put(Map<Object,Object> map, Object key, Object value) {
12 if(map.containsKey(key))
13 Unification.unify(map.get(key), value);
18 @SuppressWarnings({ "rawtypes", "unchecked" })
19 public static Object get(final Function def, THashMap<Object,Object> map, Object key) {
21 Object value = map.get(key);
23 if(!map.containsKey(key)) {
24 value = def.apply(Tuple0.INSTANCE);
30 Object extrValue = Unification.extractWithDefault(def, value);
31 if(extrValue != value)
32 map.put(key, extrValue);
35 } catch(RuntimeException e) {
36 throw new RuntimeException("While generating value for key " + key + ".", e);