]> gerrit.simantics Code Review - simantics/interop.git/blob - org.simantics.interop.scl/src/org/simantics/interop/scl/FunctionRegistry.java
003a50ad8488a1fbcf237deb401acdeb7d4fa5fe
[simantics/interop.git] / org.simantics.interop.scl / src / org / simantics / interop / scl / FunctionRegistry.java
1 package org.simantics.interop.scl;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.simantics.scl.runtime.function.Function;
7 import org.simantics.utils.datastructures.MapList;
8
9 @SuppressWarnings({"rawtypes","unchecked"})
10 public class FunctionRegistry {
11     
12     
13     static Map<Object, MapList<String, Function>> map = new HashMap<Object, MapList<String,Function>>();
14     
15     public static void register(Object key, String name, Function f) {
16         MapList<String, Function> fmap = map.get(key);
17         if (fmap == null) {
18             fmap = new MapList<>();
19             map.put(key, fmap);
20         }
21         fmap.add(name, f);
22     }
23     
24     public static void call0 (Object key, String name) {
25         MapList<String, Function> fmap = map.get(key);
26         if (fmap == null)
27             return;
28         for (Function f : fmap.getValues(name)) {
29             f.apply(null);
30         }
31     }
32     
33     
34     public static void call1 (Object key, String name, Object o1) {
35         MapList<String, Function> fmap = map.get(key);
36         if (fmap == null)
37             return;
38         for (Function f : fmap.getValues(name)) {
39             f.apply(o1);
40         }
41     }
42     
43     public static void call2 (Object key, String name, Object o1, Object o2) {
44         MapList<String, Function> fmap = map.get(key);
45         if (fmap == null)
46             return;
47         for (Function f : fmap.getValues(name)) {
48             f.apply(o1,o2);
49         }
50     }
51     
52     public static void call3 (Object key, String name, Object o1, Object o2, Object o3) {
53         MapList<String, Function> fmap = map.get(key);
54         if (fmap == null)
55             return;
56         for (Function f : fmap.getValues(name)) {
57             f.apply(o1,o2,o3);
58         }
59     }
60     
61     public static void call4 (Object key, String name, Object o1, Object o2, Object o3, Object o4) {
62         MapList<String, Function> fmap = map.get(key);
63         if (fmap == null)
64             return;
65         for (Function f : fmap.getValues(name)) {
66             f.apply(o1,o2,o3,o4);
67         }
68     }
69     
70     public static void clear(Object key) {
71         map.remove(key);
72     }
73     
74     public static void clear(Object key, String name) {
75         MapList<String, Function> fmap = map.get(key);
76         if (fmap == null)
77             return;
78         fmap.remove(name);
79     }
80     
81
82 }