public TableColumnValueSortedEnumerator(Collection<IReadableTable.TableReader> readers, int colIndex, final Comparator<String> comparator) { this.readers = readers; this.colIndex = colIndex; this.comparator = comparator; pq = new PriorityQueue<ReaderBuffer>(11, new Comparator<ReaderBuffer>() { @Override public int compare(ReaderBuffer i, ReaderBuffer j) { boolean isEmpty1 = i.empty(); boolean isEmpty2 = j.empty(); if (isEmpty1 && isEmpty2) return 0; if (isEmpty1 && !isEmpty2) return 1; if (!isEmpty1 && isEmpty2) return -1; return comparator.compare(i.peek(), j.peek()); } }); for (IReadableTable.TableReader reader : readers) { if (reader != null) { try { pq.add(new ReaderBuffer(reader)); } catch (IOException e) { e.printStackTrace(); } } } }
@Override public boolean moveNext() throws IOException { while (pq.size() > 0) { ReaderBuffer buffer = pq.poll(); String minEntry = buffer.pop(); this.colValue = minEntry; if (buffer.empty()) { pq.remove(buffer); } else { pq.add(buffer); // add it back } if (this.colValue == null) { //avoid the case of empty file return false; } return true; } return false; }
public TableColumnValueSortedEnumerator(Collection<IReadableTable.TableReader> readers, int colIndex, final Comparator<String> comparator) { this.readers = readers; this.colIndex = colIndex; this.comparator = comparator; pq = new PriorityQueue<ReaderBuffer>(11, new Comparator<ReaderBuffer>() { @Override public int compare(ReaderBuffer i, ReaderBuffer j) { boolean isEmpty1 = i.empty(); boolean isEmpty2 = j.empty(); if (isEmpty1 && isEmpty2) return 0; if (isEmpty1 && !isEmpty2) return 1; if (!isEmpty1 && isEmpty2) return -1; return comparator.compare(i.peek(), j.peek()); } }); for (IReadableTable.TableReader reader : readers) { if (reader != null) { try { pq.add(new ReaderBuffer(reader)); } catch (IOException e) { e.printStackTrace(); } } } }
@Override public boolean moveNext() throws IOException { while (pq.size() > 0) { ReaderBuffer buffer = pq.poll(); String minEntry = buffer.pop(); this.colValue = minEntry; if (buffer.empty()) { pq.remove(buffer); } else { pq.add(buffer); // add it back } if (this.colValue == null) { //avoid the case of empty file return false; } return true; } return false; }
public ReaderBuffer(IReadableTable.TableReader reader) throws IOException { this.reader = reader; reload(); }
public String pop() throws IOException { String result = this.cache; reload(); return result; }
public ReaderBuffer(IReadableTable.TableReader reader) throws IOException { this.reader = reader; reload(); }
public String pop() throws IOException { String result = this.cache; reload(); return result; }