/** Ensures that this object has a minimum capacity available before requiring the internal buffer to be enlarged. The general * policy of this method is that if the {@code minimumCapacity} is larger than the current {@link #capacity()}, then the * capacity will be increased to the largest value of either the {@code minimumCapacity} or the current capacity multiplied by * two plus two. Although this is the general policy, there is no guarantee that the capacity will change. * * @param min the new minimum capacity to set. */ public void ensureCapacity (int min) { if (min > chars.length) { int twice = (chars.length << 1) + 2; enlargeBuffer(twice > min ? twice : min); } }
/** Ensures that this object has a minimum capacity available before requiring the internal buffer to be enlarged. The general * policy of this method is that if the {@code minimumCapacity} is larger than the current {@link #capacity()}, then the * capacity will be increased to the largest value of either the {@code minimumCapacity} or the current capacity multiplied by * two plus two. Although this is the general policy, there is no guarantee that the capacity will change. * * @param min the new minimum capacity to set. */ public void ensureCapacity (int min) { if (min > chars.length) { int twice = (chars.length << 1) + 2; enlargeBuffer(twice > min ? twice : min); } }
final void appendNull () { int newSize = length + 4; if (newSize > chars.length) { enlargeBuffer(newSize); } chars[length++] = 'n'; chars[length++] = 'u'; chars[length++] = 'l'; chars[length++] = 'l'; }
final void appendNull () { int newSize = length + 4; if (newSize > chars.length) { enlargeBuffer(newSize); } chars[length++] = 'n'; chars[length++] = 'u'; chars[length++] = 'l'; chars[length++] = 'l'; }
final void append0 (char ch) { if (length == chars.length) { enlargeBuffer(length + 1); } chars[length++] = ch; }
final void append0 (char ch) { if (length == chars.length) { enlargeBuffer(length + 1); } chars[length++] = ch; }
final void append0 (char[] value) { int newSize = length + value.length; if (newSize > chars.length) { enlargeBuffer(newSize); } System.arraycopy(value, 0, chars, length, value.length); length = newSize; }
final void append0 (char[] value) { int newSize = length + value.length; if (newSize > chars.length) { enlargeBuffer(newSize); } System.arraycopy(value, 0, chars, length, value.length); length = newSize; }
final void append0 (char[] value, int offset, int length) { // Force null check of chars first! if (offset > value.length || offset < 0) { throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset); } if (length < 0 || value.length - offset < length) { throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + length); } int newSize = this.length + length; if (newSize > chars.length) { enlargeBuffer(newSize); } System.arraycopy(value, offset, chars, this.length, length); this.length = newSize; }
final void append0 (char[] value, int offset, int length) { // Force null check of chars first! if (offset > value.length || offset < 0) { throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset); } if (length < 0 || value.length - offset < length) { throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + length); } int newSize = this.length + length; if (newSize > chars.length) { enlargeBuffer(newSize); } System.arraycopy(value, offset, chars, this.length, length); this.length = newSize; }
final void append0 (String string) { if (string == null) { appendNull(); return; } int adding = string.length(); int newSize = length + adding; if (newSize > chars.length) { enlargeBuffer(newSize); } string.getChars(0, adding, chars, length); length = newSize; }
final void append0 (String string) { if (string == null) { appendNull(); return; } int adding = string.length(); int newSize = length + adding; if (newSize > chars.length) { enlargeBuffer(newSize); } string.getChars(0, adding, chars, length); length = newSize; }
/** Sets the current length to a new value. If the new length is larger than the current length, then the new characters at the * end of this object will contain the {@code char} value of {@code \u0000}. * * @param newLength the new length of this StringBuilder. * @exception IndexOutOfBoundsException if {@code length < 0}. * @see #length */ public void setLength (int newLength) { if (newLength < 0) { throw new StringIndexOutOfBoundsException(newLength); } if (newLength > chars.length) { enlargeBuffer(newLength); } else { if (length < newLength) { Arrays.fill(chars, length, newLength, (char)0); } } length = newLength; }
/** Sets the current length to a new value. If the new length is larger than the current length, then the new characters at the * end of this object will contain the {@code char} value of {@code \u0000}. * * @param newLength the new length of this StringBuilder. * @exception IndexOutOfBoundsException if {@code length < 0}. * @see #length */ public void setLength (int newLength) { if (newLength < 0) { throw new StringIndexOutOfBoundsException(newLength); } if (newLength > chars.length) { enlargeBuffer(newLength); } else { if (length < newLength) { Arrays.fill(chars, length, newLength, (char)0); } } length = newLength; }
final void appendNull () { int newSize = length + 4; if (newSize > chars.length) { enlargeBuffer(newSize); } chars[length++] = 'n'; chars[length++] = 'u'; chars[length++] = 'l'; chars[length++] = 'l'; }
/** Ensures that this object has a minimum capacity available before requiring the internal buffer to be enlarged. The general * policy of this method is that if the {@code minimumCapacity} is larger than the current {@link #capacity()}, then the * capacity will be increased to the largest value of either the {@code minimumCapacity} or the current capacity multiplied by * two plus two. Although this is the general policy, there is no guarantee that the capacity will change. * * @param min the new minimum capacity to set. */ public void ensureCapacity (int min) { if (min > chars.length) { int twice = (chars.length << 1) + 2; enlargeBuffer(twice > min ? twice : min); } }
final void append0 (char ch) { if (length == chars.length) { enlargeBuffer(length + 1); } chars[length++] = ch; }
final void append0 (char[] value) { int newSize = length + value.length; if (newSize > chars.length) { enlargeBuffer(newSize); } System.arraycopy(value, 0, chars, length, value.length); length = newSize; }
final void append0 (char[] value, int offset, int length) { // Force null check of chars first! if (offset > value.length || offset < 0) { throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset); } if (length < 0 || value.length - offset < length) { throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + length); } int newSize = this.length + length; if (newSize > chars.length) { enlargeBuffer(newSize); } System.arraycopy(value, offset, chars, this.length, length); this.length = newSize; }
final void append0 (String string) { if (string == null) { appendNull(); return; } int adding = string.length(); int newSize = length + adding; if (newSize > chars.length) { enlargeBuffer(newSize); } string.getChars(0, adding, chars, length); length = newSize; }