PairUtils { public static Map<AuxUserUserDirectional, AuxUserUserDirectional> pairCommenters(List<Commenter> commenters) { Map<AuxUserUserDirectional, AuxUserUserDirectional> pairCommenter = new HashMap<>(); for (int i = 0; i < commenters.size(); i++) { Commenter author1 = commenters.get(i); for (int j = i - 1; j >= 0; j--) { Commenter author2 = commenters.get(j); if (!author1.equals(author2)) { AuxUserUserDirectional pair = new AuxUserUserDirectional(author1.getName(), author1.getEmail(), author2.getName(), author2.getEmail()); if (pairCommenter.containsKey(pair)) { pairCommenter.get(pair).inc(); } else { pairCommenter.put(pair, pair); } } } } return pairCommenter; }  static Map<AuxUserUserDirectional, AuxUserUserDirectional> pairCommenters(List<Commenter> commenters); static Map<UserPairDirectionalWeighted, UserPairDirectionalWeighted> buildUserPairDirectionalWeighted(List<Commenter> commenters);  }
@Test public void testPairCommenters() { List<Commenter> commenters = new ArrayList<>(); Commenter commenterA = new Commenter(1, "A", "A", true); Commenter commenterB = new Commenter(2, "B", "B", true); Commenter commenterC = new Commenter(3, "C", "C", false); commenters.add(commenterA); commenters.add(commenterB); commenters.add(commenterA); commenters.add(commenterB); commenters.add(commenterB); commenters.add(commenterC); Map<AuxUserUserDirectional, AuxUserUserDirectional> expResult = new HashMap<>(); AuxUserUserDirectional ba = new AuxUserUserDirectional("B", "A"); AuxUserUserDirectional ab = new AuxUserUserDirectional("A", "B"); AuxUserUserDirectional ca = new AuxUserUserDirectional("C", "A"); AuxUserUserDirectional cb = new AuxUserUserDirectional("C", "B"); expResult.put(ba, ba); expResult.put(ab, ab); expResult.put(ca, ca); expResult.put(cb, cb); Map<AuxUserUserDirectional, AuxUserUserDirectional> result = PairUtils.pairCommenters(commenters); for (AuxUserUserDirectional keySet : result.keySet()) { System.out.println(keySet.toString()); } assertEquals(expResult, result); }