@Override public void absorbContent(ListIterator<Content> contents) { // Fast forward the iterator until after this content. //noinspection StatementWithEmptyBody while (contents.hasPrevious() && contents.previous() != this) {} while (contents.hasPrevious()) { Content content = contents.previous(); if (content instanceof PathContent) { pathContents.add((PathContent) content); contents.remove(); } } }
// Substitute appropriate type. ArrayList<...> a = new ArrayList<...>(); // Add elements to list. // Generate an iterator. Start just after the last element. ListIterator li = a.listIterator(a.size()); // Iterate in reverse. while(li.hasPrevious()) { System.out.println(li.previous()); }
private static DefaultWebFilterChain initChain(List<WebFilter> filters, WebHandler handler) { DefaultWebFilterChain chain = new DefaultWebFilterChain(filters, handler, null, null); ListIterator<? extends WebFilter> iterator = filters.listIterator(filters.size()); while (iterator.hasPrevious()) { chain = new DefaultWebFilterChain(filters, handler, iterator.previous(), chain); } return chain; }
void appendWhereClause(StringBuilder builder, String tablePrefixOrNull, List<Object> values) { ListIterator<WhereCondition> iter = whereConditions.listIterator(); while (iter.hasNext()) { if (iter.hasPrevious()) { builder.append(" AND "); } WhereCondition condition = iter.next(); condition.appendTo(builder, tablePrefixOrNull); condition.appendValuesTo(values); } }
public void testEmptyListIterator() { ListIterator<String> iterator = Iterators.emptyListIterator(); assertFalse(iterator.hasNext()); assertFalse(iterator.hasPrevious()); assertEquals(0, iterator.nextIndex()); assertEquals(-1, iterator.previousIndex()); try { iterator.next(); fail("no exception thrown"); } catch (NoSuchElementException expected) { iterator.previous(); fail("no exception thrown"); } catch (NoSuchElementException expected) { iterator.remove(); fail("no exception thrown"); } catch (UnsupportedOperationException expected) {
public boolean hasPrevious() { // put the cursor in the right position if(_indexIterator.previousId() != null && _indexIterator.lastId() != null) { if(_indexIterator.previousId().equals(_indexIterator.lastId())) { _indexIterator.previous(); } } while(!_keyIterator.hasPrevious()) { if(_indexIterator.hasPrevious()) { _currentIndexId = _indexIterator.previousId(); List<byte[]> byteList = _indexIterator.previous().getValue(); _keyIterator = byteList.listIterator(byteList.size()); } else { break; } } return _keyIterator.hasPrevious(); }
private static void assertTransformListIterator(List<String> list) { ListIterator<String> iterator = list.listIterator(1); assertEquals(1, iterator.nextIndex()); assertEquals("2", iterator.next()); assertEquals("3", iterator.next()); assertEquals("4", iterator.next()); assertEquals(4, iterator.nextIndex()); try { assertEquals("4", iterator.previous()); assertEquals("3", iterator.previous()); assertEquals("2", iterator.previous()); assertTrue(iterator.hasPrevious()); assertEquals("1", iterator.previous()); assertFalse(iterator.hasPrevious()); assertEquals(-1, iterator.previousIndex()); try { } catch (NoSuchElementException expected) { iterator.remove(); assertEquals(asList("2", "3", "4"), list); assertFalse(list.isEmpty());
protected void checkUnexpectedStart(ListIterator<Token> iterator){ if (!iterator.hasPrevious()){ iterator.next(); Token current = iterator.previous(); unexpectedToken(current); } }
/** * Test method for {@link groovy.lang.EmptyRange#listIterator()}. */ public void testListIterator() { final ListIterator iterator = range.listIterator(); assertFalse("iterator has next value", iterator.hasNext()); assertFalse("iterator has previous value", iterator.hasPrevious()); try { iterator.next(); fail("got next value in an empty range"); } catch (NoSuchElementException e) { assertTrue("expected exception thrown", true); } }
for (ListIterator<GridCacheMvccCandidate> it = rmts.listIterator(rmts.size()); it.hasPrevious(); ) { GridCacheMvccCandidate cur = it.previous(); mvAfter = new LinkedList<>(); it.remove();
private void walkBackward(ListIterator expected, ListIterator testing) { while(expected.hasPrevious()) { assertEquals(expected.nextIndex(),testing.nextIndex()); assertEquals(expected.previousIndex(),testing.previousIndex()); assertTrue(testing.hasPrevious()); assertEquals(expected.previous(),testing.previous()); } }
/** An implementation of {@link List#lastIndexOf(Object)}. */ static int lastIndexOfImpl(List<?> list, @NullableDecl Object element) { if (list instanceof RandomAccess) { return lastIndexOfRandomAccess(list, element); } else { ListIterator<?> listIterator = list.listIterator(list.size()); while (listIterator.hasPrevious()) { if (Objects.equal(element, listIterator.previous())) { return listIterator.nextIndex(); } } return -1; } }
/** * Test method for {@link groovy.lang.EmptyRange#listIterator(int)}. */ public void testListIteratorInt() { final ListIterator iterator = range.listIterator(0); assertFalse("iterator has next value", iterator.hasNext()); assertFalse("iterator has previous value", iterator.hasPrevious()); try { range.listIterator(1); fail("got list iterator at index 1"); } catch (IndexOutOfBoundsException e) { assertTrue("expected exception thrown", true); } }
/** An implementation of {@link List#lastIndexOf(Object)}. */ static int lastIndexOfImpl(List<?> list, @Nullable Object element) { if (list instanceof RandomAccess) { return lastIndexOfRandomAccess(list, element); } else { ListIterator<?> listIterator = list.listIterator(list.size()); while (listIterator.hasPrevious()) { if (Objects.equal(element, listIterator.previous())) { return listIterator.nextIndex(); } } return -1; } }
@Override public synchronized T get() { if(iter.hasNext()) { T obj = iter.next().get(); if(null != obj) { return obj; } } else if(iter.hasPrevious()) { // rewind while(iter.hasPrevious()) { iter.previous(); } return get(); } return null; } };
public void testWalkForwardAndBack() { ArrayList list = new ArrayList(); ListIterator it = makeFullListIterator(); while (it.hasNext()) { list.add(it.next()); assertEquals(false, it.hasNext()); assertEquals(true, it.hasPrevious()); assertEquals(obj, it.previous()); assertEquals(true, it.hasNext()); assertEquals(false, it.hasPrevious()); try { it.previous(); fail("NoSuchElementException must be thrown from previous at start of ListIterator"); } catch (NoSuchElementException e) {
@Override public void absorbContent(ListIterator<Content> contentsIter) { // This check prevents a repeater from getting added twice. // This can happen in the following situation: // RECTANGLE // REPEATER 1 // FILL // REPEATER 2 // In this case, the expected structure would be: // REPEATER 2 // REPEATER 1 // RECTANGLE // FILL // Without this check, REPEATER 1 will try and absorb contents once it is already inside of // REPEATER 2. if (contentGroup != null) { return; } // Fast forward the iterator until after this content. //noinspection StatementWithEmptyBody while (contentsIter.hasPrevious() && contentsIter.previous() != this) {} List<Content> contents = new ArrayList<>(); while (contentsIter.hasPrevious()) { contents.add(contentsIter.previous()); contentsIter.remove(); } Collections.reverse(contents); contentGroup = new ContentGroup(lottieDrawable, layer, "Repeater", hidden, contents, null); }
private void nextNextPrevious(ListIterator expected, ListIterator testing) { // calls to next() should change the value returned by previous() // even after previous() has been set by a call to hasPrevious() assertEquals(expected.next(),testing.next()); assertEquals(expected.hasPrevious(),testing.hasPrevious()); Object expecteda = expected.next(); Object testinga = testing.next(); assertEquals(expecteda,testinga); Object expectedb = expected.previous(); Object testingb = testing.previous(); assertEquals(expecteda,expectedb); assertEquals(testinga,testingb); }
private DefaultResourceTransformerChain initTransformerChain(ResourceResolverChain resolverChain, ArrayList<ResourceTransformer> transformers) { DefaultResourceTransformerChain chain = new DefaultResourceTransformerChain(resolverChain, null, null); ListIterator<? extends ResourceTransformer> it = transformers.listIterator(transformers.size()); while (it.hasPrevious()) { chain = new DefaultResourceTransformerChain(resolverChain, it.previous(), chain); } return chain; }
public void pushForward(List<Token> matchedTokenList) { ListIterator<Token> iter = matchedTokenList.listIterator(matchedTokenList.size()); while (iter.hasPrevious()) { tokenQueue.addFirst(iter.previous()); } }