45 private int modCount = 0;
48 private Node first =
null, last =
null;
70 first = last = newNode;
71 first.prec = first.succ =
null;
75 Node node = findPosition(ev);
78 newNode.succ.prec = newNode;
83 newNode.succ = node.succ;
85 if (newNode.succ !=
null)
86 newNode.succ.prec = newNode;
99 first = last = newNode;
102 newNode.succ = first;
103 first.prec = newNode;
111 while (node !=
null && node.ev.
compareTo(other) >= 0 && node.ev != other)
113 if (node.ev != other)
114 throw new IllegalArgumentException(
"Event not in list.");
117 newNode =
new Node();
121 newNode.prec = node.prec;
124 if (newNode.prec !=
null)
125 newNode.prec.succ = newNode;
133 while (node !=
null && node.ev.
compareTo(other) >= 0 && node.ev != other)
135 if (node.ev != other)
136 throw new IllegalArgumentException(
"Event not in list.");
139 newNode =
new Node();
144 newNode.succ = node.succ;
146 if (newNode.succ !=
null)
147 newNode.succ.prec = newNode;
154 return first ==
null ? null : first.ev;
159 while (node !=
null) {
160 if (node.ev.getClass().getName().equals(cl))
167 @SuppressWarnings(
"unchecked")
170 while (node !=
null) {
171 if (node.ev.getClass() == cl)
181 while (node !=
null && node.ev.
compareTo(ev) >= 0 && node.ev != ev)
183 if (node ==
null || node.ev != ev)
186 if (node == last && node == first)
193 node.succ.prec = node.prec;
198 node.prec.succ = node.succ;
228 public Iterator<Event> iterator() {
236 public String toString() {
237 StringBuilder sb =
new StringBuilder(
"Contents of the event list DoublyLinked:");
239 while (node !=
null) {
241 +
PrintfFormat.
g(8, 4, node.ev.priority()) +
" : " + node.ev.toString());
244 return sb.toString();
249 private static class Node {
254 private class DLItr
implements ListIterator<Event> {
257 private Node lastRet;
258 private int expectedModCount;
259 private int nextIndex;
264 expectedModCount = modCount;
269 public void add(Event ev) {
270 if (modCount != expectedModCount)
271 throw new ConcurrentModificationException();
274 if (next !=
null && ev.compareTo(next.ev) > 0) {
275 ev.setTime(next.ev.time());
276 ev.setPriority(next.ev.priority());
278 if (prev !=
null && ev.compareTo(prev.ev) < 0) {
279 ev.setTime(prev.ev.time());
280 ev.setPriority(prev.ev.priority());
284 newNode =
new Node();
292 first = last = newNode;
293 first.prec = first.succ =
null;
297 }
else if (prev ==
null) {
299 newNode.succ = first;
300 newNode.succ.prec = newNode;
309 if (newNode.succ !=
null)
310 newNode.succ.prec = newNode;
317 public boolean hasNext() {
318 if (modCount != expectedModCount)
319 throw new ConcurrentModificationException();
323 public boolean hasPrevious() {
324 if (modCount != expectedModCount)
325 throw new ConcurrentModificationException();
329 public Event next() {
331 throw new NoSuchElementException();
341 public int nextIndex() {
343 throw new NoSuchElementException();
348 public Event previous() {
350 throw new NoSuchElementException();
360 public int previousIndex() {
362 throw new NoSuchElementException();
364 return nextIndex - 1;
367 public void remove() {
368 if (modCount != expectedModCount)
369 throw new ConcurrentModificationException();
371 throw new IllegalStateException();
379 if (lastRet == last && lastRet == first) {
383 if (lastRet == last) {
387 lastRet.succ.prec = lastRet.prec;
388 if (lastRet == first) {
389 first = lastRet.succ;
392 lastRet.prec.succ = lastRet.succ;
404 public void set(Event ev) {
405 if (modCount != expectedModCount)
406 throw new ConcurrentModificationException();
408 throw new IllegalStateException();
411 if (lastRet.prec !=
null && ev.compareTo(lastRet.prec.ev) < 0) {
412 ev.setTime(lastRet.prec.ev.time());
413 ev.setPriority(lastRet.prec.ev.priority());
415 if (lastRet.succ !=
null && ev.compareTo(lastRet.succ.ev) > 0) {
416 ev.setTime(lastRet.succ.ev.time());
417 ev.setPriority(lastRet.succ.ev.priority());
424 private Node findPosition(Event ev) {
430 while (node !=
null && ev.compareTo(node.ev) < 0) {