/** An implementation of {@link List#addAll(int, Collection)}. */ static <E> boolean addAllImpl(List<E> list, int index, Iterable<? extends E> elements) { boolean changed = false; ListIterator<E> listIterator = list.listIterator(index); for (E e : elements) { listIterator.add(e); changed = true; } return changed; }
public static List<IWord> spilt(List<IWord> wordList) { ListIterator<IWord> listIterator = wordList.listIterator(); while (listIterator.hasNext()) { IWord word = listIterator.next(); if (word instanceof CompoundWord) { listIterator.remove(); for (Word inner : ((CompoundWord) word).innerList) { listIterator.add(inner); } } } return wordList; } }
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) { iterator.add("a"); fail("no exception thrown"); } catch (UnsupportedOperationException expected) {
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()); } catch (NoSuchElementException expected) { iterator.remove(); assertEquals(asList("2", "3", "4"), list); assertFalse(list.isEmpty()); iterator.add("1"); fail("transformed list iterator is addable"); } catch (UnsupportedOperationException expected) {
ListIterator<Vertex> listIterator = vertexList.listIterator(); listIterator.next(); int length = vertexList.size() - 2; for (int i = 0; i < length; ++i) Vertex vertex = listIterator.next(); Term termMain = convert(vertex); termList.add(termMain); listIterator.add(smallVertex); Term termSub = convert(smallVertex); termSub.offset = currentLine - 1;
public boolean add(Object toadd) { if (contains(toadd)) { return false; } /* it is not added to the end, but keep it in the order */ int index = fulllist.indexOf(toadd); for (ListIterator worklistIter = worklist.listIterator(); worklistIter.hasNext();) { Object tocomp = worklistIter.next(); int tmpidx = fulllist.indexOf(tocomp); if (index < tmpidx) { worklistIter.add(toadd); return true; } } return false; }
/** * Test remove after add behaviour. */ public void testAddThenRemove() { ListIterator it = makeFullListIterator(); // add then remove if (supportsAdd() && supportsRemove()) { it.next(); it.add(addSetValue()); try { it.remove(); fail("IllegalStateException must be thrown from remove after add"); } catch (IllegalStateException e) { } } }
/** * Replaces the void `<init>(boolean)` constructor for a call to the * `void <init>(int, int, int)` one. */ private void replaceGregorianCalendarBooleanConstructor(ListIterator<AbstractInsnNode> instructions, MethodInsnNode targetMethod) { // Remove the call to GregorianCalendar(boolean) instructions.remove(); // Discard the already-pushed parameter for GregorianCalendar(boolean) instructions.add(new InsnNode(Opcodes.POP)); // Add parameters values for calling GregorianCalendar(int, int, int) instructions.add(new InsnNode(Opcodes.ICONST_0)); instructions.add(new InsnNode(Opcodes.ICONST_0)); instructions.add(new InsnNode(Opcodes.ICONST_0)); // Call GregorianCalendar(int, int, int) instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, targetMethod.owner, targetMethod.name, "(III)V", targetMethod.itf)); }
@Override public List<IWord> flow(List<IWord> input) { ListIterator<IWord> listIterator = input.listIterator(); while (listIterator.hasNext()) { IWord wordOrSentence = listIterator.next(); if (wordOrSentence.getLabel() != null) continue; // 这是别的管道已经处理过的单词,跳过 listIterator.remove(); // 否则是句子 String sentence = wordOrSentence.getValue(); Matcher matcher = pattern.matcher(sentence); int begin = 0; int end; while (matcher.find()) { end = matcher.start(); listIterator.add(new Word(sentence.substring(begin, end), null)); // 未拦截的部分 listIterator.add(new Word(matcher.group(), label)); // 拦截到的部分 begin = matcher.end(); } if (begin < sentence.length()) listIterator.add(new Word(sentence.substring(begin), null)); } return input; } }
if (!it.hasNext()) { return phoneList; it.previous(); // one step back it.add("-"); // insert syllable boundary it.next(); // and forward again int minIndex = -1; // position of the sonority minimum int syllableStart = -1; while (it.hasNext()) { while (it.nextIndex() > minIndex) { steps++; it.previous(); it.add("."); it.previous(); // skip . backwards it.remove(); // remove the . it.next(); // skip one ph it.add("-"); } else { it.remove(); // remove _ it.next(); // skip N forwards it.add("-"); // insert -
public void testListIteratorAdd() { // override to cope with Set behaviour resetEmpty(); List list1 = getList(); List list2 = getConfirmedList(); Object[] elements = getOtherElements(); // changed here ListIterator iter1 = list1.listIterator(); ListIterator iter2 = list2.listIterator(); for (int i = 0; i < elements.length; i++) { iter1.add(elements[i]); iter2.add(elements[i]); super.verify(); // changed here } resetFull(); iter1 = getList().listIterator(); iter2 = getConfirmedList().listIterator(); for (int i = 0; i < elements.length; i++) { iter1.next(); iter2.next(); iter1.add(elements[i]); iter2.add(elements[i]); super.verify(); // changed here } }
private void push(int numstate, ArrayList<Object> listNode, boolean hidden) throws ParserException, LexerException, IOException { this.nodeList = listNode; if(!hidden) { filter(); } if(!this.stack.hasNext()) { this.stack.add(new State(numstate, this.nodeList)); return; } State s = (State) this.stack.next(); s.state = numstate; s.nodes = this.nodeList; }
/** An implementation of {@link List#addAll(int, Collection)}. */ static <E> boolean addAllImpl(List<E> list, int index, Iterable<? extends E> elements) { boolean changed = false; ListIterator<E> listIterator = list.listIterator(index); for (E e : elements) { listIterator.add(e); changed = true; } return changed; }