Text extends BinaryComparable implements WritableComparable<BinaryComparable> { public void clear() { length = 0; textLength = -1; } Text();  Text(String string);  Text(Text utf8);  Text(byte[] utf8); byte[] copyBytes(); @Override byte[] getBytes(); @Override int getLength(); int getTextLength(); int charAt(int position); int find(String what); int find(String what, int start); void set(String string); void set(byte[] utf8); void set(Text other); void set(byte[] utf8, int start, int len); void append(byte[] utf8, int start, int len); void clear(); @Override String toString(); @Override void readFields(DataInput in); void readFields(DataInput in, int maxLength); static void skip(DataInput in); void readWithKnownLength(DataInput in, int len); @Override void write(DataOutput out); void write(DataOutput out, int maxLength); @Override boolean equals(Object o); @Override int hashCode(); static String decode(byte[] utf8); static String decode(byte[] utf8, int start, int length); static String decode(byte[] utf8, int start, int length, boolean replace); static ByteBuffer encode(String string); static ByteBuffer encode(String string, boolean replace); static String readString(DataInput in); static String readString(DataInput in, int maxLength); static int writeString(DataOutput out, String s); static int writeString(DataOutput out, String s, int maxLength); static void validateUTF8(byte[] utf8); static void validateUTF8(byte[] utf8, int start, int len); static int bytesToCodePoint(ByteBuffer bytes); static int utf8Length(String string); static final public int DEFAULT_MAX_LEN; }
@Test public void testClear() throws Exception { 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()); 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()); }