@Override public Iterator<T> iterator() { return Iterators.cycle(iterable); }
@Override public Iterator<T> iterator() { return Iterators.cycle(iterable); }
@Override public Iterator<T> iterator() { return Iterators.cycle(iterable); }
/** * Returns an iterator that cycles indefinitely over the provided elements. * * <p>The returned iterator supports {@code remove()}. After {@code remove()} is called, * subsequent cycles omit the removed element, but {@code elements} does not change. The * iterator's {@code hasNext()} method returns {@code true} until all of the original elements * have been removed. * * <p><b>Warning:</b> Typical uses of the resulting iterator may produce an infinite loop. You * should use an explicit {@code break} or be certain that you will eventually remove all the * elements. */ @SafeVarargs public static <T> Iterator<T> cycle(T... elements) { return cycle(Lists.newArrayList(elements)); }
/** * Returns an iterator that cycles indefinitely over the provided elements. * * <p>The returned iterator supports {@code remove()}. After {@code remove()} is called, * subsequent cycles omit the removed element, but {@code elements} does not change. The * iterator's {@code hasNext()} method returns {@code true} until all of the original elements * have been removed. * * <p><b>Warning:</b> Typical uses of the resulting iterator may produce an infinite loop. You * should use an explicit {@code break} or be certain that you will eventually remove all the * elements. */ @SafeVarargs public static <T> Iterator<T> cycle(T... elements) { return cycle(Lists.newArrayList(elements)); }
@Override protected Iterator<Integer> newTargetIterator() { return Iterators.cycle(asList(1, 2)); } }.test();
/** * Returns an iterator that cycles indefinitely over the provided elements. * * <p>The returned iterator supports {@code remove()}. After {@code remove()} is called, * subsequent cycles omit the removed element, but {@code elements} does not change. The * iterator's {@code hasNext()} method returns {@code true} until all of the original elements * have been removed. * * <p><b>Warning:</b> Typical uses of the resulting iterator may produce an infinite loop. You * should use an explicit {@code break} or be certain that you will eventually remove all the * elements. */ @SafeVarargs public static <T> Iterator<T> cycle(T... elements) { return cycle(Lists.newArrayList(elements)); }
public void testCycleWhenRemoveIsNotSupported() { Iterable<String> iterable = asList("a", "b"); Iterator<String> cycle = Iterators.cycle(iterable); cycle.next(); try { cycle.remove(); fail("no exception thrown"); } catch (UnsupportedOperationException expected) { } }
@Setup(Level.Iteration) public void setup() { final Random r = new Random(1234567891L); dataIterator = Iterators.cycle( Stream.generate(() -> Math.round(Math.exp(2.0 + r.nextGaussian()))).limit(1048576) .collect(Collectors.toList())); } }
public void testCycleRemoveSameElementTwice() { Iterator<String> cycle = Iterators.cycle("a", "b"); cycle.next(); cycle.remove(); try { cycle.remove(); fail("no exception thrown"); } catch (IllegalStateException expected) { } }
public void testCycleOfEmpty() { // "<String>" for javac 1.5. Iterator<String> cycle = Iterators.<String>cycle(); assertFalse(cycle.hasNext()); }
public void testCycleRemoveWithoutNext() { Iterator<String> cycle = Iterators.cycle("a", "b"); assertTrue(cycle.hasNext()); try { cycle.remove(); fail("no exception thrown"); } catch (IllegalStateException expected) { } }
public void testCycleOfOne() { Iterator<String> cycle = Iterators.cycle("a"); for (int i = 0; i < 3; i++) { assertTrue(cycle.hasNext()); assertEquals("a", cycle.next()); } }
public void testCycleOfOneWithRemove() { Iterable<String> iterable = Lists.newArrayList("a"); Iterator<String> cycle = Iterators.cycle(iterable); assertTrue(cycle.hasNext()); assertEquals("a", cycle.next()); cycle.remove(); assertEquals(Collections.emptyList(), iterable); assertFalse(cycle.hasNext()); }
public void testCycleNoSuchElementException() { Iterable<String> iterable = Lists.newArrayList("a"); Iterator<String> cycle = Iterators.cycle(iterable); assertTrue(cycle.hasNext()); assertEquals("a", cycle.next()); cycle.remove(); assertFalse(cycle.hasNext()); try { cycle.next(); fail(); } catch (NoSuchElementException expected) { } }
public void testCycleRemoveAfterHasNext() { Iterable<String> iterable = Lists.newArrayList("a"); Iterator<String> cycle = Iterators.cycle(iterable); assertTrue(cycle.hasNext()); assertEquals("a", cycle.next()); assertTrue(cycle.hasNext()); cycle.remove(); assertEquals(Collections.emptyList(), iterable); assertFalse(cycle.hasNext()); }
public void testCycleOfTwo() { Iterator<String> cycle = Iterators.cycle("a", "b"); for (int i = 0; i < 3; i++) { assertTrue(cycle.hasNext()); assertEquals("a", cycle.next()); assertTrue(cycle.hasNext()); assertEquals("b", cycle.next()); } }
/** * used for bucket map join */ public void setupContext(List<Path> paths) { this.iterPath = paths.iterator(); List<PartitionDesc> partitionDescs; if (!isPartitioned) { this.iterPartDesc = Iterators.cycle(new PartitionDesc(work.getTblDesc(), null)); } else { this.iterPartDesc = work.getPartDescs(paths).iterator(); } this.context = setupExecContext(operator, paths); }
public void testCycleRemoveAfterHasNextExtraPicky() { PickyIterable<String> iterable = new PickyIterable("a"); Iterator<String> cycle = Iterators.cycle(iterable); assertTrue(cycle.hasNext()); assertEquals("a", cycle.next()); assertTrue(cycle.hasNext()); cycle.remove(); assertTrue(iterable.elements.isEmpty()); assertFalse(cycle.hasNext()); }
public void testCycleOfTwoWithRemove() { Iterable<String> iterable = Lists.newArrayList("a", "b"); Iterator<String> cycle = Iterators.cycle(iterable); assertTrue(cycle.hasNext()); assertEquals("a", cycle.next()); assertTrue(cycle.hasNext()); assertEquals("b", cycle.next()); assertTrue(cycle.hasNext()); assertEquals("a", cycle.next()); cycle.remove(); assertEquals(Collections.singletonList("b"), iterable); assertTrue(cycle.hasNext()); assertEquals("b", cycle.next()); assertTrue(cycle.hasNext()); assertEquals("b", cycle.next()); cycle.remove(); assertEquals(Collections.emptyList(), iterable); assertFalse(cycle.hasNext()); }