@Test public void testHasNext() { Queue<Object[]> queue = new LinkedList<Object[]>(); queue.add(new Object[]{new Text("foo"), new LongWritable(1L)}); queue.add(new Object[]{new Text("foo"), new LongWritable(2L)}); queue.add(new Object[]{new Text("bar"), new LongWritable(3L)}); queue.add(new Object[]{new Text("bar"), new LongWritable(4L)}); Record key = new WritableRecord(SchemaUtils.fromString("k:string")); Record value = new WritableRecord(SchemaUtils.fromString("v:bigint")); Comparator<Object[]> comparator = new ColumnBasedRecordComparator(new int[]{0}, key.getColumns()); GroupingRecordIterator itr = new GroupingRecordIterator(queue, (WritableRecord) key, (WritableRecord) value, comparator); key.set(Arrays.copyOf(queue.peek(), 1)); Long v = 1L; while (itr.hasNext()) { itr.hasNext(); Long val = (Long) itr.next().get(0); assertEquals(v, val); v++; } itr.reset(); while (itr.hasNext()) { itr.hasNext(); Long val = (Long) itr.next().get(0); assertEquals(v, val); v++; } assertEquals(5, v.longValue()); }
@Override public boolean hasNext() { if (prefetch != null) { return hasNext; } else { prefetch = queue.poll(); } if (prefetch == null || keyGroupingComparator.compare(key.toWritableArray(), prefetch) != 0) { hasNext = false; } else { hasNext = true; fillKeyValue(prefetch); } return hasNext; }
GroupingRecordIterator implements Iterator<Record> { @Override public boolean hasNext() { if (prefetch != null) { return hasNext; } else { prefetch = queue.poll(); } if (prefetch == null || keyGroupingComparator.compare(key.toWritableArray(), prefetch) != 0) { hasNext = false; } else { hasNext = true; fillKeyValue(prefetch); } return hasNext; } }
GroupingRecordIterator implements Iterator<Record> { @Override public boolean hasNext() { if (prefetch != null) { return hasNext; } else { prefetch = queue.poll(); } if (prefetch == null || keyGroupingComparator.compare(key.toWritableArray(), prefetch) != 0) { hasNext = false; } else { hasNext = true; fillKeyValue(prefetch); } return hasNext; } GroupingRecordIterator(Queue<Object[]> queue, WritableRecord key,
                                WritableRecord value, Comparator<Object[]> keyGroupingComparator); }
GroupingRecordIterator implements Iterator<Record> { @Override public boolean hasNext() { if (prefetch != null) { return hasNext; } else { prefetch = queue.poll(); } if (prefetch == null || keyGroupingComparator.compare(key.toWritableArray(), prefetch) != 0) { hasNext = false; } else { hasNext = true; fillKeyValue(prefetch); } return hasNext; } GroupingRecordIterator(Queue<Object[]> queue, WritableRecord key,
                                WritableRecord value, Comparator<Object[]> keyGroupingComparator); @Override boolean hasNext(); boolean reset(); @Override Record next(); @Override void remove(); }
GroupingRecordIterator implements Iterator<Record> { @Override public boolean hasNext() { if (prefetch != null) { return hasNext; } else { prefetch = queue.poll(); } if (prefetch == null || keyGroupingComparator.compare(key.toWritableArray(), prefetch) != 0) { hasNext = false; } else { hasNext = true; fillKeyValue(prefetch); } return hasNext; } GroupingRecordIterator(Queue<Object[]> queue, WritableRecord key,
                                WritableRecord value, Comparator<Object[]> keyGroupingComparator); @Override boolean hasNext(); boolean reset(); @Override Record next(); @Override void remove();  }