@SuppressWarnings("unchecked") @Override public UnmodifiableListIterator<E> listIterator(int index) { // for performance // The fake cast to E is safe because the creation methods only allow E's return (UnmodifiableListIterator<E>) Iterators.forArray(array, 0, array.length, index); }
/** Iterates in the order {@link #nodeU()}, {@link #nodeV()}. */ @Override public final UnmodifiableIterator<N> iterator() { return Iterators.forArray(nodeU, nodeV); }
@Override public UnmodifiableIterator<E> iterator() { return (UnmodifiableIterator<E>) Iterators.forArray(elements); }
/** * Returns an iterator containing the elements of {@code array} in order. The returned iterator is * a view of the array; subsequent changes to the array will be reflected in the iterator. * * <p><b>Note:</b> It is often preferable to represent your data using a collection type, for * example using {@link Arrays#asList(Object[])}, making this method unnecessary. * * <p>The {@code Iterable} equivalent of this method is either {@link Arrays#asList(Object[])}, * {@link ImmutableList#copyOf(Object[])}}, or {@link ImmutableList#of}. */ @SafeVarargs public static <T> UnmodifiableIterator<T> forArray(final T... array) { return forArray(array, 0, array.length, 0); }
@Override public Iterator<String> iterator() { count++; return Iterators.forArray("a", "b", "a"); } }
@Override public Iterator<V> iterator() { checkState(!calledIteratorAlready); calledIteratorAlready = true; return Iterators.forArray(v3()); } };
@Override protected Iterator<Integer> newTargetIterator() { return Iterators.forArray(1, 2, 3); } }.test();
@Override protected Iterator<Integer> newTargetIterator() { return Iterators.forArray(new Integer[] {0, 1, 2, 3, 4}, 1, 3, 0); } }.test();
@Override protected Iterator<List<Integer>> newTargetIterator() { Iterator<Integer> source = Iterators.forArray(1, 2, 3, 4, 5, 6, 7); return Iterators.partition(source, 3); } }.test();
@Override protected Iterator<List<Integer>> newTargetIterator() { Iterator<Integer> source = Iterators.forArray(1, 2, 3, 4, 5, 6, 7); return Iterators.paddedPartition(source, 3); } }.test();
public void testForArrayEmpty() { String[] array = new String[0]; Iterator<String> iterator = Iterators.forArray(array); assertFalse(iterator.hasNext()); try { iterator.next(); fail(); } catch (NoSuchElementException expected) { } }
public void testCopyOf_iterator_oneElementRepeated() { Iterator<String> iterator = Iterators.forArray("a", "a", "a"); Set<String> set = copyOf(iterator); assertEquals(Collections.singleton("a"), set); }
public void testCopyOf_iteratorContainingNull() { Iterator<String> c = Iterators.forArray("a", null, "b"); try { copyOf(c); fail(); } catch (NullPointerException expected) { } }
public void testLeastOfIterator_simple_negativeOne() { try { numberOrdering.leastOf(Iterators.forArray(3, 4, 5, -1), -1); fail(); } catch (IllegalArgumentException expected) { } }
public void testConcatPartiallyAdvancedFirst() { Iterator<String> itr1 = Iterators.concat(Iterators.singletonIterator("a"), Iterators.forArray("b", "c")); assertEquals("a", itr1.next()); assertEquals("b", itr1.next()); Iterator<String> itr2 = Iterators.concat(itr1, Iterators.singletonIterator("d")); assertEquals("c", itr2.next()); assertEquals("d", itr2.next()); }
public void testConcatPartiallyAdvancedSecond() { Iterator<String> itr1 = Iterators.concat(Iterators.singletonIterator("a"), Iterators.forArray("b", "c")); assertEquals("a", itr1.next()); assertEquals("b", itr1.next()); Iterator<String> itr2 = Iterators.concat(Iterators.singletonIterator("d"), itr1); assertEquals("d", itr2.next()); assertEquals("c", itr2.next()); }
public void testCopyOf_iterator_general() { Iterator<String> iterator = Iterators.forArray("a", "b", "a"); Set<String> set = copyOf(iterator); assertEquals(2, set.size()); assertTrue(set.contains("a")); assertTrue(set.contains("b")); }
public void testLeastOfIterator_simple_0() { List<Integer> result = numberOrdering.leastOf(Iterators.forArray(3, 4, 5, -1), 0); assertTrue(result instanceof RandomAccess); assertListImmutable(result); assertEquals(ImmutableList.<Integer>of(), result); }
public void testLeastOfIterator_simple_1() { List<Integer> result = numberOrdering.leastOf(Iterators.forArray(3, 4, 5, -1), 1); assertTrue(result instanceof RandomAccess); assertListImmutable(result); assertEquals(ImmutableList.of(-1), result); }
public void testLeastOfIterator_simple_nMinusOne_withNullElement() { Iterator<Integer> itr = Iterators.forArray(3, null, 5, -1); List<Integer> result = Ordering.natural().nullsLast().leastOf(itr, 3); assertTrue(result instanceof RandomAccess); assertListImmutable(result); assertEquals(ImmutableList.of(-1, 3, 5), result); }