StringBundler implements Serializable { public void setIndex(int newIndex) { if (newIndex < 0) { throw new ArrayIndexOutOfBoundsException(newIndex); } if (newIndex > _array.length) { String[] newArray = new String[newIndex]; System.arraycopy(_array, 0, newArray, 0, _arrayIndex); _array = newArray; } if (_arrayIndex < newIndex) { for (int i = _arrayIndex; i < newIndex; i++) { _array[i] = StringPool.BLANK; } } if (_arrayIndex > newIndex) { for (int i = newIndex; i < _arrayIndex; i++) { _array[i] = null; } } _arrayIndex = newIndex; } StringBundler();  StringBundler(int initialCapacity);  StringBundler(String s);  StringBundler(String[] stringArray);  StringBundler(String[] stringArray, int extraSpace); static String concat(Object... objects); static String concat(String... strings); StringBundler append(boolean b); StringBundler append(char c); StringBundler append(char[] chars); StringBundler append(double d); StringBundler append(float f); StringBundler append(int i); StringBundler append(long l); StringBundler append(Object object); StringBundler append(String s); StringBundler append(String[] stringArray); StringBundler append(StringBundler sb); int capacity(); String[] getStrings(); int index(); int length(); void setIndex(int newIndex); void setStringAt(String s, int index); String stringAt(int index); @Override String toString(); void writeTo(Writer writer);  }
@Test public void testSetIndex() { StringBundler sb = new StringBundler(); try { sb.setIndex(-1); Assert.fail(); } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { } sb = new StringBundler(4); sb.append("test1"); sb.append("test2"); Assert.assertEquals(2, sb.index()); Assert.assertEquals("test1", sb.stringAt(0)); Assert.assertEquals("test2", sb.stringAt(1)); sb.setIndex(2); Assert.assertEquals(2, sb.index()); Assert.assertEquals("test1", sb.stringAt(0)); Assert.assertEquals("test2", sb.stringAt(1)); Assert.assertEquals(4, sb.capacity()); sb.setIndex(4); Assert.assertEquals(4, sb.capacity()); Assert.assertEquals(4, sb.index()); Assert.assertEquals("test1", sb.stringAt(0)); Assert.assertEquals("test2", sb.stringAt(1)); Assert.assertEquals(StringPool.BLANK, sb.stringAt(2)); Assert.assertEquals(StringPool.BLANK, sb.stringAt(3)); sb.setIndex(6); Assert.assertEquals(6, sb.capacity()); Assert.assertEquals(6, sb.index()); Assert.assertEquals("test1", sb.stringAt(0)); Assert.assertEquals("test2", sb.stringAt(1)); Assert.assertEquals(StringPool.BLANK, sb.stringAt(2)); Assert.assertEquals(StringPool.BLANK, sb.stringAt(3)); Assert.assertEquals(StringPool.BLANK, sb.stringAt(4)); Assert.assertEquals(StringPool.BLANK, sb.stringAt(5)); sb.setIndex(1); Assert.assertEquals(6, sb.capacity()); Assert.assertEquals(1, sb.index()); Assert.assertEquals("test1", sb.stringAt(0)); try { Assert.assertEquals(null, sb.stringAt(1)); Assert.fail(); } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) { } }