protected Iterator<String> keysImpl() { @SuppressWarnings("unchecked") Enumeration<String> headerNames = request.getHeaderNames(); return headerNames == null ? null : CollectionUtil.iterator(headerNames); } }
protected List<String> valueImpl(final String pName) { @SuppressWarnings("unchecked") Enumeration<String> headers = request.getHeaders(pName); return headers == null ? null : toList(CollectionUtil.iterator(headers)); }
/** * Creates a thin {@link Iterator} wrapper around an array. * * @param pArray the array to iterate * @return a new {@link ListIterator} * @throws IllegalArgumentException if {@code pArray} is {@code null}, * {@code pStart < 0}, or * {@code pLength > pArray.length - pStart} */ public static <E> ListIterator<E> iterator(final E[] pArray) { return iterator(pArray, 0, notNull(pArray).length); }
protected Iterator<String> keysImpl() { @SuppressWarnings("unchecked") Enumeration<String> names = request.getParameterNames(); return names == null ? null : CollectionUtil.iterator(names); } }
@Test(expected = IllegalArgumentException.class) public void testArrayIteratorRangeBadStart() { CollectionUtil.iterator(stringObjects, stringObjects.length + 1, 2); } @Test(expected = IllegalArgumentException.class)
@Test(expected = IllegalArgumentException.class) public void testArrayIteratorNull() { CollectionUtil.iterator((Object[]) null); }
@Test(expected = IllegalArgumentException.class) public void testEnumIteratorNull() { CollectionUtil.iterator((Enumeration<Object>) null); }
@Test(expected = IllegalArgumentException.class) public void testArrayIteratorRangeBadLength() { CollectionUtil.iterator(stringObjects, 1, stringObjects.length); }
@Test(expected = IllegalArgumentException.class) public void testArrayIteratorRangeNull() { CollectionUtil.iterator(null, 0, 0); }
@Test public void testArrayListIterator() { assertCorrectListIterator(CollectionUtil.iterator(new String[] {"foo", "bar", "baz"}), stringObjects); }
@Test public void testArrayListIteratorRange() { assertCorrectListIterator(CollectionUtil.iterator(new String[] {"foo", "bar", "baz", "boo"}, 1, 2), new String[] {"bar", "baz"}); }
@Test public void testEmptyIteratorConstructor() throws IOException { Reader reader = new CompoundReader(CollectionUtil.iterator(new Reader[0])); assertEquals(-1, reader.read()); }
@Test public void testIteratorWithNullConstructor() throws IOException { try { new CompoundReader(CollectionUtil.iterator(new Reader[] {null})); fail("Should not allow null in iterator argument"); } catch (RuntimeException e) { assertNotNull(e.getMessage()); } } }
@Test public void testArrayIteratorRange() { Iterator<String> iterator = CollectionUtil.iterator(new String[] {"foo", "bar", "baz", "xyzzy"}, 1, 2); for (int i = 1; i < 3; i++) { assertTrue(iterator.hasNext()); assertEquals(stringObjects[i], iterator.next()); try { iterator.remove(); fail("Array has no remove method, iterator.remove() must throw exception"); } catch (UnsupportedOperationException expected) { } } assertFalse(iterator.hasNext()); try { iterator.next(); fail("Iterator has more elements than array range"); } catch (NoSuchElementException expected) { } }
@Test public void testEnumIterator() { @SuppressWarnings("unchecked") Iterator<String> iterator = CollectionUtil.iterator((Enumeration) new StringTokenizer("foo, bar, baz", ", ")); int count = 0; for (Object stringObject : stringObjects) { assertTrue(iterator.hasNext()); assertEquals(stringObject, iterator.next()); try { iterator.remove(); fail("Enumeration has no remove method, iterator.remove() must throw exception"); } catch (UnsupportedOperationException expected) { } count++; } assertEquals(3, count); assertFalse(iterator.hasNext()); try { iterator.next(); fail("Iterator has more elements than enumeration"); } catch (NoSuchElementException expected) { } }
@Test public void testArrayIterator() { Iterator<String> iterator = CollectionUtil.iterator(new String[] {"foo", "bar", "baz"}); int count = 0; for (Object stringObject : stringObjects) { assertTrue(iterator.hasNext()); assertEquals(stringObject, iterator.next()); try { iterator.remove(); fail("Array have fixed length, iterator.remove() must throw exception"); } catch (UnsupportedOperationException expected) { } count++; } assertEquals(3, count); assertFalse(iterator.hasNext()); try { iterator.next(); fail("Iterator has more elements than array"); } catch (NoSuchElementException expected) { } }
/** * Creates a thin {@link Iterator} wrapper around an array. * * @param pArray the array to iterate * @return a new {@link ListIterator} * @throws IllegalArgumentException if {@code pArray} is {@code null}, * {@code pStart < 0}, or * {@code pLength > pArray.length - pStart} */ public static <E> ListIterator<E> iterator(final E[] pArray) { return iterator(pArray, 0, notNull(pArray).length); }
@Test(expected = IllegalArgumentException.class) public void testArrayIteratorRangeBadLength() { CollectionUtil.iterator(stringObjects, 1, stringObjects.length); }
@Test public void testEmptyIteratorConstructor() throws IOException { Reader reader = new CompoundReader(CollectionUtil.iterator(new Reader[0])); assertEquals(-1, reader.read()); }
@Test public void testIteratorWithNullConstructor() throws IOException { try { new CompoundReader(CollectionUtil.iterator(new Reader[] {null})); fail("Should not allow null in iterator argument"); } catch (RuntimeException e) { assertNotNull(e.getMessage()); } } }