Iterator<T> () { FlyweightCapableTreeStructure<T> structure = getStructure(); Ref<T[]> ref = Ref.create(); int count = structure.getChildren(node, ref); if (count == 0) return Collections.emptyIterator(); T[] array = ref.get(); LinkedList<T> list = new LinkedList<>(); for (int i = 0; i < count; i++) { T child = array[i]; IElementType childType = typeOf(child); // tokens and errors getParent() == null if (childType == TokenType.WHITE_SPACE || childType == TokenType.BAD_CHARACTER) { continue; } array[i] = null; // do not dispose meaningful TokenNodes list.addLast(child); } structure.disposeChildren(array, count); return list.iterator(); }