public void clear() {
    length = 0;
    textLength = -1;
  }
@Test
  public void testClear() throws Exception {
    // Test lengths on an empty text object
    Text text = new Text();
    assertEquals(
            "Actual string on an empty text object must be an empty string",
        "", text.toString());
    assertEquals("Underlying byte array length must be zero",
            0, text.getBytes().length);
    assertEquals("String's length must be zero",
        0, text.getLength());
    assertEquals("String's text length must be zero",
        0, text.getTextLength());

    // Test if clear works as intended
    text = new Text("abcd\u20acbdcd\u20ac");
    int len = text.getLength();
    text.clear();
    assertEquals("String must be empty after clear()",
            "", text.toString());
    assertTrue(
            "Length of the byte array must not decrease after clear()",
        text.getBytes().length >= len);
    assertEquals("Length of the string must be reset to 0 after clear()",
        0, text.getLength());
    assertEquals("Text length of the string must be reset to 0 after clear()",
        0, text.getTextLength());
  }