/** * Checks two pairs for equality. * * @param obj object for comparison * @return <code>true</code> if <code>obj</code> is equal to this object, <code>false</code> * otherwise */ public boolean equals(Object obj) { PairOfStringInt pair = (PairOfStringInt) obj; return leftElement.equals(pair.getLeftElement()) && rightElement == pair.getRightElement(); }
/** * Defines a natural sort order for pairs. Pairs are sorted first by the left element, and then by * the right element. * * @return a value less than zero, a value greater than zero, or zero if this pair should be * sorted before, sorted after, or is equal to <code>obj</code>. */ public int compareTo(PairOfStringInt pair) { String pl = pair.getLeftElement(); int pr = pair.getRightElement(); if (leftElement.equals(pl)) { if (rightElement == pr) return 0; return rightElement < pr ? -1 : 1; } return leftElement.compareTo(pl); }
public void reduce(PairOfStringInt key, Iterator<Text> values, OutputCollector<IntWritable, IntWritable> output, Reporter reporter) throws IOException { if (key.getRightElement() == 0) { // We want to emit a placeholder in case this is a dangling node. curArticle = key.getLeftElement(); curDocid = Integer.parseInt(values.next().toString()); finalSrc.set(curDocid); finalDest.set(curDocid); output.collect(finalSrc, finalDest); } else { if (!key.getLeftElement().equals(curArticle)) { return; } while (values.hasNext()) { finalSrc.set(Integer.parseInt(values.next().toString())); finalDest.set(curDocid); output.collect(finalSrc, finalDest); } } } }
public void reduce(PairOfStringInt key, Iterator<PairOfStrings> values, OutputCollector<IntWritable, PairOfIntString> output, Reporter reporter) throws IOException { if (key.getRightElement() == 0) { targetTitle = key.getLeftElement(); targetDocid = Integer.parseInt(values.next().getLeftElement()); } else { if (!key.getLeftElement().equals(targetTitle)) { return; } while (values.hasNext()) { PairOfStrings pair = values.next(); SRCID.set(Integer.parseInt(pair.getLeftElement())); TARGET_ANCHOR_PAIR.set(targetDocid, pair.getRightElement()); output.collect(SRCID, TARGET_ANCHOR_PAIR); } } } }