SHOW:
|
|
- or go back to the newest paste.
| 1 | import java.util.ArrayList; | |
| 2 | ||
| 3 | public class shitty project extends Reducer<Text, Text, Text, Text> {
| |
| 4 | ||
| 5 | private Text friendList = new Text(); | |
| 6 | ||
| 7 | @Override | |
| 8 | public void reduce(final Text key, final Iterable<Text> values, final Context context) throws IOException, InterruptedException {
| |
| 9 | ||
| 10 | ArrayList commonFriends = new ArrayList(); | |
| 11 | ||
| 12 | if(values.size()!=2) System.out.println("Error");
| |
| 13 | else{
| |
| 14 | StringTokenizer list1 = new StringTokenizer(values[0].toString()); | |
| 15 | StringTokenizer list2 = new StringTokenizer(values[1].toString()); | |
| 16 | while (list1.hasMoreTokens()) {
| |
| 17 | friend1=list1.nextToken(); | |
| 18 | while (list2.hasMoreTokens()) {
| |
| 19 | friend2=list2.nextToken(); | |
| 20 | if(friend1==friend2) commonFriends(friend1); | |
| 21 | } | |
| 22 | } | |
| 23 | } | |
| 24 | - | friendList.set(commonFriends); |
| 24 | + | Collection<String> allValues= commonFriends.values(); |
| 25 | java.lang.String entireText = StringUtils.join(allValues, ','); | |
| 26 | ||
| 27 | friendList.set(entireText); | |
| 28 | context.write(key, friendList); | |
| 29 | } | |
| 30 | } |