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