blob: 39709388a4178759e1295a4737ac0a4d00ee1c1e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package org.madore.damlengine;
import java.util.Collection;
import java.util.LinkedList;
public final class TodoDeque {
protected final LinkedList<TodoItem> deque;
public TodoDeque() {
deque = new LinkedList<TodoItem>();
}
public void registerAtEnd(TodoItem it) {
it.setOwnerDeque(this);
deque.addLast(it);
}
public void registerAtEnd(Collection<? extends TodoItem> them) {
for ( TodoItem it : them )
it.setOwnerDeque(this);
deque.addAll(them);
}
public void registerAtStart(TodoItem it) {
it.setOwnerDeque(this);
deque.addFirst(it);
}
public void registerAtStart(Collection<? extends TodoItem> them) {
for ( TodoItem it : them )
it.setOwnerDeque(this);
deque.addAll(0, them);
}
public TodoItem removeNext() {
return deque.poll();
}
public boolean dispatchOne() {
TodoItem it = removeNext();
if ( it != null ) {
assert(it.getOwnerDeque() == this);
it.handle();
return true;
} else
return false;
}
public void dispatchLoop() {
while ( dispatchOne() )
;
}
}
|