1 7 8 package java.lang; 9 10 import sun.misc.FloatingDecimal; 11 12 56 public final class StringBuilder 57 extends AbstractStringBuilder 58 implements java.io.Serializable , CharSequence 59 { 60 61 62 static final long serialVersionUID = 4383685877147921099L; 63 64 68 public StringBuilder() { 69 super(16); 70 } 71 72 80 public StringBuilder(int capacity) { 81 super(capacity); 82 } 83 84 92 public StringBuilder(String str) { 93 super(str.length() + 16); 94 append(str); 95 } 96 97 106 public StringBuilder(CharSequence seq) { 107 this(seq.length() + 16); 108 append(seq); 109 } 110 111 115 public StringBuilder append(Object obj) { 116 return append(String.valueOf(obj)); 117 } 118 119 public StringBuilder append(String str) { 120 super.append(str); 121 return this; 122 } 123 124 private StringBuilder append(StringBuilder sb) { 126 if (sb == null) 127 return append("null"); 128 int len = sb.length(); 129 int newcount = count + len; 130 if (newcount > value.length) 131 expandCapacity(newcount); 132 sb.getChars(0, len, value, count); 133 count = newcount; 134 return this; 135 } 136 137 156 public StringBuilder append(StringBuffer sb) { 157 super.append(sb); 158 return this; 159 } 160 161 164 public StringBuilder append(CharSequence s) { 165 if (s == null) 166 s = "null"; 167 if (s instanceof String ) 168 return this.append((String )s); 169 if (s instanceof StringBuffer ) 170 return this.append((StringBuffer )s); 171 if (s instanceof StringBuilder ) 172 return this.append((StringBuilder )s); 173 return this.append(s, 0, s.length()); 174 } 175 176 179 public StringBuilder append(CharSequence s, int start, int end) { 180 super.append(s, start, end); 181 return this; 182 } 183 184 public StringBuilder append(char str[]) { 185 super.append(str); 186 return this; 187 } 188 189 public StringBuilder append(char str[], int offset, int len) { 190 super.append(str, offset, len); 191 return this; 192 } 193 194 198 public StringBuilder append(boolean b) { 199 super.append(b); 200 return this; 201 } 202 203 public StringBuilder append(char c) { 204 super.append(c); 205 return this; 206 } 207 208 212 public StringBuilder append(int i) { 213 super.append(i); 214 return this; 215 } 216 217 221 public StringBuilder append(long lng) { 222 super.append(lng); 223 return this; 224 } 225 226 230 public StringBuilder append(float f) { 231 super.append(f); 232 return this; 233 } 234 235 239 public StringBuilder append(double d) { 240 super.append(d); 241 return this; 242 } 243 244 247 public StringBuilder appendCodePoint(int codePoint) { 248 super.appendCodePoint(codePoint); 249 return this; 250 } 251 252 255 public StringBuilder delete(int start, int end) { 256 super.delete(start, end); 257 return this; 258 } 259 260 263 public StringBuilder deleteCharAt(int index) { 264 super.deleteCharAt(index); 265 return this; 266 } 267 268 271 public StringBuilder replace(int start, int end, String str) { 272 super.replace(start, end, str); 273 return this; 274 } 275 276 279 public StringBuilder insert(int index, char str[], int offset, 280 int len) 281 { 282 super.insert(index, str, offset, len); 283 return this; 284 } 285 286 292 public StringBuilder insert(int offset, Object obj) { 293 return insert(offset, String.valueOf(obj)); 294 } 295 296 300 public StringBuilder insert(int offset, String str) { 301 super.insert(offset, str); 302 return this; 303 } 304 305 308 public StringBuilder insert(int offset, char str[]) { 309 super.insert(offset, str); 310 return this; 311 } 312 313 316 public StringBuilder insert(int dstOffset, CharSequence s) { 317 if (s == null) 318 s = "null"; 319 if (s instanceof String ) 320 return this.insert(dstOffset, (String )s); 321 return this.insert(dstOffset, s, 0, s.length()); 322 } 323 324 327 public StringBuilder insert(int dstOffset, CharSequence s, 328 int start, int end) 329 { 330 super.insert(dstOffset, s, start, end); 331 return this; 332 } 333 334 340 public StringBuilder insert(int offset, boolean b) { 341 super.insert(offset, b); 342 return this; 343 } 344 345 349 public StringBuilder insert(int offset, char c) { 350 super.insert(offset, c); 351 return this; 352 } 353 354 360 public StringBuilder insert(int offset, int i) { 361 return insert(offset, String.valueOf(i)); 362 } 363 364 370 public StringBuilder insert(int offset, long l) { 371 return insert(offset, String.valueOf(l)); 372 } 373 374 380 public StringBuilder insert(int offset, float f) { 381 return insert(offset, String.valueOf(f)); 382 } 383 384 390 public StringBuilder insert(int offset, double d) { 391 return insert(offset, String.valueOf(d)); 392 } 393 394 397 public int indexOf(String str) { 398 return indexOf(str, 0); 399 } 400 401 404 public int indexOf(String str, int fromIndex) { 405 return String.indexOf(value, 0, count, 406 str.toCharArray(), 0, str.length(), fromIndex); 407 } 408 409 412 public int lastIndexOf(String str) { 413 return lastIndexOf(str, count); 414 } 415 416 419 public int lastIndexOf(String str, int fromIndex) { 420 return String.lastIndexOf(value, 0, count, 421 str.toCharArray(), 0, str.length(), fromIndex); 422 } 423 424 public StringBuilder reverse() { 425 super.reverse(); 426 return this; 427 } 428 429 public String toString() { 430 return new String (value, 0, count); 432 } 433 434 445 private void writeObject(java.io.ObjectOutputStream s) 446 throws java.io.IOException { 447 s.defaultWriteObject(); 448 s.writeInt(count); 449 s.writeObject(value); 450 } 451 452 456 private void readObject(java.io.ObjectInputStream s) 457 throws java.io.IOException , ClassNotFoundException { 458 s.defaultReadObject(); 459 count = s.readInt(); 460 value = (char[]) s.readObject(); 461 } 462 463 } 464 | Popular Tags |