@Test public void testSimpleAggregateRanking() { List<String> aggregate = BordaCount.getAggregatedRanking(this.rankings); assert (aggregate != null); assert (aggregate.equals(this.aggregate)); }
public static <T> List<T> getAggregatedRanking(List<List<T>> rankings) { List<T> result = new ArrayList<>(); if (rankings != null && rankings.size() > 0) { int size = rankings.get(0).size(); for (List<T> ranking : rankings) { if (ranking.size() != size) throw new IllegalArgumentException( "Number of element in each ranking should be same."); } Map<T, Integer> scores = new HashMap<>(); for (List<T> ranking : rankings) { for (int i = 0; i < size; i++) { int index = size - 1 - i; T item = ranking.get(index); if (!scores.containsKey(item)) scores.put(item, 0); scores.put(item, scores.get(item) + i); } } result = Sorters.sortMapByValue(scores); Collections.reverse(result); } return result; }
BordaCount { public static <T> List<T> getAggregatedRanking(List<List<T>> rankings) { List<T> result = new ArrayList<>(); if (rankings != null && rankings.size() > 0) { int size = rankings.get(0).size(); for (List<T> ranking : rankings) { if (ranking.size() != size) throw new IllegalArgumentException( "Number of element in each ranking should be same."); } Map<T, Integer> scores = new HashMap<>(); for (List<T> ranking : rankings) { for (int i = 0; i < size; i++) { int index = size - 1 - i; T item = ranking.get(index); if (!scores.containsKey(item)) scores.put(item, 0); scores.put(item, scores.get(item) + i); } } result = Sorters.sortMapByValue(scores); Collections.reverse(result); } return result; } }
BordaCount { public static <T> List<T> getAggregatedRanking(List<List<T>> rankings) { List<T> result = new ArrayList<>(); if (rankings != null && rankings.size() > 0) { int size = rankings.get(0).size(); for (List<T> ranking : rankings) { if (ranking.size() != size) throw new IllegalArgumentException( "Number of element in each ranking should be same."); } Map<T, Integer> scores = new HashMap<>(); for (List<T> ranking : rankings) { for (int i = 0; i < size; i++) { int index = size - 1 - i; T item = ranking.get(index); if (!scores.containsKey(item)) scores.put(item, 0); scores.put(item, scores.get(item) + i); } } result = Sorters.sortMapByValue(scores); Collections.reverse(result); } return result; }  }
BordaCount { public static <T> List<T> getAggregatedRanking(List<List<T>> rankings) { List<T> result = new ArrayList<>(); if (rankings != null && rankings.size() > 0) { int size = rankings.get(0).size(); for (List<T> ranking : rankings) { if (ranking.size() != size) throw new IllegalArgumentException( "Number of element in each ranking should be same."); } Map<T, Integer> scores = new HashMap<>(); for (List<T> ranking : rankings) { for (int i = 0; i < size; i++) { int index = size - 1 - i; T item = ranking.get(index); if (!scores.containsKey(item)) scores.put(item, 0); scores.put(item, scores.get(item) + i); } } result = Sorters.sortMapByValue(scores); Collections.reverse(result); } return result; }  static List<T> getAggregatedRanking(List<List<T>> rankings); }
BordaCount { public static <T> List<T> getAggregatedRanking(List<List<T>> rankings) { List<T> result = new ArrayList<>(); if (rankings != null && rankings.size() > 0) { int size = rankings.get(0).size(); for (List<T> ranking : rankings) { if (ranking.size() != size) throw new IllegalArgumentException( "Number of element in each ranking should be same."); } Map<T, Integer> scores = new HashMap<>(); for (List<T> ranking : rankings) { for (int i = 0; i < size; i++) { int index = size - 1 - i; T item = ranking.get(index); if (!scores.containsKey(item)) scores.put(item, 0); scores.put(item, scores.get(item) + i); } } result = Sorters.sortMapByValue(scores); Collections.reverse(result); } return result; }  static List<T> getAggregatedRanking(List<List<T>> rankings);  }