diff options
Diffstat (limited to 'org/madore/damlengine/TodoDeque.java')
-rw-r--r-- | org/madore/damlengine/TodoDeque.java | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/org/madore/damlengine/TodoDeque.java b/org/madore/damlengine/TodoDeque.java index 037723b..eb90006 100644 --- a/org/madore/damlengine/TodoDeque.java +++ b/org/madore/damlengine/TodoDeque.java @@ -5,47 +5,49 @@ import java.util.LinkedList; public final class TodoDeque { - // FIXME: having everything static is ugly as hell... maybe this - // should be instantiatable? + private LinkedList<TodoItem> deque; - private TodoDeque() { } // Forbid instantiation - - private static LinkedList<TodoItem> todoDeque = new LinkedList<TodoItem>(); - - { - todoDeque = new LinkedList<TodoItem>(); + public TodoDeque() { + deque = new LinkedList<TodoItem>(); } - public static void registerAtEnd(TodoItem it) { - todoDeque.addLast(it); + public void registerAtEnd(TodoItem it) { + it.ownerDeque = this; + deque.addLast(it); } - public static void registerAtEnd(Collection<? extends TodoItem> them) { - todoDeque.addAll(them); + public void registerAtEnd(Collection<? extends TodoItem> them) { + for ( TodoItem it : them ) + it.ownerDeque = this; + deque.addAll(them); } - public static void registerAtStart(TodoItem it) { - todoDeque.addFirst(it); + public void registerAtStart(TodoItem it) { + it.ownerDeque = this; + deque.addFirst(it); } - public static void registerAtStart(Collection<? extends TodoItem> them) { - todoDeque.addAll(0, them); + public void registerAtStart(Collection<? extends TodoItem> them) { + for ( TodoItem it : them ) + it.ownerDeque = this; + deque.addAll(0, them); } - public static TodoItem removeNext() { - return todoDeque.poll(); + public TodoItem removeNext() { + return deque.poll(); } - public static boolean dispatchOne() { + public boolean dispatchOne() { TodoItem it = removeNext(); if ( it != null ) { + assert(it.ownerDeque == this); it.dispatch(); return true; } else return false; } - public static void dispatchLoop() { + public void dispatchLoop() { while ( dispatchOne() ) ; } |