Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / lang / AbstractStringBuilder.js
1 Clazz.load(null,"java.lang.AbstractStringBuilder",["java.io.InvalidObjectException","java.lang.ArrayIndexOutOfBoundsException","$.IndexOutOfBoundsException","$.NegativeArraySizeException","$.NullPointerException","$.StringIndexOutOfBoundsException"],function(){
2 c$=Clazz.decorateAsClass(function(){
3 this.value=null;
4 this.count=0;
5 this.shared=false;
6 Clazz.instantialize(this,arguments);
7 },java.lang,"AbstractStringBuilder");
8 Clazz.defineMethod(c$,"getValue",
9 function(){
10 return this.value;
11 });
12 Clazz.defineMethod(c$,"shareValue",
13 function(){
14 this.shared=true;
15 return this.value;
16 });
17 Clazz.defineMethod(c$,"set",
18 function(val,len){
19 if(val==null)val=Clazz.newArray(0,'\0');
20 if(val.length<len)throw new java.io.InvalidObjectException(("K0199"));
21 this.shared=false;
22 this.value=val;
23 this.count=len;
24 },"~A,~N");
25 Clazz.makeConstructor(c$,
26 function(){
27 this.value=Clazz.newArray(16,'\0');
28 });
29 Clazz.makeConstructor(c$,
30 function(capacity){
31 if(capacity<0)throw new NegativeArraySizeException();
32 this.value=Clazz.newArray(capacity,'\0');
33 },"~N");
34 Clazz.makeConstructor(c$,
35 function(string){
36 this.count=string.length;
37 this.shared=false;
38 this.value=Clazz.newArray(this.count+16,'\0');
39 string.getChars(0,this.count,this.value,0);
40 },"~S");
41 Clazz.defineMethod(c$,"enlargeBuffer",
42 ($fz=function(min){
43 var twice=(this.value.length<<1)+2;
44 var newData=Clazz.newArray(min>twice?min:twice,'\0');
45 System.arraycopy(this.value,0,newData,0,this.count);
46 this.value=newData;
47 this.shared=false;
48 },$fz.isPrivate=true,$fz),"~N");
49 Clazz.defineMethod(c$,"appendNull",
50 function(){
51 var newSize=this.count+4;
52 if(newSize>this.value.length){
53 this.enlargeBuffer(newSize);
54 }else if(this.shared){
55 this.value=this.value.clone();
56 this.shared=false;
57 }this.value[this.count++]='n';
58 this.value[this.count++]='u';
59 this.value[this.count++]='l';
60 this.value[this.count++]='l';
61 });
62 Clazz.defineMethod(c$,"append0",
63 function(chars){
64 var newSize=this.count+chars.length;
65 if(newSize>this.value.length){
66 this.enlargeBuffer(newSize);
67 }else if(this.shared){
68 this.value=this.value.clone();
69 this.shared=false;
70 }System.arraycopy(chars,0,this.value,this.count,chars.length);
71 this.count=newSize;
72 },"~A");
73 Clazz.defineMethod(c$,"append0",
74 function(chars,start,length){
75 if(chars==null){
76 throw new NullPointerException();
77 }if(start>=0&&0<=length&&length<=chars.length-start){
78 var newSize=this.count+length;
79 if(newSize>this.value.length){
80 this.enlargeBuffer(newSize);
81 }else if(this.shared){
82 this.value=this.value.clone();
83 this.shared=false;
84 }System.arraycopy(chars,start,this.value,this.count,length);
85 this.count=newSize;
86 }else{
87 throw new ArrayIndexOutOfBoundsException();
88 }},"~A,~N,~N");
89 Clazz.defineMethod(c$,"append0",
90 function(ch){
91 if(this.count==this.value.length){
92 this.enlargeBuffer(this.count+1);
93 }if(this.shared){
94 this.value=this.value.clone();
95 this.shared=false;
96 }this.value[this.count++]=ch;
97 },"~N");
98 Clazz.defineMethod(c$,"append0",
99 function(string){
100 if(string==null){
101 this.appendNull();
102 return;
103 }var adding=string.length;
104 var newSize=this.count+adding;
105 if(newSize>this.value.length){
106 this.enlargeBuffer(newSize);
107 }else if(this.shared){
108 this.value=this.value.clone();
109 this.shared=false;
110 }string.getChars(0,adding,this.value,this.count);
111 this.count=newSize;
112 },"~S");
113 Clazz.defineMethod(c$,"append0",
114 function(s,start,end){
115 if(s==null)s="null";
116 if(start<0||end<0||start>end||end>s.length())throw new IndexOutOfBoundsException();
117 this.append0(s.subSequence(start,end).toString());
118 },"CharSequence,~N,~N");
119 Clazz.defineMethod(c$,"capacity",
120 function(){
121 return this.value.length;
122 });
123 Clazz.defineMethod(c$,"charAt",
124 function(index){
125 if(index<0||index>=this.count)throw new StringIndexOutOfBoundsException(index);
126 return this.value[index];
127 },"~N");
128 Clazz.defineMethod(c$,"delete0",
129 function(start,end){
130 if(start>=0){
131 if(end>this.count){
132 end=this.count;
133 }if(end==start){
134 return;
135 }if(end>start){
136 var length=this.count-end;
137 if(length>0){
138 if(!this.shared){
139 System.arraycopy(this.value,end,this.value,start,length);
140 }else{
141 var newData=Clazz.newArray(this.value.length,'\0');
142 System.arraycopy(this.value,0,newData,0,start);
143 System.arraycopy(this.value,end,newData,start,length);
144 this.value=newData;
145 this.shared=false;
146 }}this.count-=end-start;
147 return;
148 }}throw new StringIndexOutOfBoundsException();
149 },"~N,~N");
150 Clazz.defineMethod(c$,"deleteCharAt0",
151 function(location){
152 if(0>location||location>=this.count)throw new StringIndexOutOfBoundsException(location);
153 var length=this.count-location-1;
154 if(length>0){
155 if(!this.shared){
156 System.arraycopy(this.value,location+1,this.value,location,length);
157 }else{
158 var newData=Clazz.newArray(this.value.length,'\0');
159 System.arraycopy(this.value,0,newData,0,location);
160 System.arraycopy(this.value,location+1,newData,location,length);
161 this.value=newData;
162 this.shared=false;
163 }}this.count--;
164 },"~N");
165 Clazz.defineMethod(c$,"ensureCapacity",
166 function(min){
167 if(min>this.value.length){
168 this.enlargeBuffer(min);
169 }},"~N");
170 Clazz.defineMethod(c$,"getChars",
171 function(start,end,dest,destStart){
172 if(start>this.count||end>this.count||start>end){
173 throw new StringIndexOutOfBoundsException();
174 }System.arraycopy(this.value,start,dest,destStart,end-start);
175 },"~N,~N,~A,~N");
176 Clazz.defineMethod(c$,"insert0",
177 function(index,chars){
178 if(0>index||index>this.count){
179 throw new StringIndexOutOfBoundsException(index);
180 }if(chars.length!=0){
181 this.move(chars.length,index);
182 System.arraycopy(chars,0,this.value,index,chars.length);
183 this.count+=chars.length;
184 }},"~N,~A");
185 Clazz.defineMethod(c$,"insert0",
186 function(index,chars,start,length){
187 if(0<=index&&index<=this.count){
188 if(start>=0&&0<=length&&length<=chars.length-start){
189 if(length!=0){
190 this.move(length,index);
191 System.arraycopy(chars,start,this.value,index,length);
192 this.count+=length;
193 }return;
194 }throw new StringIndexOutOfBoundsException("offset "+start+", len "+length+", array.length "+chars.length);
195 }throw new StringIndexOutOfBoundsException(index);
196 },"~N,~A,~N,~N");
197 Clazz.defineMethod(c$,"insert0",
198 function(index,ch){
199 if(0>index||index>this.count){
200 throw new ArrayIndexOutOfBoundsException(index);
201 }this.move(1,index);
202 this.value[index]=ch;
203 this.count++;
204 },"~N,~N");
205 Clazz.defineMethod(c$,"insert0",
206 function(index,string){
207 if(0<=index&&index<=this.count){
208 if(string==null)string="null";
209 var min=string.length;
210 if(min!=0){
211 this.move(min,index);
212 string.getChars(0,min,this.value,index);
213 this.count+=min;
214 }}else{
215 throw new StringIndexOutOfBoundsException(index);
216 }},"~N,~S");
217 Clazz.defineMethod(c$,"insert0",
218 function(index,s,start,end){
219 if(s==null)s="null";
220 if(index<0||index>this.count||start<0||end<0||start>end||end>s.length())throw new IndexOutOfBoundsException();
221 this.insert0(index,s.subSequence(start,end).toString());
222 },"~N,CharSequence,~N,~N");
223 Clazz.defineMethod(c$,"length",
224 function(){
225 return this.count;
226 });
227 Clazz.defineMethod(c$,"move",
228 ($fz=function(size,index){
229 var newSize;
230 if(this.value.length-this.count>=size){
231 if(!this.shared){
232 System.arraycopy(this.value,index,this.value,index+size,this.count-index);
233 return;
234 }newSize=this.value.length;
235 }else{
236 var a=this.count+size;
237 var b=(this.value.length<<1)+2;
238 newSize=a>b?a:b;
239 }var newData=Clazz.newArray(newSize,'\0');
240 System.arraycopy(this.value,0,newData,0,index);
241 System.arraycopy(this.value,index,newData,index+size,this.count-index);
242 this.value=newData;
243 this.shared=false;
244 },$fz.isPrivate=true,$fz),"~N,~N");
245 Clazz.defineMethod(c$,"replace0",
246 function(start,end,string){
247 if(start>=0){
248 if(end>this.count)end=this.count;
249 if(end>start){
250 var stringLength=string.length;
251 var diff=end-start-stringLength;
252 if(diff>0){
253 if(!this.shared){
254 System.arraycopy(this.value,end,this.value,start+stringLength,this.count-end);
255 }else{
256 var newData=Clazz.newArray(this.value.length,'\0');
257 System.arraycopy(this.value,0,newData,0,start);
258 System.arraycopy(this.value,end,newData,start+stringLength,this.count-end);
259 this.value=newData;
260 this.shared=false;
261 }}else if(diff<0){
262 this.move(-diff,end);
263 }else if(this.shared){
264 this.value=this.value.clone();
265 this.shared=false;
266 }string.getChars(0,stringLength,this.value,start);
267 this.count-=diff;
268 return;
269 }if(start==end){
270 if(string==null)throw new NullPointerException();
271 this.insert0(start,string);
272 return;
273 }}throw new StringIndexOutOfBoundsException();
274 },"~N,~N,~S");
275 Clazz.defineMethod(c$,"reverse0",
276 function(){
277 if(this.count<2){
278 return;
279 }if(!this.shared){
280 for(var i=0,end=this.count,mid=Math.floor(this.count/2);i<mid;i++){
281 var temp=this.value[--end];
282 this.value[end]=this.value[i];
283 this.value[i]=temp;
284 }
285 }else{
286 var newData=Clazz.newArray(this.value.length,'\0');
287 for(var i=0,end=this.count;i<this.count;i++){
288 newData[--end]=this.value[i];
289 }
290 this.value=newData;
291 this.shared=false;
292 }});
293 Clazz.defineMethod(c$,"setCharAt",
294 function(index,ch){
295 if(0>index||index>=this.count){
296 throw new StringIndexOutOfBoundsException(index);
297 }if(this.shared){
298 this.value=this.value.clone();
299 this.shared=false;
300 }this.value[index]=ch;
301 },"~N,~N");
302 Clazz.defineMethod(c$,"setLength",
303 function(length){
304 if(length<0)throw new StringIndexOutOfBoundsException(length);
305 if(this.count<length){
306 if(length>this.value.length){
307 this.enlargeBuffer(length);
308 }else{
309 if(this.shared){
310 var newData=Clazz.newArray(this.value.length,'\0');
311 System.arraycopy(this.value,0,newData,0,this.count);
312 this.value=newData;
313 this.shared=false;
314 }else{
315 for(var i=this.count;i<length;i++){
316 this.value[i]=String.fromCharCode(0);
317 }
318 }}}this.count=length;
319 },"~N");
320 Clazz.defineMethod(c$,"substring",
321 function(start){
322 if(0<=start&&start<=this.count){
323 if(start==this.count)return"";
324 this.shared=true;
325 return String.instantialize(start,this.count-start,this.value);
326 }throw new StringIndexOutOfBoundsException(start);
327 },"~N");
328 Clazz.defineMethod(c$,"substring",
329 function(start,end){
330 if(0<=start&&start<=end&&end<=this.count){
331 if(start==end)return"";
332 this.shared=true;
333 return String.instantialize(this.value,start,end-start);
334 }throw new StringIndexOutOfBoundsException();
335 },"~N,~N");
336 Clazz.overrideMethod(c$,"toString",
337 function(){
338 if(this.count==0)return"";
339 if(this.count>=256&&this.count<=(this.value.length>>1))return String.instantialize(this.value,0,this.count);
340 this.shared=true;
341 return String.instantialize(0,this.count,this.value);
342 });
343 Clazz.defineMethod(c$,"subSequence",
344 function(start,end){
345 return this.substring(start,end);
346 },"~N,~N");
347 Clazz.defineMethod(c$,"indexOf",
348 function(string){
349 return this.indexOf(string,0);
350 },"~S");
351 Clazz.defineMethod(c$,"indexOf",
352 function(subString,start){
353 if(start<0)start=0;
354 var subCount=subString.length;
355 if(subCount>0){
356 if(subCount+start>this.count)return-1;
357 var firstChar=subString.charAt(0);
358 while(true){
359 var i=start;
360 var found=false;
361 for(;i<this.count;i++)if((this.value[i]).charCodeAt(0)==(firstChar).charCodeAt(0)){
362 found=true;
363 break;
364 }
365 if(!found||subCount+i>this.count)return-1;
366 var o1=i;
367 var o2=0;
368 while(++o2<subCount&&(this.value[++o1]).charCodeAt(0)==(subString.charAt(o2)).charCodeAt(0)){
369 }
370 if(o2==subCount)return i;
371 start=i+1;
372 }
373 }return(start<this.count||start==0)?start:this.count;
374 },"~S,~N");
375 Clazz.defineMethod(c$,"lastIndexOf",
376 function(string){
377 return this.lastIndexOf(string,this.count);
378 },"~S");
379 Clazz.defineMethod(c$,"lastIndexOf",
380 function(subString,start){
381 var subCount=subString.length;
382 if(subCount<=this.count&&start>=0){
383 if(subCount>0){
384 if(start>this.count-subCount)start=this.count-subCount;
385 var firstChar=subString.charAt(0);
386 while(true){
387 var i=start;
388 var found=false;
389 for(;i>=0;--i)if((this.value[i]).charCodeAt(0)==(firstChar).charCodeAt(0)){
390 found=true;
391 break;
392 }
393 if(!found)return-1;
394 var o1=i;
395 var o2=0;
396 while(++o2<subCount&&(this.value[++o1]).charCodeAt(0)==(subString.charAt(o2)).charCodeAt(0)){
397 }
398 if(o2==subCount)return i;
399 start=i-1;
400 }
401 }return start<this.count?start:this.count;
402 }return-1;
403 },"~S,~N");
404 Clazz.defineMethod(c$,"trimToSize",
405 function(){
406 if(this.count<this.value.length){
407 var newValue=Clazz.newArray(this.count,'\0');
408 System.arraycopy(this.value,0,newValue,0,this.count);
409 this.value=newValue;
410 this.shared=false;
411 }});
412 Clazz.defineStatics(c$,
413 "INITIAL_CAPACITY",16);
414 });