summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david@procyon.(none)>2010-04-15 21:07:01 +0200
committerDavid A. Madore <david@procyon.(none)>2010-04-15 21:07:01 +0200
commit9176d80ae6dcad88da79714d934b226afe66c1ad (patch)
tree32c843f6e7e63d5e997525296b0921cc50f53ddb
parent5c6ccfca16a421860cd57d11e41d94d8a70cda76 (diff)
downloaddamlengine-9176d80ae6dcad88da79714d934b226afe66c1ad.tar.gz
damlengine-9176d80ae6dcad88da79714d934b226afe66c1ad.tar.bz2
damlengine-9176d80ae6dcad88da79714d934b226afe66c1ad.zip
Instantiate TodoDeque rather than using static variables.
Unfortunately, processing is now rather significantly slower.
-rw-r--r--org/madore/damlengine/DamlEngine.java5
-rw-r--r--org/madore/damlengine/ElementHandler.java5
-rw-r--r--org/madore/damlengine/TodoDeque.java42
-rw-r--r--org/madore/damlengine/TodoItem.java2
4 files changed, 30 insertions, 24 deletions
diff --git a/org/madore/damlengine/DamlEngine.java b/org/madore/damlengine/DamlEngine.java
index a2ce87e..b87b069 100644
--- a/org/madore/damlengine/DamlEngine.java
+++ b/org/madore/damlengine/DamlEngine.java
@@ -18,12 +18,13 @@ public final class DamlEngine {
private DamlEngine() { } // Forbid instantiation
public static void processDocument() {
+ TodoDeque todoDeque = new TodoDeque();
HashMap<String,Object> options = new HashMap<String,Object>();
options.put("isRoot", true);
- TodoDeque.registerAtEnd(new TodoElement(doc.getDocumentElement(),
+ todoDeque.registerAtEnd(new TodoElement(doc.getDocumentElement(),
new HashMap<String,Object>(),
options));
- TodoDeque.dispatchLoop();
+ todoDeque.dispatchLoop();
}
public static void main(String[] args)
diff --git a/org/madore/damlengine/ElementHandler.java b/org/madore/damlengine/ElementHandler.java
index 4e14756..59981ac 100644
--- a/org/madore/damlengine/ElementHandler.java
+++ b/org/madore/damlengine/ElementHandler.java
@@ -15,7 +15,7 @@ public abstract class ElementHandler {
new HashMap<String,Object>());
toProcess.add(it);
}
- TodoDeque.registerAtStart(toProcess);
+ that.ownerDeque.registerAtStart(toProcess);
}
public void handleNodeOnly(TodoElement that) {
@@ -30,10 +30,11 @@ public abstract class ElementHandler {
toProcess.add(it);
}
}
- TodoDeque.registerAtStart(toProcess);
+ that.ownerDeque.registerAtStart(toProcess);
}
public void handle(TodoElement that) {
+ assert(that.ownerDeque != null);
handleAttributes(that);
handleNodeOnly(that);
}
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() )
;
}
diff --git a/org/madore/damlengine/TodoItem.java b/org/madore/damlengine/TodoItem.java
index 677b3b1..84dfd05 100644
--- a/org/madore/damlengine/TodoItem.java
+++ b/org/madore/damlengine/TodoItem.java
@@ -2,6 +2,8 @@ package org.madore.damlengine;
public abstract class TodoItem {
+ public TodoDeque ownerDeque;
+
public abstract void dispatch();
}