/** * Builds the syntactic type depending on the current depth. * <p> * For instance, a current depth of 3 would return: * * <pre> * l(l(l(''))) * </pre> * * Note that the processor ignore the 'real' mime-type (the data is just * passed on), and thus uses '' as the innermost type. * * @return */ private String getSyntacticType() { String syntacticType = "''"; for (int i = 0; i < getDepth(); i++) { syntacticType = "l(" + syntacticType + ")"; } return syntacticType; }
public void stateChanged(ChangeEvent e) { label.setText(makeHelp((Integer) spinner.getValue())); flattener.setDepth((Integer) spinner.getValue()); } }
protected FlattenList getLocalWorker() { return new FlattenList(); }
public void testXMLImport() { FlattenList flattener = getLocalWorker(); flattener.setDepth(1337); Element e = flattener.provideXML(); FlattenList flattener2 = getLocalWorker(); flattener2.consumeXML(e); assertEquals("Did not consume XML correctly", 1337, flattener2.getDepth()); }
public void testSettingDepth() { FlattenList l = getLocalWorker(); l.setDepth(3); assertEquals(3, l.getDepth()); l.setDepth(1337); assertEquals(1337, l.getDepth()); // Below 2 should not work, should limit to 2 l.setDepth(1); assertEquals(2, l.getDepth()); l.setDepth(0); assertEquals(2, l.getDepth()); l.setDepth(-1); assertEquals(2, l.getDepth()); l.setDepth(-20); assertEquals(2, l.getDepth()); // But setting to 2 should work l.setDepth(3); l.setDepth(2); assertEquals(2, l.getDepth()); }
public String[] inputTypes() { logger.error("Not supposed to call inputTypes() on LocalWorkerWithPorts instance"); return new String[] { getSyntacticType() }; }
for (Object o : collection) { if (o instanceof Collection && depth > 0) { flatten((Collection) o, results, depth - 1); } else { results.add(o);
private List runFlattener(FlattenList flattener, List list) throws TaskExecutionException { Map<String, DataThing> inputs = new HashMap<String, DataThing>(); inputs.put("inputlist", new DataThing(list)); Map out = flattener.execute(inputs); DataThing thing = (DataThing) out.get("outputlist"); List result = (List) thing.getDataObject(); return result; }
public void testXMLExport() throws DataConversionException { Element e = getLocalWorker().provideXML(); assertEquals(XScufl.XScuflNS, e.getNamespace()); assertEquals("extensions", e.getName()); Element flattenlist = e.getChild("flattenlist", XScufl.XScuflNS); assertNotNull("Element <flattenlist> not found", flattenlist); Attribute depth = flattenlist.getAttribute("depth", XScufl.XScuflNS); assertNotNull("Attribute depth='' not found", depth); assertEquals(2, depth.getIntValue()); }
public List<InputPort> inputPorts(LocalServiceProcessor processor) throws DuplicatePortNameException, PortCreationException { InputPort port = new InputPort(processor, INPUTLIST); port.setSyntacticType(getSyntacticType()); List<InputPort> ports = new ArrayList<InputPort>(); ports.add(port); return ports; }
/** * Copy each entry in the input list into the output list iff it matches the * supplied regular expression. */ public Map<String, DataThing> execute(Map inputs) throws TaskExecutionException { List inputList = (List) ((DataThing) (inputs.get(INPUTLIST))).getDataObject(); List<Object> outputList = new ArrayList<Object>(); flatten(inputList, outputList, depth - 1); Map<String, DataThing> outputs = new HashMap<String, DataThing>(); outputs.put(OUTPUTLIST, new DataThing(outputList)); return outputs; }
/** * Extract the <flattenlist depth="X" /> number from the <extensions> * element. */ public void consumeXML(Element element) { Element flattenList = element.getChild(FLATTENLIST, XScufl.XScuflNS); if (flattenList == null) { return; } Attribute depth = flattenList.getAttribute(DEPTH, XScufl.XScuflNS); if (depth == null) { return; } try { setDepth(depth.getIntValue()); } catch (DataConversionException ex) { logger.warn("Invalid depth: " + depth.getValue()); } }
/** * Export depth as <extensions><flattenlist depth="X" * /></extensions> */ public Element provideXML() { Element extensions = new Element(EXTENSIONS, XScufl.XScuflNS); Element flattenList = new Element(FLATTENLIST, XScufl.XScuflNS); flattenList.setAttribute(DEPTH, Integer.toString(getDepth()), XScufl.XScuflNS); extensions.addContent(flattenList); return extensions; }
public void testTooNarrow() throws TaskExecutionException { List<List<String>> deepList = makeDeepList(0); FlattenList l = getLocalWorker(); l.setDepth(3); // Should still manage, even if list is not that deep List result = runFlattener(l, deepList); assertEquals("incorrect number of entries in the list", 10, result.size()); for (int i = 1; i <= 10; i++) { String testVal = String.valueOf(i); assertEquals("incorrect value in list", testVal, result.get(i - 1)); } }
new SpinnerNumberModel(flattener.getDepth(), 2, 100, 1); final JSpinner spinner = new JSpinner(range); panel.add(spinner, c);
public void testFlatteningDeeper() throws TaskExecutionException { List<List<List<String>>> deeperList = makeDeeperList(); FlattenList l = getLocalWorker(); l.setDepth(3); List result = runFlattener(l, deeperList); assertEquals("incorrect number of entries in the list", 4*10, result.size()); for (int i = 1; i <= 4*10; i++) { String testVal = String.valueOf(i); assertEquals("incorrect value in list", testVal, result.get(i - 1)); } }
public void testDefaultDepth() { assertEquals("Default value should be 2", 2, getLocalWorker().getDepth()); }