Author: ruschein
Date: 2010-09-10 16:23:15 -0700 (Fri, 10 Sep 2010)
New Revision: 21806

Modified:
   core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractTask.java
   core3/work-api/trunk/src/main/java/org/cytoscape/work/TaskIterator.java
   core3/work-api/trunk/src/test/java/org/cytoscape/work/TaskIteratorTest.java
Log:
Overloaded TaskIterator.insertTaskAfterReferenceTask() to also take another 
TaskIterator.

Modified: 
core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractTask.java
===================================================================
--- core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractTask.java     
2010-09-10 23:06:17 UTC (rev 21805)
+++ core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractTask.java     
2010-09-10 23:23:15 UTC (rev 21806)
@@ -21,6 +21,12 @@
                taskIterator.insertTasksAfter(this, newTasks);
        }
 
+       /** Inserts "newTasks" after the current Task, in the TaskIterator that 
is being managed by this class.
+        */
+       final protected void insertTasksAfterCurrentTask(final TaskIterator 
newTasks) {
+               taskIterator.insertTasksAfter(this, newTasks);
+       }
+
        /** Calling this attempts to abort the current task.  How well this 
works depends on the granularity of
         *  a Task's checking whether "cancelled" is true or not and then 
taking appropriate action.
         */

Modified: 
core3/work-api/trunk/src/main/java/org/cytoscape/work/TaskIterator.java
===================================================================
--- core3/work-api/trunk/src/main/java/org/cytoscape/work/TaskIterator.java     
2010-09-10 23:06:17 UTC (rev 21805)
+++ core3/work-api/trunk/src/main/java/org/cytoscape/work/TaskIterator.java     
2010-09-10 23:23:15 UTC (rev 21806)
@@ -43,6 +43,22 @@
                }
        }
 
+       /** Inserts "newTasks" immediately after "referenceTask".
+        *  @throws IllegalStateException if "referenceTask" is not known to 
the iterator.
+        */
+       public void insertTasksAfter(final Task referenceTask, final 
TaskIterator newTasks) throws IllegalStateException {
+               final int referenceIndex = tasks.indexOf(referenceTask);
+               if (referenceIndex == -1)
+                       throw new IllegalStateException("invalid reference task 
in call to insertTaskAfter()!");
+               int offset = 0;
+               while (newTasks.hasNext()) {
+                       final Task newTask = newTasks.next();
+                       tryToAddSelfReferenceToTask(newTask);
+                       ++offset;
+                       tasks.add(referenceIndex + offset, newTask);
+               }
+       }
+
        /** @return true if a call to next() would return another Task, 
otherwise false
         */
        public boolean hasNext() {

Modified: 
core3/work-api/trunk/src/test/java/org/cytoscape/work/TaskIteratorTest.java
===================================================================
--- core3/work-api/trunk/src/test/java/org/cytoscape/work/TaskIteratorTest.java 
2010-09-10 23:06:17 UTC (rev 21805)
+++ core3/work-api/trunk/src/test/java/org/cytoscape/work/TaskIteratorTest.java 
2010-09-10 23:23:15 UTC (rev 21806)
@@ -50,6 +50,21 @@
                assertEquals("Task sequence error (3)!", 2, 
((SimpleTask)thirdTask).getId());
        }
 
+       @Test
+       public final void testInsertTasksAfterUsingAnIterator() throws 
Exception {
+               final Task initialTask = new SimpleTask(1);
+               final TaskIterator iter = new TaskIterator(initialTask);
+               final TaskIterator newIter = new TaskIterator(new 
SimpleTask(2), new SimpleTask(3));
+               iter.insertTasksAfter(initialTask, newIter);
+
+               Task firstTask = iter.next();
+               assertEquals("Task sequence error (1)!", 1, 
((SimpleTask)firstTask).getId());
+               Task secondTask = iter.next();
+               assertEquals("Task sequence error (2)!", 2, 
((SimpleTask)secondTask).getId());
+               Task thirdTask = iter.next();
+               assertEquals("Task sequence error (3)!", 3, 
((SimpleTask)thirdTask).getId());
+       }
+
        @Test(expected=UnsupportedOperationException.class)
        public final void testRemove() throws Exception {
                final TaskIterator iter = new TaskIterator();

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to