1 Clazz.declarePackage ("java.util");
\r
2 Clazz.load (["java.util.AbstractCollection", "$.Iterator", "java.util.Deque"], "java.util.ArrayDeque", ["java.lang.AssertionError", "$.IllegalStateException", "$.NullPointerException", "java.lang.reflect.Array", "java.util.Arrays", "$.ConcurrentModificationException", "$.NoSuchElementException"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
4 this.elements = null;
\r
7 if (!Clazz.isClassDefined ("java.util.ArrayDeque.DeqIterator")) {
\r
8 java.util.ArrayDeque.$ArrayDeque$DeqIterator$ ();
\r
10 if (!Clazz.isClassDefined ("java.util.ArrayDeque.DescendingIterator")) {
\r
11 java.util.ArrayDeque.$ArrayDeque$DescendingIterator$ ();
\r
13 Clazz.instantialize (this, arguments);
\r
14 }, java.util, "ArrayDeque", java.util.AbstractCollection, [java.util.Deque, Cloneable, java.io.Serializable]);
\r
15 Clazz.defineMethod (c$, "allocateElements",
\r
16 function (numElements) {
\r
17 var initialCapacity = 8;
\r
18 if (numElements >= initialCapacity) {
\r
19 initialCapacity = numElements;
\r
20 initialCapacity |= (initialCapacity >>> 1);
\r
21 initialCapacity |= (initialCapacity >>> 2);
\r
22 initialCapacity |= (initialCapacity >>> 4);
\r
23 initialCapacity |= (initialCapacity >>> 8);
\r
24 initialCapacity |= (initialCapacity >>> 16);
\r
26 if (initialCapacity < 0) initialCapacity >>>= 1;
\r
27 }this.elements = new Array (initialCapacity);
\r
29 Clazz.defineMethod (c$, "doubleCapacity",
\r
32 var n = this.elements.length;
\r
34 var newCapacity = n << 1;
\r
35 if (newCapacity < 0) throw new IllegalStateException ("Sorry, deque too big");
\r
36 var a = new Array (newCapacity);
\r
37 System.arraycopy (this.elements, p, a, 0, r);
\r
38 System.arraycopy (this.elements, 0, a, r, p);
\r
43 Clazz.defineMethod (c$, "copyElements",
\r
45 if (this.head < this.tail) {
\r
46 System.arraycopy (this.elements, this.head, a, 0, this.size ());
\r
47 } else if (this.head > this.tail) {
\r
48 var headPortionLen = this.elements.length - this.head;
\r
49 System.arraycopy (this.elements, this.head, a, 0, headPortionLen);
\r
50 System.arraycopy (this.elements, 0, a, headPortionLen, this.tail);
\r
53 Clazz.makeConstructor (c$,
\r
55 Clazz.superConstructor (this, java.util.ArrayDeque, []);
\r
56 this.elements = new Array (16);
\r
58 Clazz.makeConstructor (c$,
\r
59 function (numElements) {
\r
60 Clazz.superConstructor (this, java.util.ArrayDeque, []);
\r
61 this.allocateElements (numElements);
\r
63 Clazz.makeConstructor (c$,
\r
65 Clazz.superConstructor (this, java.util.ArrayDeque, []);
\r
66 this.allocateElements (c.size ());
\r
68 }, "java.util.Collection");
\r
69 Clazz.overrideMethod (c$, "addFirst",
\r
71 if (e == null) throw new NullPointerException ();
\r
72 this.elements[this.head = (this.head - 1) & (this.elements.length - 1)] = e;
\r
73 if (this.head == this.tail) this.doubleCapacity ();
\r
75 Clazz.overrideMethod (c$, "addLast",
\r
77 if (e == null) throw new NullPointerException ();
\r
78 this.elements[this.tail] = e;
\r
79 if ((this.tail = (this.tail + 1) & (this.elements.length - 1)) == this.head) this.doubleCapacity ();
\r
81 Clazz.overrideMethod (c$, "offerFirst",
\r
86 Clazz.overrideMethod (c$, "offerLast",
\r
91 Clazz.overrideMethod (c$, "removeFirst",
\r
93 var x = this.pollFirst ();
\r
94 if (x == null) throw new java.util.NoSuchElementException ();
\r
97 Clazz.overrideMethod (c$, "removeLast",
\r
99 var x = this.pollLast ();
\r
100 if (x == null) throw new java.util.NoSuchElementException ();
\r
103 Clazz.overrideMethod (c$, "pollFirst",
\r
106 var result = this.elements[h];
\r
107 if (result == null) return null;
\r
108 this.elements[h] = null;
\r
109 this.head = (h + 1) & (this.elements.length - 1);
\r
112 Clazz.overrideMethod (c$, "pollLast",
\r
114 var t = (this.tail - 1) & (this.elements.length - 1);
\r
115 var result = this.elements[t];
\r
116 if (result == null) return null;
\r
117 this.elements[t] = null;
\r
121 Clazz.overrideMethod (c$, "getFirst",
\r
123 var x = this.elements[this.head];
\r
124 if (x == null) throw new java.util.NoSuchElementException ();
\r
127 Clazz.overrideMethod (c$, "getLast",
\r
129 var x = this.elements[(this.tail - 1) & (this.elements.length - 1)];
\r
130 if (x == null) throw new java.util.NoSuchElementException ();
\r
133 Clazz.overrideMethod (c$, "peekFirst",
\r
135 return this.elements[this.head];
\r
137 Clazz.overrideMethod (c$, "peekLast",
\r
139 return this.elements[(this.tail - 1) & (this.elements.length - 1)];
\r
141 Clazz.overrideMethod (c$, "removeFirstOccurrence",
\r
143 if (o == null) return false;
\r
144 var mask = this.elements.length - 1;
\r
147 while ((x = this.elements[i]) != null) {
\r
148 if (o.equals (x)) {
\r
151 }i = (i + 1) & mask;
\r
155 Clazz.overrideMethod (c$, "removeLastOccurrence",
\r
157 if (o == null) return false;
\r
158 var mask = this.elements.length - 1;
\r
159 var i = (this.tail - 1) & mask;
\r
161 while ((x = this.elements[i]) != null) {
\r
162 if (o.equals (x)) {
\r
165 }i = (i - 1) & mask;
\r
169 Clazz.overrideMethod (c$, "add",
\r
174 Clazz.overrideMethod (c$, "offer",
\r
176 return this.offerLast (e);
\r
178 Clazz.defineMethod (c$, "remove",
\r
180 return this.removeFirst ();
\r
182 Clazz.overrideMethod (c$, "poll",
\r
184 return this.pollFirst ();
\r
186 Clazz.overrideMethod (c$, "element",
\r
188 return this.getFirst ();
\r
190 Clazz.overrideMethod (c$, "peek",
\r
192 return this.peekFirst ();
\r
194 Clazz.overrideMethod (c$, "push",
\r
198 Clazz.overrideMethod (c$, "pop",
\r
200 return this.removeFirst ();
\r
202 Clazz.defineMethod (c$, "checkInvariants",
\r
205 Clazz.defineMethod (c$, "$delete",
\r
207 this.checkInvariants ();
\r
208 var elements = this.elements;
\r
209 var mask = elements.length - 1;
\r
212 var front = (i - h) & mask;
\r
213 var back = (t - i) & mask;
\r
214 if (front >= ((t - h) & mask)) throw new java.util.ConcurrentModificationException ();
\r
215 if (front < back) {
\r
217 System.arraycopy (elements, h, elements, h + 1, front);
\r
219 System.arraycopy (elements, 0, elements, 1, i);
\r
220 elements[0] = elements[mask];
\r
221 System.arraycopy (elements, h, elements, h + 1, mask - h);
\r
222 }elements[h] = null;
\r
223 this.head = (h + 1) & mask;
\r
227 System.arraycopy (elements, i + 1, elements, i, back);
\r
230 System.arraycopy (elements, i + 1, elements, i, mask - i);
\r
231 elements[mask] = elements[0];
\r
232 System.arraycopy (elements, 1, elements, 0, t);
\r
233 this.tail = (t - 1) & mask;
\r
236 Clazz.overrideMethod (c$, "size",
\r
238 return (this.tail - this.head) & (this.elements.length - 1);
\r
240 Clazz.overrideMethod (c$, "isEmpty",
\r
242 return this.head == this.tail;
\r
244 Clazz.overrideMethod (c$, "iterator",
\r
246 return Clazz.innerTypeInstance (java.util.ArrayDeque.DeqIterator, this, null);
\r
248 Clazz.overrideMethod (c$, "descendingIterator",
\r
250 return Clazz.innerTypeInstance (java.util.ArrayDeque.DescendingIterator, this, null);
\r
252 Clazz.overrideMethod (c$, "contains",
\r
254 if (o == null) return false;
\r
255 var mask = this.elements.length - 1;
\r
258 while ((x = this.elements[i]) != null) {
\r
259 if (o.equals (x)) return true;
\r
260 i = (i + 1) & mask;
\r
264 Clazz.defineMethod (c$, "remove",
\r
266 return this.removeFirstOccurrence (o);
\r
268 Clazz.overrideMethod (c$, "clear",
\r
273 this.head = this.tail = 0;
\r
275 var mask = this.elements.length - 1;
\r
277 this.elements[i] = null;
\r
278 i = (i + 1) & mask;
\r
281 Clazz.defineMethod (c$, "toArray",
\r
283 return this.copyElements ( new Array (this.size ()));
\r
285 Clazz.defineMethod (c$, "toArray",
\r
287 var size = this.size ();
\r
288 if (a.length < size) a = java.lang.reflect.Array.newInstance (a.getClass ().getComponentType (), size);
\r
289 this.copyElements (a);
\r
290 if (a.length > size) a[size] = null;
\r
293 Clazz.defineMethod (c$, "clone",
\r
296 var result = Clazz.superCall (this, java.util.ArrayDeque, "clone", []);
\r
297 result.elements = java.util.Arrays.copyOf (this.elements, this.elements.length);
\r
300 if (Clazz.exceptionOf (e, CloneNotSupportedException)) {
\r
301 throw new AssertionError ();
\r
307 c$.$ArrayDeque$DeqIterator$ = function () {
\r
308 Clazz.pu$h(self.c$);
\r
309 c$ = Clazz.decorateAsClass (function () {
\r
310 Clazz.prepareCallback (this, arguments);
\r
314 Clazz.instantialize (this, arguments);
\r
315 }, java.util.ArrayDeque, "DeqIterator", null, java.util.Iterator);
\r
316 Clazz.prepareFields (c$, function () {
\r
317 this.cursor = this.b$["java.util.ArrayDeque"].head;
\r
318 this.fence = this.b$["java.util.ArrayDeque"].tail;
\r
320 Clazz.overrideMethod (c$, "hasNext",
\r
322 return this.cursor != this.fence;
\r
324 Clazz.overrideMethod (c$, "next",
\r
326 if (this.cursor == this.fence) throw new java.util.NoSuchElementException ();
\r
327 var a = this.b$["java.util.ArrayDeque"].elements[this.cursor];
\r
328 if (this.b$["java.util.ArrayDeque"].tail != this.fence || a == null) throw new java.util.ConcurrentModificationException ();
\r
329 this.lastRet = this.cursor;
\r
330 this.cursor = (this.cursor + 1) & (this.b$["java.util.ArrayDeque"].elements.length - 1);
\r
333 Clazz.overrideMethod (c$, "remove",
\r
335 if (this.lastRet < 0) throw new IllegalStateException ();
\r
336 if (this.b$["java.util.ArrayDeque"].$delete (this.lastRet)) {
\r
337 this.cursor = (this.cursor - 1) & (this.b$["java.util.ArrayDeque"].elements.length - 1);
\r
338 this.fence = this.b$["java.util.ArrayDeque"].tail;
\r
339 }this.lastRet = -1;
\r
343 c$.$ArrayDeque$DescendingIterator$ = function () {
\r
344 Clazz.pu$h(self.c$);
\r
345 c$ = Clazz.decorateAsClass (function () {
\r
346 Clazz.prepareCallback (this, arguments);
\r
350 Clazz.instantialize (this, arguments);
\r
351 }, java.util.ArrayDeque, "DescendingIterator", null, java.util.Iterator);
\r
352 Clazz.prepareFields (c$, function () {
\r
353 this.cursor = this.b$["java.util.ArrayDeque"].tail;
\r
354 this.fence = this.b$["java.util.ArrayDeque"].head;
\r
356 Clazz.overrideMethod (c$, "hasNext",
\r
358 return this.cursor != this.fence;
\r
360 Clazz.overrideMethod (c$, "next",
\r
362 if (this.cursor == this.fence) throw new java.util.NoSuchElementException ();
\r
363 this.cursor = (this.cursor - 1) & (this.b$["java.util.ArrayDeque"].elements.length - 1);
\r
364 var a = this.b$["java.util.ArrayDeque"].elements[this.cursor];
\r
365 if (this.b$["java.util.ArrayDeque"].head != this.fence || a == null) throw new java.util.ConcurrentModificationException ();
\r
366 this.lastRet = this.cursor;
\r
369 Clazz.overrideMethod (c$, "remove",
\r
371 if (this.lastRet < 0) throw new IllegalStateException ();
\r
372 if (!this.b$["java.util.ArrayDeque"].$delete (this.lastRet)) {
\r
373 this.cursor = (this.cursor + 1) & (this.b$["java.util.ArrayDeque"].elements.length - 1);
\r
374 this.fence = this.b$["java.util.ArrayDeque"].head;
\r
375 }this.lastRet = -1;
\r
379 Clazz.defineStatics (c$,
\r
380 "MIN_INITIAL_CAPACITY", 8);
\r