@Test
    public void shouldLimitIterator() {
        List<String> list = Arrays.asList("a","b","c","d","e");
        Iterator<String> itty = IteratorUtils.limit(list.iterator(),3);
        assertTrue(itty.hasNext());
        assertEquals("a", itty.next());
        assertTrue(itty.hasNext());
        assertEquals("b", itty.next());
        assertTrue(itty.hasNext());
        assertEquals("c", itty.next());
        assertFalse(itty.hasNext());

        list = Arrays.asList("a","b","c");
        itty = IteratorUtils.limit(list.iterator(),4);
        assertTrue(itty.hasNext());
        assertEquals("a", itty.next());
        assertTrue(itty.hasNext());
        assertEquals("b", itty.next());
        assertTrue(itty.hasNext());
        assertEquals("c", itty.next());
        assertFalse(itty.hasNext());
    }
@author Stephen Mallette (http://stephen.genoprime.com)
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java