/** * Inserts the string representation of an object into this builder. * Inserting null will use the stored null text value. * * @param index the index to add at, must be valid * @param obj the object to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final Object obj) { if (obj == null) { return insert(index, nullText); } return insert(index, obj.toString()); }
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final int value) { return insert(index, String.valueOf(value)); }
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final double value) { return insert(index, String.valueOf(value)); }
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final long value) { return insert(index, String.valueOf(value)); }
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final float value) { return insert(index, String.valueOf(value)); }
/** * Inserts the character array into this builder. * Inserting null will use the stored null text value. * * @param index the index to add at, must be valid * @param chars the char array to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final char chars[]) { validateIndex(index); if (chars == null) { return insert(index, nullText); } final int len = chars.length; if (len > 0) { ensureCapacity(size + len); System.arraycopy(buffer, index, buffer, index + len, size - index); System.arraycopy(chars, 0, buffer, index, len); size += len; } return this; }
/** * Inserts part of the character array into this builder. * Inserting null will use the stored null text value. * * @param index the index to add at, must be valid * @param chars the char array to insert * @param offset the offset into the character array to start at, must be valid * @param length the length of the character array part to copy, must be positive * @return this, to enable chaining * @throws IndexOutOfBoundsException if any index is invalid */ public StrBuilder insert(final int index, final char chars[], final int offset, final int length) { validateIndex(index); if (chars == null) { return insert(index, nullText); } if (offset < 0 || offset > chars.length) { throw new StringIndexOutOfBoundsException("Invalid offset: " + offset); } if (length < 0 || offset + length > chars.length) { throw new StringIndexOutOfBoundsException("Invalid length: " + length); } if (length > 0) { ensureCapacity(size + length); System.arraycopy(buffer, index, buffer, index + length, size - index); System.arraycopy(chars, offset, buffer, index, length); size += length; } return this; }
sb.insert(-1, FOO); fail("insert(-1, Object) expected StringIndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException e) { sb.insert(7, FOO); fail("insert(7, Object) expected StringIndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException e) { sb.insert(0, (Object) null); assertEquals("nullbarbaz", sb.toString()); sb.insert(0, FOO); assertEquals("foonullbarbaz", sb.toString()); sb.insert(-1, "foo"); fail("insert(-1, String) expected StringIndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException e) { sb.insert(7, "foo"); fail("insert(7, String) expected StringIndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException e) { sb.insert(0, (String) null); assertEquals("nullbarbaz", sb.toString()); sb.insert(0, "foo"); assertEquals("foonullbarbaz", sb.toString()); sb.insert(0, (char[]) null);
sb.insert(-1, FOO); fail("insert(-1, Object) expected StringIndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException e) { sb.insert(7, FOO); fail("insert(7, Object) expected StringIndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException e) { sb.insert(0, (Object) null); assertEquals("barbaz", sb.toString()); sb.insert(0, FOO); assertEquals("foobarbaz", sb.toString()); sb.insert(-1, "foo"); fail("insert(-1, String) expected StringIndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException e) { sb.insert(7, "foo"); fail("insert(7, String) expected StringIndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException e) { sb.insert(0, (String) null); assertEquals("barbaz", sb.toString()); sb.insert(0, "foo"); assertEquals("foobarbaz", sb.toString()); sb.insert(-1, new char[]{'f', 'o', 'o'});
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final int value) { return insert(index, String.valueOf(value)); }
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final long value) { return insert(index, String.valueOf(value)); }
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final double value) { return insert(index, String.valueOf(value)); }
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final long value) { return insert(index, String.valueOf(value)); }
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final float value) { return insert(index, String.valueOf(value)); }
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final int value) { return insert(index, String.valueOf(value)); }
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final double value) { return insert(index, String.valueOf(value)); }
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final int value) { return insert(index, String.valueOf(value)); }
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final double value) { return insert(index, String.valueOf(value)); }
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final float value) { return insert(index, String.valueOf(value)); }
/** * Inserts the value into this builder. * * @param index the index to add at, must be valid * @param value the value to insert * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ public StrBuilder insert(final int index, final float value) { return insert(index, String.valueOf(value)); }