JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / swingjs / j2s / jssun / misc / Queue.js
1 Clazz.declarePackage ("jssun.misc");\r
2 Clazz.load (["java.util.Enumeration"], ["jssun.misc.Queue", "$.LIFOQueueEnumerator", "$.FIFOQueueEnumerator", "$.QueueElement"], ["java.util.NoSuchElementException", "swingjs.JSToolkit"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.length = 0;\r
5 this.head = null;\r
6 this.tail = null;\r
7 Clazz.instantialize (this, arguments);\r
8 }, jssun.misc, "Queue");\r
9 Clazz.makeConstructor (c$, \r
10 function () {\r
11 });\r
12 Clazz.defineMethod (c$, "enqueue", \r
13 function (obj) {\r
14 var newElt =  new jssun.misc.QueueElement (obj);\r
15 if (this.head == null) {\r
16 this.head = newElt;\r
17 this.tail = newElt;\r
18 this.length = 1;\r
19 } else {\r
20 newElt.next = this.head;\r
21 this.head.prev = newElt;\r
22 this.head = newElt;\r
23 this.length++;\r
24 }this.notify ();\r
25 }, "~O");\r
26 Clazz.defineMethod (c$, "dequeue", \r
27 function () {\r
28 return this.dequeue (0);\r
29 });\r
30 Clazz.defineMethod (c$, "dequeue", \r
31 function (timeOut) {\r
32 while (this.tail == null) {\r
33 swingjs.JSToolkit.warn ("Cannot wait in Queue.java");\r
34 this.wait (timeOut);\r
35 }\r
36 var elt = this.tail;\r
37 this.tail = elt.prev;\r
38 if (this.tail == null) {\r
39 this.head = null;\r
40 } else {\r
41 this.tail.next = null;\r
42 }this.length--;\r
43 return elt.obj;\r
44 }, "~N");\r
45 Clazz.defineMethod (c$, "isEmpty", \r
46 function () {\r
47 return (this.tail == null);\r
48 });\r
49 Clazz.defineMethod (c$, "elements", \r
50 function () {\r
51 return  new jssun.misc.LIFOQueueEnumerator (this);\r
52 });\r
53 Clazz.defineMethod (c$, "reverseElements", \r
54 function () {\r
55 return  new jssun.misc.FIFOQueueEnumerator (this);\r
56 });\r
57 Clazz.defineMethod (c$, "dump", \r
58 function (msg) {\r
59 System.err.println (">> " + msg);\r
60 System.err.println ("[" + this.length + " elt(s); head = " + (this.head == null ? "null" : (this.head.obj) + "") + " tail = " + (this.tail == null ? "null" : (this.tail.obj) + ""));\r
61 var cursor = this.head;\r
62 var last = null;\r
63 while (cursor != null) {\r
64 System.err.println ("  " + cursor);\r
65 last = cursor;\r
66 cursor = cursor.next;\r
67 }\r
68 if (last !== this.tail) {\r
69 System.err.println ("  tail != last: " + this.tail + ", " + last);\r
70 }System.err.println ("]");\r
71 }, "~S");\r
72 c$ = Clazz.decorateAsClass (function () {\r
73 this.queue = null;\r
74 this.cursor = null;\r
75 Clazz.instantialize (this, arguments);\r
76 }, jssun.misc, "FIFOQueueEnumerator", null, java.util.Enumeration);\r
77 Clazz.makeConstructor (c$, \r
78 function (q) {\r
79 this.queue = q;\r
80 this.cursor = q.tail;\r
81 }, "jssun.misc.Queue");\r
82 Clazz.overrideMethod (c$, "hasMoreElements", \r
83 function () {\r
84 return (this.cursor != null);\r
85 });\r
86 Clazz.overrideMethod (c$, "nextElement", \r
87 function () {\r
88 {\r
89 if (this.cursor != null) {\r
90 var result = this.cursor;\r
91 this.cursor = this.cursor.prev;\r
92 return result.obj;\r
93 }}throw  new java.util.NoSuchElementException ("FIFOQueueEnumerator");\r
94 });\r
95 c$ = Clazz.decorateAsClass (function () {\r
96 this.queue = null;\r
97 this.cursor = null;\r
98 Clazz.instantialize (this, arguments);\r
99 }, jssun.misc, "LIFOQueueEnumerator", null, java.util.Enumeration);\r
100 Clazz.makeConstructor (c$, \r
101 function (q) {\r
102 this.queue = q;\r
103 this.cursor = q.head;\r
104 }, "jssun.misc.Queue");\r
105 Clazz.overrideMethod (c$, "hasMoreElements", \r
106 function () {\r
107 return (this.cursor != null);\r
108 });\r
109 Clazz.overrideMethod (c$, "nextElement", \r
110 function () {\r
111 {\r
112 if (this.cursor != null) {\r
113 var result = this.cursor;\r
114 this.cursor = this.cursor.next;\r
115 return result.obj;\r
116 }}throw  new java.util.NoSuchElementException ("LIFOQueueEnumerator");\r
117 });\r
118 c$ = Clazz.decorateAsClass (function () {\r
119 this.next = null;\r
120 this.prev = null;\r
121 this.obj = null;\r
122 Clazz.instantialize (this, arguments);\r
123 }, jssun.misc, "QueueElement");\r
124 Clazz.makeConstructor (c$, \r
125 function (obj) {\r
126 this.obj = obj;\r
127 }, "~O");\r
128 Clazz.overrideMethod (c$, "toString", \r
129 function () {\r
130 return "QueueElement[obj=" + this.obj + (this.prev == null ? " null" : " prev") + (this.next == null ? " null" : " next") + "]";\r
131 });\r
132 });\r