private Codec<?> buildCustomCodec(Element e) { String classAttr = e.getAttribute(ATTR_CODEC); Class<?> customCodecClass; try { customCodecClass = Class.forName(classAttr); if (CustomCodec.class.isAssignableFrom(customCodecClass)) { CustomCodec customCodec = (CustomCodec) customCodecClass.newInstance(); Map<String, String> params = new HashMap<>(); List<Element> paramElements = getSubElements(e); for (Element paramElement : paramElements) { params.put(paramElement.getAttribute(ATTR_KEY), paramElement.getAttribute(ATTR_VALUE)); } if (customCodec instanceof Configurable) { ((Configurable) customCodec).configure(params); } return new CustomCodecAdapter(customCodec, getOptionalInteger(e, ATTR_LENGTH)); } else { throw new ConfigException(format("Invalid custom class %s", classAttr)); } } catch (ClassNotFoundException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException ex) { throw new ConfigException(ex.getMessage(), ex); } }
/** @param args */ public static void main(String[] args) { long startTime = System.currentTimeMillis(); try { Class<?> problemClass = Class.forName("problems.Problem" + args[0]); Problem problemInstance = (Problem) problemClass.newInstance(); problemInstance.solve(); } catch (ClassNotFoundException | SecurityException | InstantiationException | IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } long endTime = System.currentTimeMillis(); System.out.println("Done [Elapsed: " + ((endTime - startTime) / 1000.0) + "\"]"); }