@Test(expected = NoSuchElementException.class) public void testOfNoCopyIteratorReadsTooFar() { Iterator<Integer> it = Iterables.ofNoCopy(1).iterator(); assertTrue(it.hasNext()); assertEquals(1, (int) it.next()); it.next(); }
@SafeVarargs public static <T> Iterable<T> ofNoCopy(T... values) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { int i = 0; @Override public boolean hasNext() { return i < values.length; } @Override public T next() { if (i >= values.length) { throw new NoSuchElementException(); } else { T t = values[i]; i++; return t; } } }; } }; }
Iterables { @SafeVarargs public static <T> Iterable<T> ofNoCopy(T... values) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { int i = 0; @Override public boolean hasNext() { return i < values.length; } @Override public T next() { if (i >= values.length) { throw new NoSuchElementException(); } else { T t = values[i]; i++; return t; } } }; } }; } }
Iterables { @SafeVarargs public static <T> Iterable<T> ofNoCopy(T... values) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { int i = 0; @Override public boolean hasNext() { return i < values.length; } @Override public T next() { if (i >= values.length) { throw new NoSuchElementException(); } else { T t = values[i]; i++; return t; } } }; } }; } private  Iterables(); }
Iterables { @SafeVarargs public static <T> Iterable<T> ofNoCopy(T... values) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { int i = 0; @Override public boolean hasNext() { return i < values.length; } @Override public T next() { if (i >= values.length) { throw new NoSuchElementException(); } else { T t = values[i]; i++; return t; } } }; } }; } private  Iterables(); static Iterable<T> fromArray(T[] array); @SafeVarargs static Iterable<T> ofNoCopy(T... values); }
Iterables { @SafeVarargs public static <T> Iterable<T> ofNoCopy(T... values) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { int i = 0; @Override public boolean hasNext() { return i < values.length; } @Override public T next() { if (i >= values.length) { throw new NoSuchElementException(); } else { T t = values[i]; i++; return t; } } }; } }; } private  Iterables(); static Iterable<T> fromArray(T[] array); @SafeVarargs static Iterable<T> ofNoCopy(T... values);  }