throws IOException, InterruptedException {
String[] splits = value.toString().split(":");
int movieId = Integer.valueOf(splits[splits.length-2]);
String data = splits[splits.length-1];
Movie currentMovie = new Movie(movieId, data);
HashSet<Movie> hasCalcCenters = new HashSet<Movie>();
double maxDst = -1;
Movie maxMovie = null;
for(int i=0; i<splits.length-2; i++) {
Integer cId = Integer.valueOf(splits[i]);
ArrayList<Movie> movies = canopyKmeansCenters.get(cId);
if(movies == null)
continue;
for(Movie movie: movies) {
if(hasCalcCenters.contains(movie))
continue;
hasCalcCenters.add(movie);
double dst = movie.getComplexDistance(currentMovie);
if(dst > maxDst) {
maxDst = dst;
maxMovie = movie;
}
}
}
if(maxDst > -1) {
context.write(new Text(String.valueOf(maxMovie.getMovieId())),
new Text(String.valueOf(movieId)+":"+data));
}
}