-
-
Save Mikulas/4269631 to your computer and use it in GitHub Desktop.
This file contains 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 characters
public class Comparator { // Třída Comparator, porovnává filter a databázi | |
public static List<Applicant> compare(List<Applicant> applicants, HashMap<String, List<Integer>> filter) { | |
Map<Integer, Integer> score = new TreeMap<Integer, Integer>(); // Iaždý kandidát bude mít skóre, podle kterého řadíme | |
Integer i = 0; | |
for (Applicant a : applicants) { | |
System.out.println(a.getName() + " " + i); | |
score.put(i, 0); // Inicializace | |
i++; | |
} | |
for (Map.Entry<String, List<Integer>> e : filter.entrySet()) { // Iterace přes všechny filtry | |
i = 0; | |
for (Applicant a : applicants) { | |
int p = 0; | |
if (e.getKey() == "wage") { | |
p = Enums.wage.size() - a.wage; // V některých listech přidáme body za výsledek | |
} else if (e.getKey() == "integrity") { | |
p = a.integrity; // V jednoduchých listech akorát přidáme skóre | |
} 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(); | |
} | |
// Přidáme body k uchazeči | |
if (e.getValue().size() > 0 && p != 0) { | |
score.put(i, score.get(i) + p * e.getValue().get(0)); | |
} | |
if (e.getKey() == "drive_licenses") { // Některé filtery mají složitější filterování | |
for (Integer license : e.getValue()) { | |
if (!a.drive_licenses.contains(license)) { | |
System.out.println("dsq for license"); | |
score.put(i, -100000); // DSQ // Berlička pro jednoduchost, záporné skóre znamená, že se adept vůbec nebude vykreslovat | |
break; | |
} | |
} | |
} else if (e.getKey() == "education") { | |
if (a.education < e.getValue().get(0)) { // Pokud má adept vzdělání, které jsme vybrali nebo vyšší, je to ok | |
score.put(i, -100000); // DSQ | |
System.out.println("dsq for edu"); | |
break; | |
} | |
} | |
i++; | |
} | |
} | |
List<Applicant> sorted = new ArrayList<Applicant>(); | |
while (!score.isEmpty()) { // Zde jenom vytvoříme list uchazečů v závislosti na skóra | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment