public static boolean regionMatches(
    CharSequence expected, CharSequence input, int beginIndex, int endIndex) {
    if (expected == null) throw new NullPointerException("expected == null");
    if (input == null) throw new NullPointerException("input == null");
    int regionLength = regionLength(input.length(), beginIndex, endIndex);
    if (expected.length() > regionLength) return false;
    for (int i = 0, inputIndex = beginIndex; i < regionLength; i++, inputIndex++) {
      if (expected.charAt(i) != input.charAt(inputIndex)) return false;
    }
    return true;
  }
@Test void regionMatches_badParameters() {
    assertThatThrownBy(() -> CharSequences.regionMatches(null, "b3", 0, 0))
      .isInstanceOf(NullPointerException.class)
      .hasMessage("expected == null");
    assertThatThrownBy(() -> CharSequences.regionMatches("b3", null, 0, 0))
      .isInstanceOf(NullPointerException.class)
      .hasMessage("input == null");

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

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

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

    assertThatThrownBy(() -> CharSequences.regionMatches("b3", "a", 0, 2))
      .isInstanceOf(IndexOutOfBoundsException.class)
      .hasMessage("endIndex > input");
  }