Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. public void reduce(final Text key, final Iterable<Text> values, final Context context) throws IOException, InterruptedException {
  2.  
  3. ArrayList commonFriends = new ArrayList();
  4. ArrayList allcommonFriends = new ArrayList();
  5.  
  6. for (Text word : values) {
  7. //java.lang.String[] friends = word.toString().split(" ");//convert string to string array
  8. //commonFriends.add(friends);
  9. allcommonFriends.add(word.toString());
  10. }
  11.  
  12.  
  13. //if(values.size()!=2) System.out.println("Error");
  14.  
  15. StringTokenizer list1 = new StringTokenizer( allcommonFriends.get(0).toString());
  16. StringTokenizer list2 = new StringTokenizer(allcommonFriends.get(1).toString());
  17.  
  18. while (list1.hasMoreTokens()) {
  19. String friend1=list1.nextToken();
  20. while (list2.hasMoreTokens()) {
  21. String friend2=list2.nextToken();
  22. if(friend1 == friend2) commonFriends.add(friend1);
  23. }
  24. }
  25. }
  26. Collection<String> allValues= commonFriends.values();
  27. java.lang.String entireText = StringUtils.join(allValues, ',');
  28.  
  29. friendList.set(entireText);
  30. context.write(key, friendList);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement