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