@Test public void trailingGroupIgnored() { Stream<String> lines = Stream.of("a", "b", "", "c"); GroupingSpliterator spliterator = new GroupingSpliterator(lines); assertTrue(spliterator.tryAdvance(group -> groups.add(group))); assertFalse(spliterator.tryAdvance(group -> groups.add(group))); assertEquals(1, groups.size()); assertEquals(2, groups.get(0).size()); assertEquals("a", groups.get(0).removeFirst()); assertEquals("b", groups.get(0).removeFirst()); }
@Override public boolean tryAdvance(Consumer<? super Deque<String>> action) { Deque<String> batch = new ArrayDeque<>(); boolean stopBatch = false; AtomicBoolean batchFull = new AtomicBoolean(); while (!stopBatch) { boolean more = lines.tryAdvance(line -> { if (line.equals("")) { batchFull.set(true); LOGGER.trace("end of batch"); } else { batch.add(line); LOGGER.trace("new line: {}", line.replace("\r", "\\r").replace("\n", "\\n")); } }); if (!more || batchFull.get()) { stopBatch = true; } } if (!batchFull.get()) { LOGGER.trace("no more lines"); return false; } LOGGER.trace("batch: {}", batch); action.accept(batch); return true; }
GroupingSpliterator implements Spliterator<Deque<String>> { @Override public boolean tryAdvance(Consumer<? super Deque<String>> action) { Deque<String> batch = new ArrayDeque<>(); boolean stopBatch = false; AtomicBoolean batchFull = new AtomicBoolean(); while (!stopBatch) { boolean more = lines.tryAdvance(line -> { if (line.equals("")) { batchFull.set(true); LOGGER.trace("end of batch"); } else { batch.add(line); LOGGER.trace("new line: {}", line.replace("\r", "\\r").replace("\n", "\\n")); } }); if (!more || batchFull.get()) { stopBatch = true; } } if (!batchFull.get()) { LOGGER.trace("no more lines"); return false; } LOGGER.trace("batch: {}", batch); action.accept(batch); return true; } }
GroupingSpliterator implements Spliterator<Deque<String>> { @Override public boolean tryAdvance(Consumer<? super Deque<String>> action) { Deque<String> batch = new ArrayDeque<>(); boolean stopBatch = false; AtomicBoolean batchFull = new AtomicBoolean(); while (!stopBatch) { boolean more = lines.tryAdvance(line -> { if (line.equals("")) { batchFull.set(true); LOGGER.trace("end of batch"); } else { batch.add(line); LOGGER.trace("new line: {}", line.replace("\r", "\\r").replace("\n", "\\n")); } }); if (!more || batchFull.get()) { stopBatch = true; } } if (!batchFull.get()) { LOGGER.trace("no more lines"); return false; } LOGGER.trace("batch: {}", batch); action.accept(batch); return true; } GroupingSpliterator(Stream<String> lines);  GroupingSpliterator(Spliterator<String> lines); }
GroupingSpliterator implements Spliterator<Deque<String>> { @Override public boolean tryAdvance(Consumer<? super Deque<String>> action) { Deque<String> batch = new ArrayDeque<>(); boolean stopBatch = false; AtomicBoolean batchFull = new AtomicBoolean(); while (!stopBatch) { boolean more = lines.tryAdvance(line -> { if (line.equals("")) { batchFull.set(true); LOGGER.trace("end of batch"); } else { batch.add(line); LOGGER.trace("new line: {}", line.replace("\r", "\\r").replace("\n", "\\n")); } }); if (!more || batchFull.get()) { stopBatch = true; } } if (!batchFull.get()) { LOGGER.trace("no more lines"); return false; } LOGGER.trace("batch: {}", batch); action.accept(batch); return true; } GroupingSpliterator(Stream<String> lines);  GroupingSpliterator(Spliterator<String> lines); @Override boolean tryAdvance(Consumer<? super Deque<String>> action); @Override Spliterator<Deque<String>> trySplit(); @Override long estimateSize(); @Override int characteristics(); }
GroupingSpliterator implements Spliterator<Deque<String>> { @Override public boolean tryAdvance(Consumer<? super Deque<String>> action) { Deque<String> batch = new ArrayDeque<>(); boolean stopBatch = false; AtomicBoolean batchFull = new AtomicBoolean(); while (!stopBatch) { boolean more = lines.tryAdvance(line -> { if (line.equals("")) { batchFull.set(true); LOGGER.trace("end of batch"); } else { batch.add(line); LOGGER.trace("new line: {}", line.replace("\r", "\\r").replace("\n", "\\n")); } }); if (!more || batchFull.get()) { stopBatch = true; } } if (!batchFull.get()) { LOGGER.trace("no more lines"); return false; } LOGGER.trace("batch: {}", batch); action.accept(batch); return true; } GroupingSpliterator(Stream<String> lines);  GroupingSpliterator(Spliterator<String> lines); @Override boolean tryAdvance(Consumer<? super Deque<String>> action); @Override Spliterator<Deque<String>> trySplit(); @Override long estimateSize(); @Override int characteristics();  }