< prev index next >

src/java.base/share/classes/java/lang/AbstractStringBuilder.java

Print this page

        

*** 90,150 **** coder = UTF16; } } /** ! * Constructs an AbstractStringBuilder that contains the same characters ! * as the specified {@code String}. The initial capacity of ! * the string builder is {@code 16} plus the length of the ! * {@code String} argument. ! * ! * @param str the string to copy. ! */ ! AbstractStringBuilder(String str) { ! int length = str.length(); ! int capacity = (length < Integer.MAX_VALUE - 16) ! ? length + 16 : Integer.MAX_VALUE; ! final byte initCoder = str.coder(); ! coder = initCoder; ! value = (initCoder == LATIN1) ! ? new byte[capacity] : StringUTF16.newBytesFor(capacity); ! append(str); ! } ! ! /** ! * Constructs an AbstractStringBuilder that contains the same characters ! * as the specified {@code CharSequence}. The initial capacity of ! * the string builder is {@code 16} plus the length of the ! * {@code CharSequence} argument. ! * ! * @param seq the sequence to copy. */ ! AbstractStringBuilder(CharSequence seq) { ! int length = seq.length(); if (length < 0) { throw new NegativeArraySizeException("Negative length: " + length); } ! int capacity = (length < Integer.MAX_VALUE - 16) ! ? length + 16 : Integer.MAX_VALUE; ! ! final byte initCoder; ! if (COMPACT_STRINGS) { ! if (seq instanceof AbstractStringBuilder) { ! initCoder = ((AbstractStringBuilder)seq).getCoder(); ! } else if (seq instanceof String) { ! initCoder = ((String)seq).coder(); ! } else { ! initCoder = LATIN1; ! } ! } else { ! initCoder = UTF16; ! } ! ! coder = initCoder; ! value = (initCoder == LATIN1) ? new byte[capacity] : StringUTF16.newBytesFor(capacity); - append(seq); } /** * Compares the objects of two AbstractStringBuilder implementations lexicographically. * --- 90,112 ---- coder = UTF16; } } /** ! * Creates an AbstractStringBuilder with the specified coder and with ! * the initial capacity equal to the smaller of (length + addition) ! * and Integer.MAX_VALUE. */ ! AbstractStringBuilder(byte coder, int length, int addition) { if (length < 0) { throw new NegativeArraySizeException("Negative length: " + length); } ! this.coder = coder; ! int capacity = (length < Integer.MAX_VALUE - addition) ! ? length + addition : Integer.MAX_VALUE; ! value = (coder == LATIN1) ? new byte[capacity] : StringUTF16.newBytesFor(capacity); } /** * Compares the objects of two AbstractStringBuilder implementations lexicographically. *
< prev index next >