mirror of
https://github.com/smyalygames/kahoot-challenge-2025.git
synced 2025-09-13 15:02:18 +02:00
feat: sorts the map in descending order
This commit is contained in:
parent
b4cbd34f6d
commit
75f5785297
@ -1,6 +1,4 @@
|
|||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -9,8 +7,13 @@ public class Main {
|
|||||||
|
|
||||||
// Gets a map with the total occurrences for each domain
|
// Gets a map with the total occurrences for each domain
|
||||||
Map<String, Integer> domains = getDomainTotal(data);
|
Map<String, Integer> domains = getDomainTotal(data);
|
||||||
|
|
||||||
System.out.println(domains);
|
System.out.println(domains);
|
||||||
|
|
||||||
|
// Order the map by descending value of the value
|
||||||
|
List<Map.Entry<String, Integer>> sortedDomains = sortDomainMapDesc(domains);
|
||||||
|
|
||||||
|
System.out.println(sortedDomains);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,4 +47,19 @@ public class Main {
|
|||||||
|
|
||||||
return domains;
|
return domains;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts the domains in descending order, from most occurrences to the least occurrences of domains.
|
||||||
|
* @param domains An unsorted map of domains with the amount that they occur
|
||||||
|
* @return Sorted list of Map Entries, in descending order of occurrences
|
||||||
|
*/
|
||||||
|
private static List<Map.Entry<String, Integer>> sortDomainMapDesc(Map<String, Integer> domains) {
|
||||||
|
// Create a list from the map entries
|
||||||
|
List<Map.Entry<String, Integer>> sortedDomains = new ArrayList<>(domains.entrySet());
|
||||||
|
|
||||||
|
// Sort the list in descending order
|
||||||
|
sortedDomains.sort(Map.Entry.comparingByValue(Comparator.reverseOrder()));
|
||||||
|
|
||||||
|
return sortedDomains;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user