1 package net.sourceforge.barbecue.linear.postnet;
2
3 import net.sourceforge.barbecue.Module;
4
5 import java.util.ArrayList;
6 import java.util.HashMap;
7 import java.util.List;
8 import java.util.Map;
9
10 /**
11 * @author Brendon Anderson
12 */
13 public class ModuleFactory {
14
15 public static final PostNetModule START_STOP = new PostNetModule(new int[]{1});
16
17 private static final List KEYS = new ArrayList();
18 private static final Map SET = new HashMap();
19
20 static {
21 initBaseSet();
22 }
23
24 private static void initBaseSet() {
25 KEYS.add("0");
26 SET.put("0", new PostNetModule(new int[]{1, 1, 0, 0, 0}));
27 KEYS.add("1");
28 SET.put("1", new PostNetModule(new int[]{0, 0, 0, 1, 1}));
29 KEYS.add("2");
30 SET.put("2", new PostNetModule(new int[]{0, 0, 1, 0, 1}));
31 KEYS.add("3");
32 SET.put("3", new PostNetModule(new int[]{0, 0, 1, 1, 0}));
33 KEYS.add("4");
34 SET.put("4", new PostNetModule(new int[]{0, 1, 0, 0, 1}));
35 KEYS.add("5");
36 SET.put("5", new PostNetModule(new int[]{0, 1, 0, 1, 0}));
37 KEYS.add("6");
38 SET.put("6", new PostNetModule(new int[]{0, 1, 1, 0, 0}));
39 KEYS.add("7");
40 SET.put("7", new PostNetModule(new int[]{1, 0, 0, 0, 1}));
41 KEYS.add("8");
42 SET.put("8", new PostNetModule(new int[]{1, 0, 0, 1, 0}));
43 KEYS.add("9");
44 SET.put("9", new PostNetModule(new int[]{1, 0, 1, 0, 0}));
45 }
46
47 public static Module getModule(String key) {
48 PostNetModule module = null;
49 module = (PostNetModule) SET.get(key);
50 module.setSymbol(key);
51 return module;
52 }
53
54 public static int getIndex(String key) {
55 return KEYS.indexOf(key);
56 }
57
58 public static Module getModuleForIndex(int index) {
59 return getModule((String) KEYS.get(index));
60 }
61 }