@Override public LLEntry next() { if (!hasNext()) { throw new NoSuchElementException(); } LLEntry dummy = current; // find smallest value if (currentValues.isEmpty()) { current = null; } else { int currentPos = 0; current = currentValues.get(0); for (int i = 1; i < currentValues.size(); i++) { if (current.getKey() > currentValues.get(i).getKey()) { currentPos = i; current = currentValues.get(i); } } // refill getNext(currentPos); } return dummy; }
public OrderedMergeIterator(IteratorRegistry registry, CloseableIterator<LLEntry>[] iterators) { this.registry = registry; if (registry != null) { registry.registerIterator(this); } // init values currentValues = new ArrayList<LLEntry>(); for (int i = 0; i < iterators.length; i++) { CloseableIterator<LLEntry> iter = iterators[i]; if (iter.hasNext()) { this.iterators.add(iter); currentValues.add(iter.next()); } } // find smallest value if (!currentValues.isEmpty()) { int currentPos = 0; current = currentValues.get(0); for (int i = 1; i < currentValues.size(); i++) { if (current.getKey() > currentValues.get(i).getKey()) { currentPos = i; current = currentValues.get(i); } } // refill getNext(currentPos); } }