Created
December 12, 2012 17:09
-
-
Save anonymous/4269630 to your computer and use it in GitHub Desktop.
Revisions
-
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,92 @@ public class Comparator { public static List<Applicant> compare(List<Applicant> applicants, HashMap<String, List<Integer>> filter) { Map<Integer, Integer> score = new TreeMap<Integer, Integer>(); Integer i = 0; for (Applicant a : applicants) { System.out.println(a.getName() + " " + i); score.put(i, 0); i++; } for (Map.Entry<String, List<Integer>> 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<Applicant> sorted = new ArrayList<Applicant>(); while (!score.isEmpty()) { Integer max = maxValue(score); System.out.println(max); if (max < 0) { break; // ignore applicants with negative score } for (Map.Entry<Integer, Integer> 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<Integer, Integer> tree) { Integer max = -1000000; for (Map.Entry<Integer, Integer> e : tree.entrySet()) { if (e.getValue() > max) max = e.getValue(); } return max; } }