JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / java / util / Vector.js
1 Clazz.load(["java.util.AbstractList","$.List","$.RandomAccess"],"java.util.Vector",["java.lang.ArrayIndexOutOfBoundsException","$.IllegalArgumentException","$.IndexOutOfBoundsException","$.StringBuffer","java.lang.reflect.Array","java.util.Arrays","$.Collections","$.Enumeration","$.NoSuchElementException"],function(){\r
2 c$=Clazz.decorateAsClass(function(){\r
3 this.elementCount=0;\r
4 this.elementData=null;\r
5 this.capacityIncrement=0;\r
6 Clazz.instantialize(this,arguments);\r
7 },java.util,"Vector",java.util.AbstractList,[java.util.List,java.util.RandomAccess,Cloneable,java.io.Serializable]);\r
8 Clazz.makeConstructor(c$,\r
9 function(){\r
10 this.construct(10,0);\r
11 });\r
12 Clazz.makeConstructor(c$,\r
13 function(capacity){\r
14 this.construct(capacity,0);\r
15 },"~N");\r
16 Clazz.makeConstructor(c$,\r
17 function(capacity,capacityIncrement){\r
18 Clazz.superConstructor(this,java.util.Vector,[]);\r
19 this.elementCount=0;\r
20 try{\r
21 this.elementData=this.newElementArray(capacity);\r
22 }catch(e){\r
23 if(Clazz.instanceOf(e,NegativeArraySizeException)){\r
24 throw new IllegalArgumentException();\r
25 }else{\r
26 throw e;\r
27 }\r
28 }\r
29 this.capacityIncrement=capacityIncrement;\r
30 },"~N,~N");\r
31 Clazz.makeConstructor(c$,\r
32 function(collection){\r
33 this.construct(collection.size(),0);\r
34 var it=collection.iterator();\r
35 while(it.hasNext()){\r
36 this.elementData[this.elementCount++]=it.next();\r
37 }\r
38 },"java.util.Collection");\r
39 Clazz.defineMethod(c$,"newElementArray",\r
40 ($fz=function(size){\r
41 return new Array(size);\r
42 },$fz.isPrivate=true,$fz),"~N");\r
43 Clazz.defineMethod(c$,"add",\r
44 function(location,object){\r
45 this.insertElementAt(object,location);\r
46 },"~N,~O");\r
47 Clazz.defineMethod(c$,"add",\r
48 function(object){\r
49 this.addElement(object);\r
50 return true;\r
51 },"~O");\r
52 Clazz.defineMethod(c$,"addAll",\r
53 function(location,collection){\r
54 if(0<=location&&location<=this.elementCount){\r
55 var size=collection.size();\r
56 if(size==0){\r
57 return false;\r
58 }var required=size-(this.elementData.length-this.elementCount);\r
59 if(required>0){\r
60 this.growBy(required);\r
61 }var count=this.elementCount-location;\r
62 if(count>0){\r
63 System.arraycopy(this.elementData,location,this.elementData,location+size,count);\r
64 }var it=collection.iterator();\r
65 while(it.hasNext()){\r
66 this.elementData[location++]=it.next();\r
67 }\r
68 this.elementCount+=size;\r
69 this.modCount++;\r
70 return true;\r
71 }throw new ArrayIndexOutOfBoundsException(location);\r
72 },"~N,java.util.Collection");\r
73 Clazz.defineMethod(c$,"addAll",\r
74 function(collection){\r
75 return this.addAll(this.elementCount,collection);\r
76 },"java.util.Collection");\r
77 Clazz.defineMethod(c$,"addElement",\r
78 function(object){\r
79 if(this.elementCount==this.elementData.length){\r
80 this.growByOne();\r
81 }this.elementData[this.elementCount++]=object;\r
82 this.modCount++;\r
83 },"~O");\r
84 Clazz.defineMethod(c$,"capacity",\r
85 function(){\r
86 return this.elementData.length;\r
87 });\r
88 Clazz.overrideMethod(c$,"clear",\r
89 function(){\r
90 this.removeAllElements();\r
91 });\r
92 Clazz.defineMethod(c$,"clone",\r
93 function(){\r
94 try{\r
95 var vector=Clazz.superCall(this,java.util.Vector,"clone",[]);\r
96 vector.elementData=this.elementData.clone();\r
97 return vector;\r
98 }catch(e){\r
99 if(Clazz.instanceOf(e,CloneNotSupportedException)){\r
100 return null;\r
101 }else{\r
102 throw e;\r
103 }\r
104 }\r
105 });\r
106 Clazz.overrideMethod(c$,"contains",\r
107 function(object){\r
108 return this.indexOf(object,0)!=-1;\r
109 },"~O");\r
110 Clazz.defineMethod(c$,"copyInto",\r
111 function(elements){\r
112 System.arraycopy(this.elementData,0,elements,0,this.elementCount);\r
113 },"~A");\r
114 Clazz.defineMethod(c$,"elementAt",\r
115 function(location){\r
116 if(location<this.elementCount){\r
117 return this.elementData[location];\r
118 }throw new ArrayIndexOutOfBoundsException(location);\r
119 },"~N");\r
120 Clazz.defineMethod(c$,"elements",\r
121 function(){\r
122 return((Clazz.isClassDefined("java.util.Vector$1")?0:java.util.Vector.$Vector$1$()),Clazz.innerTypeInstance(java.util.Vector$1,this,null));\r
123 });\r
124 Clazz.defineMethod(c$,"ensureCapacity",\r
125 function(minimumCapacity){\r
126 if(this.elementData.length<minimumCapacity){\r
127 var next=(this.capacityIncrement<=0?this.elementData.length:this.capacityIncrement)+this.elementData.length;\r
128 this.grow(minimumCapacity>next?minimumCapacity:next);\r
129 }},"~N");\r
130 Clazz.overrideMethod(c$,"equals",\r
131 function(object){\r
132 if(this===object){\r
133 return true;\r
134 }if(Clazz.instanceOf(object,java.util.List)){\r
135 var list=object;\r
136 if(list.size()!=this.size()){\r
137 return false;\r
138 }var index=0;\r
139 var it=list.iterator();\r
140 while(it.hasNext()){\r
141 var e1=this.elementData[index++];\r
142 var e2=it.next();\r
143 if(!(e1==null?e2==null:e1.equals(e2))){\r
144 return false;\r
145 }}\r
146 return true;\r
147 }return false;\r
148 },"~O");\r
149 Clazz.defineMethod(c$,"firstElement",\r
150 function(){\r
151 if(this.elementCount>0){\r
152 return this.elementData[0];\r
153 }throw new java.util.NoSuchElementException();\r
154 });\r
155 Clazz.overrideMethod(c$,"get",\r
156 function(location){\r
157 return this.elementAt(location);\r
158 },"~N");\r
159 Clazz.defineMethod(c$,"grow",\r
160 ($fz=function(newCapacity){\r
161 var newData=this.newElementArray(newCapacity);\r
162 System.arraycopy(this.elementData,0,newData,0,this.elementCount);\r
163 this.elementData=newData;\r
164 },$fz.isPrivate=true,$fz),"~N");\r
165 Clazz.defineMethod(c$,"growByOne",\r
166 ($fz=function(){\r
167 var adding=0;\r
168 if(this.capacityIncrement<=0){\r
169 if((adding=this.elementData.length)==0){\r
170 adding=1;\r
171 }}else{\r
172 adding=this.capacityIncrement;\r
173 }var newData=this.newElementArray(this.elementData.length+adding);\r
174 System.arraycopy(this.elementData,0,newData,0,this.elementCount);\r
175 this.elementData=newData;\r
176 },$fz.isPrivate=true,$fz));\r
177 Clazz.defineMethod(c$,"growBy",\r
178 ($fz=function(required){\r
179 var adding=0;\r
180 if(this.capacityIncrement<=0){\r
181 if((adding=this.elementData.length)==0){\r
182 adding=required;\r
183 }while(adding<required){\r
184 adding+=adding;\r
185 }\r
186 }else{\r
187 adding=(Math.floor(required/this.capacityIncrement))*this.capacityIncrement;\r
188 if(adding<required){\r
189 adding+=this.capacityIncrement;\r
190 }}var newData=this.newElementArray(this.elementData.length+adding);\r
191 System.arraycopy(this.elementData,0,newData,0,this.elementCount);\r
192 this.elementData=newData;\r
193 },$fz.isPrivate=true,$fz),"~N");\r
194 Clazz.overrideMethod(c$,"hashCode",\r
195 function(){\r
196 var result=1;\r
197 for(var i=0;i<this.elementCount;i++){\r
198 result=(31*result)+(this.elementData[i]==null?0:this.elementData[i].hashCode());\r
199 }\r
200 return result;\r
201 });\r
202 Clazz.defineMethod(c$,"indexOf",\r
203 function(object){\r
204 return this.indexOf(object,0);\r
205 },"~O");\r
206 Clazz.defineMethod(c$,"indexOf",\r
207 function(object,location){\r
208 if(object!=null){\r
209 for(var i=location;i<this.elementCount;i++){\r
210 if(object.equals(this.elementData[i])){\r
211 return i;\r
212 }}\r
213 }else{\r
214 for(var i=location;i<this.elementCount;i++){\r
215 if(this.elementData[i]==null){\r
216 return i;\r
217 }}\r
218 }return-1;\r
219 },"~O,~N");\r
220 Clazz.defineMethod(c$,"insertElementAt",\r
221 function(object,location){\r
222 if(0<=location&&location<=this.elementCount){\r
223 if(this.elementCount==this.elementData.length){\r
224 this.growByOne();\r
225 }var count=this.elementCount-location;\r
226 if(count>0){\r
227 System.arraycopy(this.elementData,location,this.elementData,location+1,count);\r
228 }this.elementData[location]=object;\r
229 this.elementCount++;\r
230 this.modCount++;\r
231 }else{\r
232 throw new ArrayIndexOutOfBoundsException(location);\r
233 }},"~O,~N");\r
234 Clazz.overrideMethod(c$,"isEmpty",\r
235 function(){\r
236 return this.elementCount==0;\r
237 });\r
238 Clazz.defineMethod(c$,"lastElement",\r
239 function(){\r
240 try{\r
241 return this.elementData[this.elementCount-1];\r
242 }catch(e){\r
243 if(Clazz.instanceOf(e,IndexOutOfBoundsException)){\r
244 throw new java.util.NoSuchElementException();\r
245 }else{\r
246 throw e;\r
247 }\r
248 }\r
249 });\r
250 Clazz.defineMethod(c$,"lastIndexOf",\r
251 function(object){\r
252 return this.lastIndexOf(object,this.elementCount-1);\r
253 },"~O");\r
254 Clazz.defineMethod(c$,"lastIndexOf",\r
255 function(object,location){\r
256 if(location<this.elementCount){\r
257 if(object!=null){\r
258 for(var i=location;i>=0;i--){\r
259 if(object.equals(this.elementData[i])){\r
260 return i;\r
261 }}\r
262 }else{\r
263 for(var i=location;i>=0;i--){\r
264 if(this.elementData[i]==null){\r
265 return i;\r
266 }}\r
267 }return-1;\r
268 }throw new ArrayIndexOutOfBoundsException(location);\r
269 },"~O,~N");\r
270 Clazz.defineMethod(c$,"remove",\r
271 function(location){\r
272 if(location<this.elementCount){\r
273 var result=this.elementData[location];\r
274 this.elementCount--;\r
275 var size=this.elementCount-location;\r
276 if(size>0){\r
277 System.arraycopy(this.elementData,location+1,this.elementData,location,size);\r
278 }this.elementData[this.elementCount]=null;\r
279 this.modCount++;\r
280 return result;\r
281 }throw new ArrayIndexOutOfBoundsException(location);\r
282 },"~N");\r
283 Clazz.defineMethod(c$,"remove",\r
284 function(object){\r
285 return this.removeElement(object);\r
286 },"~O");\r
287 Clazz.defineMethod(c$,"removeAllElements",\r
288 function(){\r
289 java.util.Arrays.fill(this.elementData,0,this.elementCount,null);\r
290 this.modCount++;\r
291 this.elementCount=0;\r
292 });\r
293 Clazz.defineMethod(c$,"removeElement",\r
294 function(object){\r
295 var index;\r
296 if((index=this.indexOf(object,0))==-1){\r
297 return false;\r
298 }this.removeElementAt(index);\r
299 return true;\r
300 },"~O");\r
301 Clazz.defineMethod(c$,"removeElementAt",\r
302 function(location){\r
303 if(0<=location&&location<this.elementCount){\r
304 this.elementCount--;\r
305 var size=this.elementCount-location;\r
306 if(size>0){\r
307 System.arraycopy(this.elementData,location+1,this.elementData,location,size);\r
308 }this.elementData[this.elementCount]=null;\r
309 this.modCount++;\r
310 }else{\r
311 throw new ArrayIndexOutOfBoundsException(location);\r
312 }},"~N");\r
313 Clazz.overrideMethod(c$,"removeRange",\r
314 function(start,end){\r
315 if(start>=0&&start<=end&&end<=this.size()){\r
316 if(start==end){\r
317 return;\r
318 }if(end!=this.elementCount){\r
319 System.arraycopy(this.elementData,end,this.elementData,start,this.elementCount-end);\r
320 var newCount=this.elementCount-(end-start);\r
321 java.util.Arrays.fill(this.elementData,newCount,this.elementCount,null);\r
322 this.elementCount=newCount;\r
323 }else{\r
324 java.util.Arrays.fill(this.elementData,start,this.elementCount,null);\r
325 this.elementCount=start;\r
326 }this.modCount++;\r
327 }else{\r
328 throw new IndexOutOfBoundsException();\r
329 }},"~N,~N");\r
330 Clazz.overrideMethod(c$,"set",\r
331 function(location,object){\r
332 if(location<this.elementCount){\r
333 var result=this.elementData[location];\r
334 this.elementData[location]=object;\r
335 return result;\r
336 }throw new ArrayIndexOutOfBoundsException(location);\r
337 },"~N,~O");\r
338 Clazz.defineMethod(c$,"setElementAt",\r
339 function(object,location){\r
340 if(location<this.elementCount){\r
341 this.elementData[location]=object;\r
342 }else{\r
343 throw new ArrayIndexOutOfBoundsException(location);\r
344 }},"~O,~N");\r
345 Clazz.defineMethod(c$,"setSize",\r
346 function(length){\r
347 if(length==this.elementCount){\r
348 return;\r
349 }this.ensureCapacity(length);\r
350 if(this.elementCount>length){\r
351 java.util.Arrays.fill(this.elementData,length,this.elementCount,null);\r
352 }this.elementCount=length;\r
353 this.modCount++;\r
354 },"~N");\r
355 Clazz.overrideMethod(c$,"size",\r
356 function(){\r
357 return this.elementCount;\r
358 });\r
359 Clazz.overrideMethod(c$,"subList",\r
360 function(start,end){\r
361 return new java.util.Collections.SynchronizedRandomAccessList(Clazz.superCall(this,java.util.Vector,"subList",[start,end]),this);\r
362 },"~N,~N");\r
363 Clazz.defineMethod(c$,"toArray",\r
364 function(){\r
365 var result=new Array(this.elementCount);\r
366 System.arraycopy(this.elementData,0,result,0,this.elementCount);\r
367 return result;\r
368 });\r
369 Clazz.defineMethod(c$,"toArray",\r
370 function(contents){\r
371 if(this.elementCount>contents.length){\r
372 var ct=contents.getClass().getComponentType();\r
373 contents=java.lang.reflect.Array.newInstance(ct,this.elementCount);\r
374 }System.arraycopy(this.elementData,0,contents,0,this.elementCount);\r
375 if(this.elementCount<contents.length){\r
376 contents[this.elementCount]=null;\r
377 }return contents;\r
378 },"~A");\r
379 Clazz.overrideMethod(c$,"toString",\r
380 function(){\r
381 if(this.elementCount==0){\r
382 return"[]";\r
383 }var length=this.elementCount-1;\r
384 var buffer=new StringBuffer(this.size()*16);\r
385 buffer.append('[');\r
386 for(var i=0;i<length;i++){\r
387 if(this.elementData[i]===this){\r
388 buffer.append("(this Collection)");\r
389 }else{\r
390 buffer.append(this.elementData[i]);\r
391 }buffer.append(", ");\r
392 }\r
393 if(this.elementData[length]===this){\r
394 buffer.append("(this Collection)");\r
395 }else{\r
396 buffer.append(this.elementData[length]);\r
397 }buffer.append(']');\r
398 return buffer.toString();\r
399 });\r
400 Clazz.defineMethod(c$,"trimToSize",\r
401 function(){\r
402 if(this.elementData.length!=this.elementCount){\r
403 this.grow(this.elementCount);\r
404 }});\r
405 c$.$Vector$1$=function(){\r
406 Clazz.pu$h(self.c$);\r
407 c$=Clazz.decorateAsClass(function(){\r
408 Clazz.prepareCallback(this,arguments);\r
409 this.pos=0;\r
410 Clazz.instantialize(this,arguments);\r
411 },java.util,"Vector$1",null,java.util.Enumeration);\r
412 Clazz.overrideMethod(c$,"hasMoreElements",\r
413 function(){\r
414 return this.pos<this.b$["java.util.Vector"].elementCount;\r
415 });\r
416 Clazz.overrideMethod(c$,"nextElement",\r
417 function(){\r
418 {\r
419 if(this.pos<this.b$["java.util.Vector"].elementCount){\r
420 return this.b$["java.util.Vector"].elementData[this.pos++];\r
421 }}throw new java.util.NoSuchElementException();\r
422 });\r
423 c$=Clazz.p0p();\r
424 };\r
425 Clazz.defineStatics(c$,\r
426 "DEFAULT_SIZE",10);\r
427 });\r