1 package com.tapina.robe.module; 2 3 import com.tapina.robe.swi.SWIDecoder; 4 import com.tapina.robe.swi.SWIHandler; 5 6 import java.util.List; 7 import java.util.ArrayList; 8 import java.util.Map; 9 import java.util.HashMap; 10 11 /*** 12 * This class provides various utilities relating to representing modules to RISC OS programs. 13 */ 14 public class ModuleUtils { 15 private static final int INITIAL_CAPACITY = 30; 16 private static final List numberedList = new ArrayList(INITIAL_CAPACITY); 17 private static final Map namedList = new HashMap(INITIAL_CAPACITY); 18 19 public static void registerModule(Module module) { 20 numberedList.add(module); 21 namedList.put(module.getName(), module); 22 if (module instanceof SWIHandler) { 23 SWIDecoder.registerHandler((SWIHandler) module); 24 } 25 } 26 27 public static Module getModule(String moduleName) { 28 return (Module) namedList.get(moduleName); 29 } 30 31 public static int getModuleNumber(Module module) { 32 return numberedList.indexOf(module); 33 } 34 35 public static byte[] getModuleData(String moduleName) { 36 final Module module = (Module) namedList.get(moduleName); 37 return module.getBytes(); 38 } 39 }