StateNodeNodeList extends NodeList<StateNode> { @Override protected void clear() { int size = size(); List<StateNode> children = null; if (size > 0) { children = new ArrayList<>(size); forEachChild(children::add); } super.clear(); if (size > 0) { children.forEach(this::detatchPotentialChild); } } protected  StateNodeNodeList(StateNode node); @Override void forEachChild(Consumer<StateNode> action);  }
@Test public void testClear() { StateNode one = StateNodeTest.createEmptyNode("one"); StateNode two = StateNodeTest.createEmptyNode("two"); nodeList.add(one); nodeList.add(two); Assert.assertEquals(2, nodeList.size()); nodeList.clear(); Assert.assertEquals(0, nodeList.size()); }