public static CharSequence withoutSubSequence(CharSequence input, int beginIndex, int endIndex) {
    if (input == null) throw new NullPointerException("input == null");
    int length = input.length();

    // Exit early if the region is empty or the entire input
    int skippedRegionLength = regionLength(length, beginIndex, endIndex);
    if (skippedRegionLength == 0) return input;
    if (beginIndex == 0 && endIndex == length) return "";

    // Exit early if the region ends on a boundary.
    // This doesn't use input.subsequence as it might allocate a String
    if (beginIndex == 0) return new SubSequence(input, endIndex, length);
    if (endIndex == length) return new SubSequence(input, 0, beginIndex);

    // Otherwise, the region to skip in the middle
    return new WithoutSubSequence(input, 0, beginIndex, endIndex, length);
  }
@Test void withoutSubSequence_badParameters() {
    assertThatThrownBy(() -> CharSequences.withoutSubSequence(null, 0, 0))
      .isInstanceOf(NullPointerException.class)
      .hasMessage("input == null");

    assertThatThrownBy(() -> CharSequences.withoutSubSequence("b3", -1, 1))
      .isInstanceOf(IndexOutOfBoundsException.class)
      .hasMessage("beginIndex < 0");

    assertThatThrownBy(() -> CharSequences.withoutSubSequence("b3", 0, -1))
      .isInstanceOf(IndexOutOfBoundsException.class)
      .hasMessage("endIndex < 0");

    assertThatThrownBy(() -> CharSequences.withoutSubSequence("b3", 1, 0))
      .isInstanceOf(IndexOutOfBoundsException.class)
      .hasMessage("beginIndex > endIndex");

    assertThatThrownBy(() -> CharSequences.withoutSubSequence("b3", 0, 3))
      .isInstanceOf(IndexOutOfBoundsException.class)
      .hasMessage("endIndex > input");
  }