Java 8 ListIterator - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ListIterator class.

This code example shows how to use the following methods:hasNext, hasPrevious, nextIndex, previous, previousIndex
8
CodeRank
This code example shows how to use the following methods:hasPrevious
        /** 
         * Check if there is another element on the list. 
         * @return if another element 
         */ 
        public boolean hasNext() { 
            return iter.hasPrevious();
        } 
 
        /** 
         * Get the next element. 
         * @return the next element. 
         */ 
        public E next() { 
            return iter.previous();
        } 
 
        /** 
         * Remove the current element. 
         */ 
        public void remove() { 
7
CodeRank
This code example shows how to use the following methods:hasPrevious, next, nextIndex, previousIndex
    @Test
    public void listIterator() 
    { 
        MutableList<T> collection = this.getCollection();
        ListIterator<T> it = collection.listIterator();
        Assert.assertFalse(it.hasPrevious());
        Assert.assertEquals(-1, it.previousIndex());
        Assert.assertEquals(0, it.nextIndex());
        it.next();
        Assert.assertEquals(1, it.nextIndex());
 
        Verify.assertThrows(UnsupportedOperationException.class, (Runnable) it::remove);
 
        Verify.assertThrows(UnsupportedOperationException.class, () -> it.add(null)); 
 
        it.set(null); 
        Assert.assertNotEquals(this.getCollection(), collection); 
    } 
 
    @Test
7
CodeRank
This code example shows how to use the following methods:add, next, previous, remove
    public static 
    void main(String[] args) {
        LinkedList list = new LinkedList();
        ListIterator e = list.listIterator();
        Object o = new Integer(1);
        e.add(o);
        e.previous();
        e.next();
        e.remove();
        e.add(o);
        if (!o.equals(list.get(0)))
            throw new RuntimeException("LinkedList ListIterator remove failed.");
    } 
} 
7
CodeRank
This code example shows how to use the following methods:hasNext
	public OLazyIteratorListWrapper(ListIterator<T> iUnderlying) {
		underlying = iUnderlying;
	} 
 
	public boolean hasNext() { 
		return underlying.hasNext();
	} 
 
	public T next() { 
		return underlying.next();
	} 
 
	public void remove() { 
		underlying.remove();
	} 
 
	public T update(T e) {
		underlying.set(e);
		return null; 
	} 
7
CodeRank
This code example shows how to use the following methods:hasPrevious, previous
        failedTestResults.add(result); 
    } 
 
    public Throwable lastThrowable() { 
        ListIterator<ITestResult> iterator = failedTestResults.listIterator(failedTestResults.size()); 
        return iterator.hasPrevious() ? iterator.previous().getThrowable() : null; 
    } 
 
    public void clear() { 
        failedTestResults.clear(); 
    } 
 
    // don't care bellow 
 
 
    public void onConfigurationSuccess(ITestResult itr) { } 
    public void onConfigurationSkip(ITestResult itr) { } 
    public void onTestStart(ITestResult result) { } 
    public void onTestSuccess(ITestResult result) { } 
    public void onTestSkipped(ITestResult result) { } 
7
CodeRank
This code example shows how to use the following methods:hasNext, hasPrevious, next, nextIndex, previous
      return; 
    } 
 
    ListIterator it = makeEmptyListIterator();
 
    assertEquals(false, it.hasNext());
    assertEquals(0, it.nextIndex());
    assertEquals(false, it.hasPrevious());
    assertEquals(-1, it.previousIndex());
 
    // next() should throw a NoSuchElementException 
    try { 
      it.next();
      fail("NoSuchElementException must be thrown from empty ListIterator"); 
    } catch (NoSuchElementException e) {
    } 
 
    // previous() should throw a NoSuchElementException 
    try { 
      it.previous();

7
CodeRank
This code example shows how to use the following methods:hasNext, hasPrevious, next, nextIndex, previous
		Wrapper date = new DateWrapper(time1);
 
		addService(date);
		addService(date);
 
		assertEquals(0, iter.nextIndex());
		Wrapper proxy1 = (Wrapper) iter.next();
 
		assertEquals(new Long(time1), proxy1.execute());
		removeService(date);
 
		assertEquals(1, iter.nextIndex());
		assertFalse(iter.hasNext());
		assertTrue(iter.hasPrevious());
		Wrapper proxy2 = ((Wrapper) iter.previous());
		assertEquals(new Long(time1), proxy2.execute());
 
		assertSame(proxy1, proxy2);
 
	} 
7
CodeRank
This code example shows how to use the following methods:hasNext, hasPrevious, nextIndex, previousIndex
    @Test 
    public void testListIterator_noparam() { 
        ListIterator<StreamInputPacketIndexEntry> result = fixture.listIterator(); 
 
        assertNotNull(result); 
        assertEquals(true, result.hasNext()); 
        assertEquals(-1, result.previousIndex()); 
        assertEquals(false, result.hasPrevious()); 
        assertEquals(0, result.nextIndex()); 
    } 
 
    /** 
     * Run the ListIterator<StreamInputPacketIndexEntry> listIterator(n) method 
     * test, with n = 1. 
     */ 
    @Test 
    public void testListIterator_withparam() { 
        ListIterator<StreamInputPacketIndexEntry> result = fixture.listIterator(1); 
 
        assertNotNull(result); 
7
CodeRank
This code example shows how to use the following methods:hasNext, hasPrevious, next, previous, remove
    @Test
    @SuppressWarnings("unchecked") 
    public void listIterator() { 
        ListIterator<Object> i = (ListIterator<Object>) view1.listIterator();
 
        assertTrue(i.hasNext()); 
        assertEquals(newItem("aaa", "111"), i.next()); 
        assertTrue(i.hasNext()); 
        assertEquals(newItem("bbb", "222"), i.next()); 
        assertTrue(i.hasNext()); 
        assertEquals(newItem("ccc", "333"), i.next()); 
        assertFalse(i.hasNext()); 
 
        try { 
            i.next(); 
            fail("Should throw NoSuchElementException"); 
        } catch (NoSuchElementException e) {
        } 
 
        assertTrue(i.hasPrevious()); 

7
CodeRank

Related Java 8 ListIterator Questions & Answers:

See Code Examples for Java 8 ListIterator Methods: