@Test public void testArrayListIterator() { final Object[] objArray = {"a", "b", "c", "d"}; ResettableListIterator<Object> iterator = IteratorUtils.arrayListIterator(objArray); assertTrue(!iterator.hasPrevious()); assertTrue(iterator.previousIndex() == -1); assertTrue(iterator.nextIndex() == 0); assertTrue(iterator.next().equals("a")); assertTrue(iterator.previous().equals("a")); assertTrue(iterator.next().equals("a")); assertTrue(iterator.previousIndex() == 0); assertTrue(iterator.nextIndex() == 1); assertTrue(iterator.next().equals("b")); assertTrue(iterator.next().equals("c")); assertTrue(iterator.next().equals("d")); assertTrue(iterator.nextIndex() == 4); assertTrue(iterator.previousIndex() == 3); try { iterator = IteratorUtils.arrayListIterator(Integer.valueOf(0)); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { } try { iterator = IteratorUtils.arrayListIterator((Object[]) null); fail("Expecting NullPointerException"); } catch (final NullPointerException ex) { } iterator = IteratorUtils.arrayListIterator(objArray, 1); assertTrue(iterator.previousIndex() == -1); assertTrue(!iterator.hasPrevious()); assertTrue(iterator.nextIndex() == 0); assertTrue(iterator.next().equals("b")); assertTrue(iterator.previousIndex() == 0); try { iterator = IteratorUtils.arrayListIterator(objArray, -1); fail("Expecting IndexOutOfBoundsException."); } catch (final IndexOutOfBoundsException ex) { } iterator = IteratorUtils.arrayListIterator(objArray, 3); assertTrue(iterator.hasNext()); try { iterator.previous(); fail("Expecting NoSuchElementException."); } catch (final NoSuchElementException ex) { } try { iterator = IteratorUtils.arrayListIterator(objArray, 5); fail("Expecting IndexOutOfBoundsException."); } catch (final IndexOutOfBoundsException ex) { } iterator = IteratorUtils.arrayListIterator(objArray, 2, 3); assertTrue(iterator.next().equals("c")); try { iterator = IteratorUtils.arrayListIterator(objArray, 2, 5); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } try { iterator = IteratorUtils.arrayListIterator(objArray, -1, 1); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } try { iterator = IteratorUtils.arrayListIterator(objArray, 2, 1); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { } final int[] intArray = {0, 1, 2}; iterator = IteratorUtils.arrayListIterator(intArray); assertTrue(iterator.previousIndex() == -1); assertTrue(!iterator.hasPrevious()); assertTrue(iterator.nextIndex() == 0); assertTrue(iterator.next().equals(Integer.valueOf(0))); assertTrue(iterator.previousIndex() == 0); assertTrue(iterator.nextIndex() == 1); assertTrue(iterator.next().equals(Integer.valueOf(1))); assertTrue(iterator.previousIndex() == 1); assertTrue(iterator.nextIndex() == 2); assertTrue(iterator.previous().equals(Integer.valueOf(1))); assertTrue(iterator.next().equals(Integer.valueOf(1))); iterator = IteratorUtils.arrayListIterator(intArray, 1); assertTrue(iterator.previousIndex() == -1); assertTrue(!iterator.hasPrevious()); assertTrue(iterator.nextIndex() == 0); assertTrue(iterator.next().equals(Integer.valueOf(1))); assertTrue(iterator.previous().equals(Integer.valueOf(1))); assertTrue(iterator.next().equals(Integer.valueOf(1))); assertTrue(iterator.previousIndex() == 0); assertTrue(iterator.nextIndex() == 1); assertTrue(iterator.next().equals(Integer.valueOf(2))); assertTrue(iterator.previousIndex() == 1); assertTrue(iterator.nextIndex() == 2); assertTrue(iterator.previous().equals(Integer.valueOf(2))); assertTrue(iterator.previousIndex() == 0); assertTrue(iterator.nextIndex() == 1); try { iterator = IteratorUtils.arrayListIterator(intArray, -1); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } iterator = IteratorUtils.arrayListIterator(intArray, 3); assertTrue(!iterator.hasNext()); try { iterator = IteratorUtils.arrayListIterator(intArray, 4); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } iterator = IteratorUtils.arrayListIterator(intArray, 2, 3); assertTrue(!iterator.hasPrevious()); assertTrue(iterator.previousIndex() == -1); assertTrue(iterator.next().equals(Integer.valueOf(2))); assertTrue(iterator.hasPrevious()); assertTrue(!iterator.hasNext()); try { iterator = IteratorUtils.arrayListIterator(intArray, 2, 4); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } try { iterator = IteratorUtils.arrayListIterator(intArray, -1, 1); fail("Expecting IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException ex) { } try { iterator = IteratorUtils.arrayListIterator(intArray, 2, 1); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { } }
public static <E> ResettableListIterator<E> arrayListIterator(final E... array) { return new ObjectArrayListIterator<E>(array); }
IteratorUtils { public static <E> ResettableListIterator<E> arrayListIterator(final E... array) { return new ObjectArrayListIterator<E>(array); } }
IteratorUtils { public static <E> ResettableListIterator<E> arrayListIterator(final E... array) { return new ObjectArrayListIterator<E>(array); } private  IteratorUtils(); }
IteratorUtils { public static <E> ResettableListIterator<E> arrayListIterator(final E... array) { return new ObjectArrayListIterator<E>(array); } private  IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator,
                                                         long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1,
                                                  final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator,
                                                   final Iterator<? extends E> iterator1,
                                                   final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator,
                                                   final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator,
                                                   final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root,
            final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator,
            final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator,
                                                   final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator,
            final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a,
                                                         final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a,
                                                         final Iterator<? extends E> b,
                                                         final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration,
                                             final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator,
                                      final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator,
                                      final Transformer<? super E, String> transformer,
                                      final String delimiter,
                                      final String prefix,
                                      final String suffix); }
IteratorUtils { public static <E> ResettableListIterator<E> arrayListIterator(final E... array) { return new ObjectArrayListIterator<E>(array); } private  IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V> emptyMapIterator(); static OrderedMapIterator<K, V> emptyOrderedMapIterator(); static ResettableIterator<E> singletonIterator(final E object); static ListIterator<E> singletonListIterator(final E object); static ResettableIterator<E> arrayIterator(final E... array); static ResettableIterator<E> arrayIterator(final Object array); static ResettableIterator<E> arrayIterator(final E[] array, final int start); static ResettableIterator<E> arrayIterator(final Object array, final int start); static ResettableIterator<E> arrayIterator(final E[] array, final int start, final int end); static ResettableIterator<E> arrayIterator(final Object array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final E... array); static ResettableListIterator<E> arrayListIterator(final Object array); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start); static ResettableListIterator<E> arrayListIterator(final Object array, final int start); static ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end); static ResettableListIterator<E> arrayListIterator(final Object array, final int start, final int end); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator, long max); static BoundedIterator<E> boundedIterator(final Iterator<? extends E> iterator,
                                                         long offset, long max); static Iterator<E> unmodifiableIterator(final Iterator<E> iterator); static ListIterator<E> unmodifiableListIterator(final ListIterator<E> listIterator); static MapIterator<K, V> unmodifiableMapIterator(final MapIterator<K, V> mapIterator); static Iterator<E> chainedIterator(final Iterator<? extends E> iterator1,
                                                  final Iterator<? extends E> iterator2); static Iterator<E> chainedIterator(final Iterator<? extends E>... iterators); static Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator,
                                                   final Iterator<? extends E> iterator1,
                                                   final Iterator<? extends E> iterator2); static Iterator<E> collatedIterator(final Comparator<? super E> comparator,
                                                   final Iterator<? extends E>... iterators); static Iterator<E> collatedIterator(final Comparator<? super E> comparator,
                                                   final Collection<Iterator<? extends E>> iterators); static Iterator<E> objectGraphIterator(final E root,
            final Transformer<? super E, ? extends E> transformer); static Iterator<O> transformedIterator(final Iterator<? extends I> iterator,
            final Transformer<? super I, ? extends O> transform); static Iterator<E> filteredIterator(final Iterator<? extends E> iterator,
                                                   final Predicate<? super E> predicate); static ListIterator<E> filteredListIterator(final ListIterator<? extends E> listIterator,
            final Predicate<? super E> predicate); static ResettableIterator<E> loopingIterator(final Collection<? extends E> coll); static ResettableListIterator<E> loopingListIterator(final List<E> list); static NodeListIterator nodeListIterator(final NodeList nodeList); static NodeListIterator nodeListIterator(final Node node); static Iterator<E> peekingIterator(final Iterator<? extends E> iterator); static Iterator<E> pushbackIterator(final Iterator<? extends E> iterator); static SkippingIterator<E> skippingIterator(final Iterator<E> iterator, long offset); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a,
                                                         final Iterator<? extends E> b); static ZippingIterator<E> zippingIterator(final Iterator<? extends E> a,
                                                         final Iterator<? extends E> b,
                                                         final Iterator<? extends E> c); static ZippingIterator<E> zippingIterator(final Iterator<? extends E>... iterators); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration); static Iterator<E> asIterator(final Enumeration<? extends E> enumeration,
                                             final Collection<? super E> removeCollection); static Enumeration<E> asEnumeration(final Iterator<? extends E> iterator); static Iterable<E> asIterable(final Iterator<? extends E> iterator); static Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator); static ListIterator<E> toListIterator(final Iterator<? extends E> iterator); static Object[] toArray(final Iterator<?> iterator); static E[] toArray(final Iterator<? extends E> iterator, final Class<E> arrayClass); static List<E> toList(final Iterator<? extends E> iterator); static List<E> toList(final Iterator<? extends E> iterator, final int estimatedSize); static Iterator<?> getIterator(final Object obj); static void forEach(final Iterator<E> iterator, final Closure<? super E> closure); static E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure); static E find(final Iterator<E> iterator, final Predicate<? super E> predicate); static int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAny(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean matchesAll(final Iterator<E> iterator, final Predicate<? super E> predicate); static boolean isEmpty(final Iterator<?> iterator); static boolean contains(final Iterator<E> iterator, final Object object); static E get(final Iterator<E> iterator, final int index); static int size(final Iterator<?> iterator); static String toString(final Iterator<E> iterator); static String toString(final Iterator<E> iterator,
                                      final Transformer<? super E, String> transformer); static String toString(final Iterator<E> iterator,
                                      final Transformer<? super E, String> transformer,
                                      final String delimiter,
                                      final String prefix,
                                      final String suffix); @SuppressWarnings("rawtypes")
    static final ResettableIterator EMPTY_ITERATOR; @SuppressWarnings("rawtypes")
    static final ResettableListIterator EMPTY_LIST_ITERATOR; @SuppressWarnings("rawtypes")
    static final OrderedIterator EMPTY_ORDERED_ITERATOR; @SuppressWarnings("rawtypes")
    static final MapIterator EMPTY_MAP_ITERATOR; @SuppressWarnings("rawtypes")
    static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR; }