Source:
public Iterator<UnderreplicatedLedger> listLedgersToRereplicate(final Predicate<List<String>> predicate) { final Queue<String> queue = new LinkedList<String>(); queue.add(urLedgerPath); return new Iterator<UnderreplicatedLedger>() { final Queue<UnderreplicatedLedger> curBatch = new LinkedList<UnderreplicatedLedger>(); @Override public void remove() { throw new UnsupportedOperationException(); } @Override public boolean hasNext() { if (curBatch.size() > 0) { return true; } while (queue.size() > 0 && curBatch.size() == 0) { String parent = queue.remove(); try { for (String c : zkc.getChildren(parent, false)) { try { String child = parent + "/" + c; if (c.startsWith("urL")) { long ledgerId = getLedgerId(child); UnderreplicatedLedgerFormat underreplicatedLedgerFormat = getLedgerUnreplicationInfo(ledgerId); List<String> replicaList = underreplicatedLedgerFormat.getReplicaList(); long ctime = (underreplicatedLedgerFormat.hasCtime() ? underreplicatedLedgerFormat.getCtime() : -1L); if ((predicate == null) || predicate.test(replicaList)) { UnderreplicatedLedger underreplicatedLedger = new UnderreplicatedLedger( ledgerId); underreplicatedLedger.setCtime(ctime); underreplicatedLedger.setReplicaList(replicaList); curBatch.add(underreplicatedLedger); } } else { queue.add(child); } } catch (KeeperException.NoNodeException nne) { } } } catch (InterruptedException ie) { Thread.currentThread().interrupt(); return false; } catch (KeeperException.NoNodeException nne) { } catch (Exception e) { throw new RuntimeException("Error reading list", e); } } return curBatch.size() > 0; } @Override public UnderreplicatedLedger next() { assert curBatch.size() > 0; return curBatch.remove(); } }; }

Target:
public Iterator<UnderreplicatedLedger> listLedgersToRereplicate(final Predicate<List<String>> predicate) { final Queue<String> queue = new LinkedList<String>(); queue.add(urLedgerPath); return new Iterator<UnderreplicatedLedger>() { final Queue<UnderreplicatedLedger> curBatch = new LinkedList<UnderreplicatedLedger>(); @Override public void remove() { throw new UnsupportedOperationException(); } @Override public boolean hasNext() { if (curBatch.size() > 0) { return true; } while (queue.size() > 0 && curBatch.size() == 0) { String parent = queue.remove(); try { for (String c : zkc.getChildren(parent, false)) { try { String child = parent + "/" + c; if (c.startsWith("urL")) { long ledgerId = getLedgerId(child); UnderreplicatedLedgerFormat underreplicatedLedgerFormat = getLedgerUnreplicationInfo(ledgerId); List<String> replicaList = underreplicatedLedgerFormat.getReplicaList(); long ctime = (underreplicatedLedgerFormat.hasCtime() ? underreplicatedLedgerFormat.getCtime() : UnderreplicatedLedger.UNASSIGNED_CTIME); if ((predicate == null) || predicate.test(replicaList)) { UnderreplicatedLedger underreplicatedLedger = new UnderreplicatedLedger( ledgerId); underreplicatedLedger.setCtime(ctime); underreplicatedLedger.setReplicaList(replicaList); curBatch.add(underreplicatedLedger); } } else { queue.add(child); } } catch (KeeperException.NoNodeException nne) { } } } catch (InterruptedException ie) { Thread.currentThread().interrupt(); return false; } catch (KeeperException.NoNodeException nne) { } catch (Exception e) { throw new RuntimeException("Error reading list", e); } } return curBatch.size() > 0; } @Override public UnderreplicatedLedger next() { assert curBatch.size() > 0; return curBatch.remove(); } }; }