List<P> projectObjects = new ArrayList<P>();
Iterator<ProjectView> iterator = projects.iterator();
int index = 0;
while (iterator.hasNext()) {
ProjectView project = iterator.next();
if (filter.doesAllowProject(project)) {
P userProjectObject = visitor.visitProject(project, index, parentProjectObject);
projectObjects.add(userProjectObject);
//visit sub projects
List<P> subProjectObjects = visitProjects(visitor, filter, project.getSubProjects(), userProjectObject);
//visit tasks. Notice that we pass in the number of subprojects as a starting index. This is so they'll come afterwards.
List<T> taskObjects = visitTasks(visitor, filter, project, subProjectObjects.size(), userProjectObject);
visitor.completedVisitingProject(userProjectObject, subProjectObjects, taskObjects);