X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fj2s%2Fjava%2Futil%2FArrayList.js;h=71e92a9043f0e5db2f2d6f6b7d914346c0e086bc;hp=f3a0bf45b9dc2caade1001d675ba1a73bb638afe;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=7301a2415adab88038b291fc54caeeb3a5a47a44 diff --git a/site/j2s/java/util/ArrayList.js b/site/j2s/java/util/ArrayList.js index f3a0bf4..71e92a9 100644 --- a/site/j2s/java/util/ArrayList.js +++ b/site/j2s/java/util/ArrayList.js @@ -1,406 +1,406 @@ -Clazz.load(["java.util.AbstractList","$.List","$.RandomAccess"],"java.util.ArrayList",["java.lang.IllegalArgumentException","$.IndexOutOfBoundsException","java.lang.reflect.Array","java.util.Arrays"],function(){ -c$=Clazz.decorateAsClass(function(){ -this.firstIndex=0; -this.lastIndex=0; -this.array=null; -Clazz.instantialize(this,arguments); -},java.util,"ArrayList",java.util.AbstractList,[java.util.List,Cloneable,java.io.Serializable,java.util.RandomAccess]); - -Clazz.overrideConstructor(c$, -function(){ -this.setup(0); -}); - -Clazz.defineMethod(c$, "setup", -function(capacity){ -//Clazz.superConstructor(this,java.util.ArrayList,[]); -this.firstIndex=this.lastIndex=0; -try{ -this.array=this.newElementArray(capacity); -}catch(e){ -if(Clazz.instanceOf(e,NegativeArraySizeException)){ -throw new IllegalArgumentException(); -}else{ -throw e; -} -} -},"~N"); -/* -Clazz.makeConstructor(c$, -function(collection){ -Clazz.superConstructor(this,java.util.ArrayList,[]); -var size=collection.size(); -this.firstIndex=this.lastIndex=0; -this.array=this.newElementArray(size+(Math.floor(size/10))); -this.addAll(collection); -},"java.util.Collection"); - -*/ - -Clazz.defineMethod(c$,"newElementArray", -($fz=function(size){ -return new Array(size); -},$fz.isPrivate=true,$fz),"~N"); - -Clazz.overrideMethod(c$,"add", -function(location,object){ - -if (arguments.length == 1) { - // coming from Java methods, e.g. Collections.list() - // location is actually the object - return this.add1(location); -} -var size=this.size(); -if(00)||this.lastIndex==this.array.length){ -System.arraycopy(this.array,this.firstIndex,this.array,--this.firstIndex,location); -}else{ -var index=location+this.firstIndex; -System.arraycopy(this.array,index,this.array,index+1,size-location); -this.lastIndex++; -}this.array[location+this.firstIndex]=object; -}else if(location==0){ -if(this.firstIndex==0){ -this.growAtFront(1); -}this.array[--this.firstIndex]=object; -}else if(location==size){ -if(this.lastIndex==this.array.length){ -this.growAtEnd(1); -}this.array[this.lastIndex++]=object; -}else{ -throw new IndexOutOfBoundsException(); -}this.modCount++; -},"~N,~O"); - -Clazz.overrideMethod(c$,"add1", -function(object){ -if(this.lastIndex==this.array.length){ -this.growAtEnd(1); -}this.array[this.lastIndex++]=object; -this.modCount++; -return true; -},"~O"); - -/* BH disallow addAll(int,List) - * -Clazz.defineMethod(c$,"addAll", -function(location,collection){ -var size=this.size(); -if(location<0||location>size){ -throw new IndexOutOfBoundsException(); -}var growSize=collection.size(); -if(00)||this.lastIndex>this.array.length-growSize){ -var newFirst=this.firstIndex-growSize; -if(newFirst<0){ -var index=location+this.firstIndex; -System.arraycopy(this.array,index,this.array,index-newFirst,size-location); -this.lastIndex-=newFirst; -newFirst=0; -}System.arraycopy(this.array,this.firstIndex,this.array,newFirst,location); -this.firstIndex=newFirst; -}else{ -var index=location+this.firstIndex; -System.arraycopy(this.array,index,this.array,index+growSize,size-location); -this.lastIndex+=growSize; -}}else if(location==0){ -this.growAtFront(growSize); -this.firstIndex-=growSize; -}else if(location==size){ -if(this.lastIndex>this.array.length-growSize){ -this.growAtEnd(growSize); -}this.lastIndex+=growSize; -}if(growSize>0){ -var it=collection.iterator(); -var index=location+this.firstIndex; -var end=index+growSize; -while(index0){ - if(this.lastIndex>this.array.length-growSize){ - this.growAtEnd(growSize); -} -var it=collection.iterator(); -var end=this.lastIndex+growSize; -while(this.lastIndex= i1;) -this.array[i] = null; -},"~N,~N"); - -Clazz.defineMethod(c$,"clone", -function(){ -try{ -var newList=Clazz.superCall(this,java.util.ArrayList,"clone",[]); -newList.array=this.array.clone(); -return newList; -}catch(e){ -if(Clazz.instanceOf(e,CloneNotSupportedException)){ -return null; -}else{ -throw e; -} -} -}); -Clazz.overrideMethod(c$,"contains", -function(object){ -if(object!=null){ -for(var i=this.firstIndex;i0){ -this.growAtFront(minimumCapacity-this.array.length); -}else{ -this.growAtEnd(minimumCapacity-this.array.length); -}}},"~N"); -Clazz.overrideMethod(c$,"get", -function(location){ -if(0<=location&&location=required-(this.array.length-this.lastIndex)){ - var newLast=this.lastIndex-this.firstIndex; - if(size>0){ - System.arraycopy(this.array,this.firstIndex,this.array,0,size); - var start=newLastincrement){ - increment=required; - } - if(increment<12){ - increment=12; - } - var newArray=this.newElementArray(size+increment); - if(size>0){ - System.arraycopy(this.array,this.firstIndex,newArray,this.firstIndex,size); - } - this.array=newArray; -} - -},$fz.isPrivate=true,$fz),"~N"); -Clazz.defineMethod(c$,"growAtFront", -($fz=function(required){ -var size=this.size(); -if(this.array.length-this.lastIndex>=required){ -var newFirst=this.array.length-size; -if(size>0){ -System.arraycopy(this.array,this.firstIndex,this.array,newFirst,size); -var length=this.firstIndex+size>newFirst?newFirst:this.firstIndex+size; -this.fill(this.firstIndex,length); -}this.firstIndex=newFirst; -this.lastIndex=this.array.length; -}else{ -var increment=Math.floor(size/2); -if(required>increment){ -increment=required; -}if(increment<12){ -increment=12; -}var newArray=this.newElementArray(size+increment); -if(size>0){ -System.arraycopy(this.array,this.firstIndex,newArray,newArray.length-size,size); -}this.firstIndex=newArray.length-size; -this.lastIndex=newArray.length; -this.array=newArray; -}},$fz.isPrivate=true,$fz),"~N"); -Clazz.defineMethod(c$,"growForInsert", -($fz=function(location,required){ -var size=this.size(); -var increment=Math.floor(size/2); -if(required>increment){ -increment=required; -}if(increment<12){ -increment=12; -}var newArray=this.newElementArray(size+increment); -if(location=this.firstIndex;i--){ -if(object.equals(this.array[i])){ -return i-this.firstIndex; -}} -}else{ -for(var i=this.lastIndex-1;i>=this.firstIndex;i--){ -if(this.array[i]==null){ -return i-this.firstIndex; -}} -}return-1; -},"~O"); -Clazz.overrideMethod(c$,"remove", -function(location){ -if (0+location != location) return this.removeObject(location) -var result; -var size=this.size(); -if(0<=location&&location=0&&start<=end&&end<=this.size()){ -if(start==end){ -return; -}var size=this.size(); -if(end==size){ - this.fill(this.firstIndex+start,this.lastIndex); -this.lastIndex=this.firstIndex+start; -}else if(start==0){ - this.fill(this.firstIndex,this.firstIndex+end); -this.firstIndex+=end; -}else{ -System.arraycopy(this.array,this.firstIndex+end,this.array,this.firstIndex+start,size-end); -var newLast=this.lastIndex+start-end; -this.fill(newLast,this.lastIndex); -this.lastIndex=newLast; -}this.modCount++; -}else{ -throw new IndexOutOfBoundsException(); -}},"~N,~N"); -Clazz.overrideMethod(c$,"set", -function(location,object){ -if(0<=location&&locationcontents.length) - contents= new Array(size); -System.arraycopy(this.array,this.firstIndex,contents,0,size); -if(size0)||this.lastIndex==this.array.length){ +System.arraycopy(this.array,this.firstIndex,this.array,--this.firstIndex,location); +}else{ +var index=location+this.firstIndex; +System.arraycopy(this.array,index,this.array,index+1,size-location); +this.lastIndex++; +}this.array[location+this.firstIndex]=object; +}else if(location==0){ +if(this.firstIndex==0){ +this.growAtFront(1); +}this.array[--this.firstIndex]=object; +}else if(location==size){ +if(this.lastIndex==this.array.length){ +this.growAtEnd(1); +}this.array[this.lastIndex++]=object; +}else{ +throw new IndexOutOfBoundsException(); +}this.modCount++; +},"~N,~O"); + +Clazz.overrideMethod(c$,"add1", +function(object){ +if(this.lastIndex==this.array.length){ +this.growAtEnd(1); +}this.array[this.lastIndex++]=object; +this.modCount++; +return true; +},"~O"); + +/* BH disallow addAll(int,List) + * +Clazz.defineMethod(c$,"addAll", +function(location,collection){ +var size=this.size(); +if(location<0||location>size){ +throw new IndexOutOfBoundsException(); +}var growSize=collection.size(); +if(00)||this.lastIndex>this.array.length-growSize){ +var newFirst=this.firstIndex-growSize; +if(newFirst<0){ +var index=location+this.firstIndex; +System.arraycopy(this.array,index,this.array,index-newFirst,size-location); +this.lastIndex-=newFirst; +newFirst=0; +}System.arraycopy(this.array,this.firstIndex,this.array,newFirst,location); +this.firstIndex=newFirst; +}else{ +var index=location+this.firstIndex; +System.arraycopy(this.array,index,this.array,index+growSize,size-location); +this.lastIndex+=growSize; +}}else if(location==0){ +this.growAtFront(growSize); +this.firstIndex-=growSize; +}else if(location==size){ +if(this.lastIndex>this.array.length-growSize){ +this.growAtEnd(growSize); +}this.lastIndex+=growSize; +}if(growSize>0){ +var it=collection.iterator(); +var index=location+this.firstIndex; +var end=index+growSize; +while(index0){ + if(this.lastIndex>this.array.length-growSize){ + this.growAtEnd(growSize); +} +var it=collection.iterator(); +var end=this.lastIndex+growSize; +while(this.lastIndex= i1;) +this.array[i] = null; +},"~N,~N"); + +Clazz.defineMethod(c$,"clone", +function(){ +try{ +var newList=Clazz.superCall(this,java.util.ArrayList,"clone",[]); +newList.array=this.array.clone(); +return newList; +}catch(e){ +if(Clazz.instanceOf(e,CloneNotSupportedException)){ +return null; +}else{ +throw e; +} +} +}); +Clazz.overrideMethod(c$,"contains", +function(object){ +if(object!=null){ +for(var i=this.firstIndex;i0){ +this.growAtFront(minimumCapacity-this.array.length); +}else{ +this.growAtEnd(minimumCapacity-this.array.length); +}}},"~N"); +Clazz.overrideMethod(c$,"get", +function(location){ +if(0<=location&&location=required-(this.array.length-this.lastIndex)){ + var newLast=this.lastIndex-this.firstIndex; + if(size>0){ + System.arraycopy(this.array,this.firstIndex,this.array,0,size); + var start=newLastincrement){ + increment=required; + } + if(increment<12){ + increment=12; + } + var newArray=this.newElementArray(size+increment); + if(size>0){ + System.arraycopy(this.array,this.firstIndex,newArray,this.firstIndex,size); + } + this.array=newArray; +} + +},$fz.isPrivate=true,$fz),"~N"); +Clazz.defineMethod(c$,"growAtFront", +($fz=function(required){ +var size=this.size(); +if(this.array.length-this.lastIndex>=required){ +var newFirst=this.array.length-size; +if(size>0){ +System.arraycopy(this.array,this.firstIndex,this.array,newFirst,size); +var length=this.firstIndex+size>newFirst?newFirst:this.firstIndex+size; +this.fill(this.firstIndex,length); +}this.firstIndex=newFirst; +this.lastIndex=this.array.length; +}else{ +var increment=Math.floor(size/2); +if(required>increment){ +increment=required; +}if(increment<12){ +increment=12; +}var newArray=this.newElementArray(size+increment); +if(size>0){ +System.arraycopy(this.array,this.firstIndex,newArray,newArray.length-size,size); +}this.firstIndex=newArray.length-size; +this.lastIndex=newArray.length; +this.array=newArray; +}},$fz.isPrivate=true,$fz),"~N"); +Clazz.defineMethod(c$,"growForInsert", +($fz=function(location,required){ +var size=this.size(); +var increment=Math.floor(size/2); +if(required>increment){ +increment=required; +}if(increment<12){ +increment=12; +}var newArray=this.newElementArray(size+increment); +if(location=this.firstIndex;i--){ +if(object.equals(this.array[i])){ +return i-this.firstIndex; +}} +}else{ +for(var i=this.lastIndex-1;i>=this.firstIndex;i--){ +if(this.array[i]==null){ +return i-this.firstIndex; +}} +}return-1; +},"~O"); +Clazz.overrideMethod(c$,"remove", +function(location){ +if (0+location != location) return this.removeObject(location) +var result; +var size=this.size(); +if(0<=location&&location=0&&start<=end&&end<=this.size()){ +if(start==end){ +return; +}var size=this.size(); +if(end==size){ + this.fill(this.firstIndex+start,this.lastIndex); +this.lastIndex=this.firstIndex+start; +}else if(start==0){ + this.fill(this.firstIndex,this.firstIndex+end); +this.firstIndex+=end; +}else{ +System.arraycopy(this.array,this.firstIndex+end,this.array,this.firstIndex+start,size-end); +var newLast=this.lastIndex+start-end; +this.fill(newLast,this.lastIndex); +this.lastIndex=newLast; +}this.modCount++; +}else{ +throw new IndexOutOfBoundsException(); +}},"~N,~N"); +Clazz.overrideMethod(c$,"set", +function(location,object){ +if(0<=location&&locationcontents.length) + contents= new Array(size); +System.arraycopy(this.array,this.firstIndex,contents,0,size); +if(size