DfsFilter implements ListFilter, Filter { @Override public List<UiObject> filter(List<UiObject> nodes) { ArrayList<UiObject> list = new ArrayList<>(); for (UiObject node : nodes) { if (isIncluded(node)) { list.add(node); } filterChildren(node, list); } return list; }  @Override List<UiObject> filter(List<UiObject> nodes); List<UiObject> filter(UiObject node);  }
@Test public void filter() throws Exception { DfsFilter filter = new RandomDfsFilter(); UiObject root = new TestUiObject(10); List<UiObject> list = filter.filter(root); for (UiObject uiObject : list) { if (root != uiObject) uiObject.recycle(); } System.out.println(TestUiObject.max); assertEquals(1, TestUiObject.count); }