class LanguageService {

    public List<Language> getMainLanguages(final String organizations, final Comparator<Language> c, Optional<String> filterLanguage) {

        Collection<String> organizationList = StringParser.parseStringList(organizations, ",");
        List<Project> projectList = new ArrayList<>();

        // get the projects
        for (String org : organizationList) {

            Iterable<Project> projects = repository.findProjects(org, Optional.empty(), filterLanguage);

            for (Project project : projects) {
                projectList.add(project);
            }
        }

        // count the languages

        List<String> languageList = new ArrayList<>();

        for (Project p : projectList) {
            if (StringUtils.isEmpty(p.getPrimaryLanguage())) {
                logger.info(String.format("No primary programming language set for project [%s].", p.getName()));
                continue;
            }

            languageList.add(p.getPrimaryLanguage());
        }

        List<Language> languages = new ArrayList<>();

        Set<String> languageSet = new HashSet<>(languageList);

        int frequency;

        for (String language : languageSet) {
            Language l = new Language(language);
            frequency = Collections.frequency(languageList, language);

            l.setPercentage((int) Math.round(((double) frequency) / languageList.size() * 100));
            l.setProjectsCount(frequency);

            languages.add(l);
        }

        // sort
        if (languages.size() > 1) {
            Collections.sort(languages, c);
        }

        return languages;
    }

    @Autowired public  LanguageService(ProjectRepository repository);

}