public @Override DiffObjectInfo<RevFeature> next() { return objects.next(); } };
@Override public ObjectInfo<RevFeature> next() { return objects.next(); } };
@Override public ObjectInfo<RevFeature> next() { return objects.next(); } };
@Override public C next() { T nextObj = source.next(); return transformFunction.apply(nextObj); }
@Override public C next() { T nextObj = source.next(); return transformFunction.apply(nextObj); }
@Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } count++; return iterator.next(); }
private T computeNext() { while (source.hasNext()) { T sourceNext = source.next(); if (filterFunction.apply(sourceNext)) { return sourceNext; } } return null; } };
@Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } count++; return iterator.next(); }
@Override public F next() throws NoSuchElementException { try { return iterator.next(); } catch (RuntimeException e) { close(); throw e; } }
private T computeNext() { while (source.hasNext()) { T sourceNext = source.next(); if (filterFunction.apply(sourceNext)) { return sourceNext; } } return null; } };
@Override public List<T> next() { if (!hasNext()) { throw new NoSuchElementException(); } List<T> list = new ArrayList<>(partitionSize); for (int i = 0; i < partitionSize && iterator.hasNext(); i++) { T next = iterator.next(); list.add(next); } return list; } };
@Override public List<T> next() { if (!hasNext()) { throw new NoSuchElementException(); } List<T> list = new ArrayList<>(partitionSize); for (int i = 0; i < partitionSize && iterator.hasNext(); i++) { T next = iterator.next(); list.add(next); } return list; } };
public @Test void testDiffTreeIteratorIsClosedOnPrematureFeatureIteratorClose() throws IOException { AutoCloseableIterator<DiffEntry> mockIt = mock(AutoCloseableIterator.class); when(mockIt.hasNext()).thenReturn(true); when(mockIt.next()).thenReturn(mock(DiffEntry.class)); doReturn(mockIt).when(difftree).call(); FeatureReader<SimpleFeatureType, SimpleFeature> featureReader = builder.build(); // close the feature reader before being fully consumed featureReader.close(); Mockito.verify(mockIt, times(0)).hasNext(); Mockito.verify(mockIt, times(0)).next(); Mockito.verify(mockIt, times(1)).close(); }
public @Test void testDiffTreeIteratorIsClosedOnPrematureFeatureIteratorClose() throws IOException { AutoCloseableIterator<DiffEntry> mockIt = mock(AutoCloseableIterator.class); when(mockIt.hasNext()).thenReturn(true); when(mockIt.next()).thenReturn(mock(DiffEntry.class)); doReturn(mockIt).when(difftree).call(); FeatureReader<SimpleFeatureType, SimpleFeature> featureReader = builder.build(); // close the feature reader before being fully consumed featureReader.close(); Mockito.verify(mockIt, times(0)).hasNext(); Mockito.verify(mockIt, times(0)).next(); Mockito.verify(mockIt, times(1)).close(); }
@Test public void testConcat2() { AtomicBoolean closed = new AtomicBoolean(false); TestAutoCloseableIterator testIter1 = new TestAutoCloseableIterator(closed); AutoCloseableIterator<List<String>> partition = AutoCloseableIterator.partition(testIter1, 1); AutoCloseableIterator<Iterator<String>> main = AutoCloseableIterator.transform(partition, item -> item.iterator()); AutoCloseableIterator<String> result = AutoCloseableIterator.concat(main); assertEquals("item1", result.next()); assertEquals("item2", result.next()); assertEquals("item11", result.next()); assertTrue(!closed.get()); result.close(); assertTrue(closed.get()); }
@Test public void testFromIterator() { Iterator<String> original = Lists.newArrayList("item1", "item2").iterator(); try (AutoCloseableIterator<String> it = AutoCloseableIterator.fromIterator(original)) { assertTrue(it.hasNext()); assertEquals("item1", it.next()); assertEquals("item2", it.next()); assertFalse(it.hasNext()); } }
@Test public void testPartition() { AtomicBoolean closed = new AtomicBoolean(false); AutoCloseableIterator<String> orig = new TestAutoCloseableIterator(closed); AutoCloseableIterator<List<String>> partition = AutoCloseableIterator.partition(orig, 2); assertTrue(partition.hasNext()); assertEquals(2, partition.next().size()); assertTrue(partition.hasNext()); assertEquals(1, partition.next().size()); assertFalse(partition.hasNext()); partition.close(); assertTrue(closed.get()); } }
@Test public void testEmptyIterator() { try (AutoCloseableIterator<Object> it = AutoCloseableIterator.emptyIterator()) { assertFalse(it.hasNext()); assertEquals(null, it.next()); } }