public Results getPossibleValues(final ApplicationUser searcher, final String jqlClauseName, final String valuePrefix, final int maxNumResults) { final List<ProjectComponent> projectComponents = new ArrayList<ProjectComponent>(projectComponentManager.findAll()); // Lets sort the whole list of components by name Collections.sort(projectComponents, new LocaleSensitiveProjectComponentNameComparator(getLocale(searcher))); final ApplicationUser sercherApplicationUser = searcher; final Set<Result> componentValues = new LinkedHashSet<Result>(); for (ProjectComponent component : projectComponents) { if (componentValues.size() == maxNumResults) { break; } // Lets do the cheapest check first final String lowerCaseCompName = component.getName().toLowerCase(); if (StringUtils.isBlank(valuePrefix) || lowerCaseCompName.startsWith(valuePrefix.toLowerCase())) { final Project project = projectManager.getProjectObj(component.getProjectId()); if (project != null && permissionManager.hasPermission(BROWSE_PROJECTS, project, sercherApplicationUser)) { componentValues.add(new Result(component.getName())); } } } return new Results(new ArrayList<Result>(componentValues)); }