From 9176d80ae6dcad88da79714d934b226afe66c1ad Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Thu, 15 Apr 2010 21:07:01 +0200 Subject: Instantiate TodoDeque rather than using static variables. Unfortunately, processing is now rather significantly slower. --- org/madore/damlengine/TodoDeque.java | 42 +++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'org/madore/damlengine/TodoDeque.java') 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 deque; - private TodoDeque() { } // Forbid instantiation - - private static LinkedList todoDeque = new LinkedList(); - - { - todoDeque = new LinkedList(); + public TodoDeque() { + deque = new LinkedList(); } - 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 them) { - todoDeque.addAll(them); + public void registerAtEnd(Collection 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 them) { - todoDeque.addAll(0, them); + public void registerAtStart(Collection 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() ) ; } -- cgit v1.2.3