public void stateChanged(ChangeEvent e) { label.setText(makeHelp((Integer) spinner.getValue())); flattener.setDepth((Integer) spinner.getValue()); } }
/** * 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()); } }
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 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 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)); } }
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()); }