List<PairOfWritables<PairOfStrings, FloatWritable>> list1 = Lists.newArrayList();
List<PairOfWritables<PairOfStrings, FloatWritable>> list2 = Lists.newArrayList();
for (PairOfWritables<PairOfStrings, FloatWritable> p : pairs) {
PairOfStrings bigram = p.getLeftElement();
if (bigram.getLeftElement().equals("light")) {
list1.add(p);
}
if (bigram.getLeftElement().equals("contain")) {
list2.add(p);
}
}
Collections.sort(list1, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() {
public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1,
PairOfWritables<PairOfStrings, FloatWritable> e2) {
if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) {
return e1.getLeftElement().compareTo(e2.getLeftElement());
}
return e2.getRightElement().compareTo(e1.getRightElement());
}
});
Iterator<PairOfWritables<PairOfStrings, FloatWritable>> iter1 =
Iterators.limit(list1.iterator(), 10);
while (iter1.hasNext()) {
PairOfWritables<PairOfStrings, FloatWritable> p = iter1.next();
PairOfStrings bigram = p.getLeftElement();
System.out.println(bigram + "\t" + p.getRightElement());
}
Collections.sort(list2, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() {
public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1,
PairOfWritables<PairOfStrings, FloatWritable> e2) {
if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) {
return e1.getLeftElement().compareTo(e2.getLeftElement());
}
return e2.getRightElement().compareTo(e1.getRightElement());
}
});
Iterator<PairOfWritables<PairOfStrings, FloatWritable>> iter2 =
Iterators.limit(list2.iterator(), 10);
while (iter2.hasNext()) {
PairOfWritables<PairOfStrings, FloatWritable> p = iter2.next();
PairOfStrings bigram = p.getLeftElement();
System.out.println(bigram + "\t" + p.getRightElement());
}
}