public class Comparator { public static List compare(List applicants, HashMap> filter) { Map score = new TreeMap(); Integer i = 0; for (Applicant a : applicants) { System.out.println(a.getName() + " " + i); score.put(i, 0); i++; } for (Map.Entry> e : filter.entrySet()) { i = 0; for (Applicant a : applicants) { int p = 0; if (e.getKey() == "wage") { p = Enums.wage.size() - a.wage; } else if (e.getKey() == "integrity") { p = a.integrity; // 0==ne } else if (e.getKey() == "focus") { p = a.education != -1 ? 1 : 0; } else if (e.getKey() == "practice") { p = a.practice; } else if (e.getKey() == "languages") { p += a.lang1skill + a.lang2skill + a.lang3skill; } else if (e.getKey() == "pc") { p = a.pc; } else if (e.getKey() == "certificates") { p = a.certificates.size(); } else if (e.getKey() == "experience") { p = Enums.experience.size() - a.experience; } else if (e.getKey() == "economics") { p = a.economics.size(); } else if (e.getKey() == "skills") { p = a.skills.size(); } // if p == 0 nothing happens anyway if (e.getValue().size() > 0 && p != 0) { score.put(i, score.get(i) + p * e.getValue().get(0)); } if (e.getKey() == "drive_licenses") { for (Integer license : e.getValue()) { if (!a.drive_licenses.contains(license)) { System.out.println("dsq for license"); score.put(i, -100000); // DSQ break; } } } else if (e.getKey() == "education") { if (a.education < e.getValue().get(0)) { score.put(i, -100000); // DSQ System.out.println("dsq for edu"); break; } } i++; } } List sorted = new ArrayList(); while (!score.isEmpty()) { Integer max = maxValue(score); System.out.println(max); if (max < 0) { break; // ignore applicants with negative score } for (Map.Entry e : score.entrySet()) { if (e.getValue() == max) { sorted.add(applicants.get(e.getKey())); score.remove(e.getKey()); break; } } } System.out.println("done filtering, have " + sorted.size()); return sorted; } private static Integer maxValue(Map tree) { Integer max = -1000000; for (Map.Entry e : tree.entrySet()) { if (e.getValue() > max) max = e.getValue(); } return max; } }