d1150e101414915d83d0f15504f642b1817bf4c6
[jalviewjs.git] / site / swingjs / j2s / java / util / Stack.js
1 Clazz.load(["java.util.Vector"],"java.util.Stack",["java.util.EmptyStackException"],function(){
2 c$=Clazz.declareType(java.util,"Stack",java.util.Vector);
3 Clazz.defineMethod(c$,"empty",
4 function(){
5 return this.elementCount==0;
6 });
7 Clazz.defineMethod(c$,"peek",
8 function(){
9 try{
10 return this.elementData[this.elementCount-1];
11 }catch(e){
12 if(Clazz.instanceOf(e,IndexOutOfBoundsException)){
13 throw new java.util.EmptyStackException();
14 }else{
15 throw e;
16 }
17 }
18 });
19 Clazz.defineMethod(c$,"pop",
20 function(){
21 try{
22 var index=this.elementCount-1;
23 var obj=this.elementData[index];
24 this.removeElementAt(index);
25 return obj;
26 }catch(e){
27 if(Clazz.instanceOf(e,IndexOutOfBoundsException)){
28 throw new java.util.EmptyStackException();
29 }else{
30 throw e;
31 }
32 }
33 });
34 Clazz.defineMethod(c$,"push",
35 function(object){
36 this.addElement(object);
37 return object;
38 },"~O");
39 Clazz.defineMethod(c$,"search",
40 function(o){
41 var index=this.lastIndexOf(o);
42 if(index>=0)return(this.elementCount-index);
43 return-1;
44 },"~O");
45 });