protected void reduce(VarLongWritable key,
Iterable<EntityPrefWritable> values,
Context context) throws IOException, InterruptedException {
List<EntityPrefWritable> prefs = new ArrayList<EntityPrefWritable>();
for (EntityPrefWritable writable : values) {
prefs.add(new EntityPrefWritable(writable));
}
Collections.sort(prefs, ByItemIDComparator.getInstance());
int size = prefs.size();
for (int i = 0; i < size; i++) {
EntityPrefWritable first = prefs.get(i);
long itemAID = first.getID();
float itemAValue = first.getPrefValue();
for (int j = i + 1; j < size; j++) {
EntityPrefWritable second = prefs.get(j);
long itemBID = second.getID();
float itemBValue = second.getPrefValue();
context.write(new EntityEntityWritable(itemAID, itemBID), new FloatWritable(itemBValue - itemAValue));
}
}
}