@Test public final void testInsertTasksAfter() throws Exception { final Task initialTask = new SimpleTask(1); final TaskIterator iter = new TaskIterator(initialTask); iter.insertTasksAfter(initialTask, new SimpleTask(2)); iter.insertTasksAfter(initialTask, new SimpleTask(3)); Task firstTask = iter.next(); assertEquals("Task sequence error (1)!", 1, ((SimpleTask)firstTask).getId()); Task secondTask = iter.next(); assertEquals("Task sequence error (2)!", 3, ((SimpleTask)secondTask).getId()); Task thirdTask = iter.next(); assertEquals("Task sequence error (3)!", 2, ((SimpleTask)thirdTask).getId()); }
public void insertTasksAfter(final Task referenceTask, final Task... newTasks) throws IllegalStateException { final int referenceIndex = tasks.indexOf(referenceTask); if (referenceIndex == -1) throw new IllegalStateException("invalid reference task in call to insertTaskAfter()."); numTasks += newTasks.length; int offset = 0; for (final Task newTask : newTasks) { tryToAddSelfReferenceToTask(newTask); ++offset; tasks.add(referenceIndex + offset, newTask); } }
TaskIterator implements Iterator<Task> { public void insertTasksAfter(final Task referenceTask, final Task... newTasks) throws IllegalStateException { final int referenceIndex = tasks.indexOf(referenceTask); if (referenceIndex == -1) throw new IllegalStateException("invalid reference task in call to insertTaskAfter()."); numTasks += newTasks.length; int offset = 0; for (final Task newTask : newTasks) { tryToAddSelfReferenceToTask(newTask); ++offset; tasks.add(referenceIndex + offset, newTask); } } }
TaskIterator implements Iterator<Task> { public void insertTasksAfter(final Task referenceTask, final Task... newTasks) throws IllegalStateException { final int referenceIndex = tasks.indexOf(referenceTask); if (referenceIndex == -1) throw new IllegalStateException("invalid reference task in call to insertTaskAfter()."); numTasks += newTasks.length; int offset = 0; for (final Task newTask : newTasks) { tryToAddSelfReferenceToTask(newTask); ++offset; tasks.add(referenceIndex + offset, newTask); } } TaskIterator(int expectedNumTasks, final Task... initialTasks);  TaskIterator(final Task... initialTasks); }
TaskIterator implements Iterator<Task> { public void insertTasksAfter(final Task referenceTask, final Task... newTasks) throws IllegalStateException { final int referenceIndex = tasks.indexOf(referenceTask); if (referenceIndex == -1) throw new IllegalStateException("invalid reference task in call to insertTaskAfter()."); numTasks += newTasks.length; int offset = 0; for (final Task newTask : newTasks) { tryToAddSelfReferenceToTask(newTask); ++offset; tasks.add(referenceIndex + offset, newTask); } } TaskIterator(int expectedNumTasks, final Task... initialTasks);  TaskIterator(final Task... initialTasks); void insertTasksAfter(final Task referenceTask, final Task... newTasks); void insertTasksAfter(final Task referenceTask, final TaskIterator newTasks); boolean hasNext(); Task next(); void remove(); int getNumTasks(); void append(Task task); void append(TaskIterator taskIterator); }
TaskIterator implements Iterator<Task> { public void insertTasksAfter(final Task referenceTask, final Task... newTasks) throws IllegalStateException { final int referenceIndex = tasks.indexOf(referenceTask); if (referenceIndex == -1) throw new IllegalStateException("invalid reference task in call to insertTaskAfter()."); numTasks += newTasks.length; int offset = 0; for (final Task newTask : newTasks) { tryToAddSelfReferenceToTask(newTask); ++offset; tasks.add(referenceIndex + offset, newTask); } } TaskIterator(int expectedNumTasks, final Task... initialTasks);  TaskIterator(final Task... initialTasks); void insertTasksAfter(final Task referenceTask, final Task... newTasks); void insertTasksAfter(final Task referenceTask, final TaskIterator newTasks); boolean hasNext(); Task next(); void remove(); int getNumTasks(); void append(Task task); void append(TaskIterator taskIterator);  }