protected Iterator<List<ResourceMethod>> getLoop(TemplateModel model) throws TemplateException { TreeMap<String, List<ResourceMethod>> resourcesByPath = new TreeMap<String, List<ResourceMethod>>(new ResourceMethodPathComparator()); for (RootResource rootResource : getModel().getRootResources()) { for (ResourceMethod resource : rootResource.getResourceMethods(true)) { if (considerFacets && !FacetFilter.accept(resource)) { continue; } String path = resource.getFullpath(); List<ResourceMethod> resourceList = resourcesByPath.get(path); if (resourceList == null) { resourceList = new ArrayList<ResourceMethod>(); resourcesByPath.put(path, resourceList); } resourceList.add(resource); } } return resourcesByPath.values().iterator(); }