/** * Clones this object. * * @return clone of this object */ public PairOfInts clone() { return new PairOfInts(this.leftElement, this.rightElement); }
/** * 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) { PairOfInts pair = (PairOfInts) obj; return leftElement == pair.getLeftElement() && rightElement == pair.getRightElement(); }
/** * Creates a pair. * * @param left the left element * @param right the right element */ public PairOfInts(int left, int right) { set(left, right); }
public int compare(PairOfInts e1, PairOfInts e2) { if (e1.getLeftElement() > e2.getLeftElement()) { return 1; } if (e1.getLeftElement() < e2.getLeftElement()) { return -1; } throw new RuntimeException("Event observed twice!"); } };
@Override public void reduce(Text key, Iterable<PairOfInts> values, Context context) throws IOException, InterruptedException { Iterator<PairOfInts> iter = values.iterator(); ArrayListWritable<PairOfInts> postings = new ArrayListWritable<>(); int df = 0; while (iter.hasNext()) { postings.add(iter.next().clone()); df++; } // Sort the postings by docno ascending. Collections.sort(postings); DF.set(df); context.write(key, new PairOfWritables<>(DF, postings)); } }
public int compare(PairOfInts e1, PairOfInts e2) { if (e1.getLeftElement() > e2.getLeftElement()) { return 1; } if (e1.getLeftElement() < e2.getLeftElement()) { return -1; } throw new RuntimeException("Event observed twice!"); } };
@Override public void reduce(Text key, Iterable<PairOfInts> values, Context context) throws IOException, InterruptedException { Iterator<PairOfInts> iter = values.iterator(); ArrayListWritable<PairOfInts> postings = new ArrayListWritable<PairOfInts>(); int df = 0; while (iter.hasNext()) { postings.add(iter.next().clone()); df++; } // Sort the postings by docno ascending. Collections.sort(postings); DF.set(df); context.write(key, new PairOfWritables<IntWritable, ArrayListWritable<PairOfInts>>(DF, postings)); } }
public int compare(PairOfInts e1, PairOfInts e2) { if (e1.getRightElement() > e2.getRightElement()) { return 1; } if (e1.getRightElement() < e2.getRightElement()) { return -1; } if (e1.getLeftElement() == e2.getLeftElement()) { throw new RuntimeException("Event observed twice!"); } return e1.getLeftElement() < e2.getLeftElement() ? -1 : 1; } };
public static PairOfInts of(int left, int right) { return new PairOfInts(left, right); }
public int compare(PairOfInts e1, PairOfInts e2) { if (e1.getLeftElement() > e2.getLeftElement()) { return -1; } if (e1.getLeftElement() < e2.getLeftElement()) { return 1; } throw new RuntimeException("Event observed twice!"); } };
@Override public PairOfInts next() { if (!hasNext()) { return null; } MapII.Entry entry = iter.next(); pair.set(entry.getKey(), entry.getValue()); return pair; }
public int compare(PairOfInts e1, PairOfInts e2) { if (e1.getRightElement() > e2.getRightElement()) { return -1; } if (e1.getRightElement() < e2.getRightElement()) { return 1; } if (e1.getLeftElement() == e2.getLeftElement()) { throw new RuntimeException("Event observed twice!"); } return e1.getLeftElement() < e2.getLeftElement() ? -1 : 1; } };
/** * Iterator returns the same object every time, just with a different payload. */ public Iterator<PairOfInts> iterator() { return new Iterator<PairOfInts>() { private Iterator<MapII.Entry> iter = Int2IntFrequencyDistributionEntry.this.counts.entrySet() .iterator(); private final PairOfInts pair = new PairOfInts(); @Override public boolean hasNext() { return iter.hasNext(); } @Override public PairOfInts next() { if (!hasNext()) { return null; } MapII.Entry entry = iter.next(); pair.set(entry.getKey(), entry.getValue()); return pair; } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
public int compare(PairOfInts e1, PairOfInts e2) { if (e1.getLeftElement() > e2.getLeftElement()) { return -1; } if (e1.getLeftElement() < e2.getLeftElement()) { return 1; } throw new RuntimeException("Event observed twice!"); } };
@Override public PairOfInts next() { if (!hasNext()) { return null; } Int2IntMap.Entry entry = iter.next(); pair.set(entry.getIntKey(), entry.getIntValue()); return pair; }
public int compare(PairOfInts e1, PairOfInts e2) { if (e1.getRightElement() > e2.getRightElement()) { return 1; } if (e1.getRightElement() < e2.getRightElement()) { return -1; } if (e1.getLeftElement() == e2.getLeftElement()) { throw new RuntimeException("Event observed twice!"); } return e1.getLeftElement() < e2.getLeftElement() ? -1 : 1; } };
private List<PairOfInts> getEntriesSorted(Comparator<PairOfInts> comparator) { List<PairOfInts> list = Lists.newArrayList(); for (MapII.Entry e : counts.entrySet()) { list.add(new PairOfInts(e.getKey(), e.getValue())); } Collections.sort(list, comparator); return list; }
public int getPartition(PairOfInts key, ArrayListWritable<AnchorText> value, int numReduceTasks) { return Math.abs(key.getLeftElement() % numReduceTasks); } }
public void map(IntWritable key, ArrayListWritable<AnchorText> anchors, OutputCollector<PairOfInts, ArrayListWritable<AnchorText>> output, Reporter reporter) throws IOException { if(anchors.size() == 0) //not a valid record return; if(!anchors.get(0).isOfOtherTypes()) { keyWord.set(key.get(), DATA); output.collect(keyWord, anchors); return; } keyWord.set(key.get(), HOSTMAP); for(AnchorText data : anchors) { arrayList.clear(); arrayList.add(data); output.collect(keyWord, arrayList); } } }
public int compare(PairOfInts e1, PairOfInts e2) { if (e1.getRightElement() > e2.getRightElement()) { return -1; } if (e1.getRightElement() < e2.getRightElement()) { return 1; } if (e1.getLeftElement() == e2.getLeftElement()) { throw new RuntimeException("Event observed twice!"); } return e1.getLeftElement() < e2.getLeftElement() ? -1 : 1; } };