/** * Extracts a portion of this string builder as a string. * * @param start the start index, inclusive, must be valid * @return the new string * @throws IndexOutOfBoundsException if the index is invalid */ public String substring(final int start) { return substring(start, size); }
/** * {@inheritDoc} * @since 3.0 */ @Override public CharSequence subSequence(final int startIndex, final int endIndex) { if (startIndex < 0) { throw new StringIndexOutOfBoundsException(startIndex); } if (endIndex > size) { throw new StringIndexOutOfBoundsException(endIndex); } if (startIndex > endIndex) { throw new StringIndexOutOfBoundsException(endIndex - startIndex); } return substring(startIndex, endIndex); }
@Test public void testSubstringInt() { final StrBuilder sb = new StrBuilder ("hello goodbye"); assertEquals ("goodbye", sb.substring(6)); assertEquals ("hello goodbye".substring(6), sb.substring(6)); assertEquals ("hello goodbye", sb.substring(0)); assertEquals ("hello goodbye".substring(0), sb.substring(0)); try { sb.substring(-1); fail (); } catch (final IndexOutOfBoundsException e) {} try { sb.substring(15); fail (); } catch (final IndexOutOfBoundsException e) {} }
@Test public void testSubstringIntInt() { final StrBuilder sb = new StrBuilder ("hello goodbye"); assertEquals ("hello", sb.substring(0, 5)); assertEquals ("hello goodbye".substring(0, 6), sb.substring(0, 6)); assertEquals ("goodbye", sb.substring(6, 13)); assertEquals ("hello goodbye".substring(6,13), sb.substring(6, 13)); assertEquals ("goodbye", sb.substring(6, 20)); try { sb.substring(-1, 5); fail(); } catch (final IndexOutOfBoundsException e) {} try { sb.substring(15, 20); fail(); } catch (final IndexOutOfBoundsException e) {} }
/** * Extracts a portion of this string builder as a string. * * @param start the start index, inclusive, must be valid * @return the new string * @throws IndexOutOfBoundsException if the index is invalid */ public String substring(final int start) { return substring(start, size); }
/** * Extracts a portion of this string builder as a string. * * @param start the start index, inclusive, must be valid * @return the new string * @throws IndexOutOfBoundsException if the index is invalid */ public String substring(final int start) { return substring(start, size); }
/** * Extracts a portion of this string builder as a string. * * @param start the start index, inclusive, must be valid * @return the new string * @throws IndexOutOfBoundsException if the index is invalid */ public String substring(final int start) { return substring(start, size); }
/** * {@inheritDoc} * @since 3.0 */ @Override public CharSequence subSequence(final int startIndex, final int endIndex) { if (startIndex < 0) { throw new StringIndexOutOfBoundsException(startIndex); } if (endIndex > size) { throw new StringIndexOutOfBoundsException(endIndex); } if (startIndex > endIndex) { throw new StringIndexOutOfBoundsException(endIndex - startIndex); } return substring(startIndex, endIndex); }
/** * {@inheritDoc} * @since 3.0 */ @Override public CharSequence subSequence(final int startIndex, final int endIndex) { if (startIndex < 0) { throw new StringIndexOutOfBoundsException(startIndex); } if (endIndex > size) { throw new StringIndexOutOfBoundsException(endIndex); } if (startIndex > endIndex) { throw new StringIndexOutOfBoundsException(endIndex - startIndex); } return substring(startIndex, endIndex); }
/** * {@inheritDoc} * @since 3.0 */ @Override public CharSequence subSequence(final int startIndex, final int endIndex) { if (startIndex < 0) { throw new StringIndexOutOfBoundsException(startIndex); } if (endIndex > size) { throw new StringIndexOutOfBoundsException(endIndex); } if (startIndex > endIndex) { throw new StringIndexOutOfBoundsException(endIndex - startIndex); } return substring(startIndex, endIndex); }