Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void reduce(final Text key, final Iterable<Text> values, final Context context) throws IOException, InterruptedException {
- ArrayList commonFriends = new ArrayList();
- ArrayList allcommonFriends = new ArrayList();
- for (Text word : values) {
- //java.lang.String[] friends = word.toString().split(" ");//convert string to string array
- //commonFriends.add(friends);
- allcommonFriends.add(word.toString());
- }
- //if(values.size()!=2) System.out.println("Error");
- StringTokenizer list1 = new StringTokenizer( allcommonFriends.get(0).toString());
- StringTokenizer list2 = new StringTokenizer(allcommonFriends.get(1).toString());
- while (list1.hasMoreTokens()) {
- String friend1=list1.nextToken();
- while (list2.hasMoreTokens()) {
- String friend2=list2.nextToken();
- if(friend1 == friend2) commonFriends.add(friend1);
- }
- }
- }
- Collection<String> allValues= commonFriends.values();
- java.lang.String entireText = StringUtils.join(allValues, ',');
- friendList.set(entireText);
- context.write(key, friendList);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement