public void testClone() throws Exception { TermAttributeImpl t = new TermAttributeImpl(); char[] content = "hello".toCharArray(); t.setTermBuffer(content, 0, 5); char[] buf = t.termBuffer(); TermAttributeImpl copy = (TermAttributeImpl) TestSimpleAttributeImpls.assertCloneIsEqual(t); assertEquals(t.term(), copy.term()); assertNotSame(buf, copy.termBuffer()); }
public void testResize() { TermAttributeImpl t = new TermAttributeImpl(); char[] content = "hello".toCharArray(); t.setTermBuffer(content, 0, content.length); for (int i = 0; i < 2000; i++) { t.resizeTermBuffer(i); assertTrue(i <= t.termBuffer().length); assertEquals("hello", t.term()); } }
public void testMixedStringArray() throws Exception { TermAttributeImpl t = new TermAttributeImpl(); t.setTermBuffer("hello"); assertEquals(t.termLength(), 5); assertEquals(t.term(), "hello"); t.setTermBuffer("hello2"); assertEquals(t.termLength(), 6); assertEquals(t.term(), "hello2"); t.setTermBuffer("hello3".toCharArray(), 0, 6); assertEquals(t.term(), "hello3"); // Make sure if we get the buffer and change a character // that term() reflects the change char[] buffer = t.termBuffer(); buffer[1] = 'o'; assertEquals(t.term(), "hollo3"); }
public void testGrow() { TermAttributeImpl t = new TermAttributeImpl(); StringBuilder buf = new StringBuilder("ab"); for (int i = 0; i < 20; i++) { char[] content = buf.toString().toCharArray(); t.setTermBuffer(content, 0, content.length); assertEquals(buf.length(), t.termLength()); assertEquals(buf.toString(), t.term()); buf.append(buf.toString()); } assertEquals(1048576, t.termLength()); assertEquals(1179654, t.termBuffer().length); // now as a string, first variant t = new TermAttributeImpl(); buf = new StringBuilder("ab"); for (int i = 0; i < 20; i++) { String content = buf.toString(); t.setTermBuffer(content, 0, content.length()); assertEquals(content.length(), t.termLength()); assertEquals(content, t.term()); buf.append(content); } assertEquals(1048576, t.termLength()); assertEquals(1179654, t.termBuffer().length); // now as a string, second variant t = new TermAttributeImpl(); buf = new StringBuilder("ab"); for (int i = 0; i < 20; i++) { String content = buf.toString(); t.setTermBuffer(content); assertEquals(content.length(), t.termLength()); assertEquals(content, t.term()); buf.append(content); } assertEquals(1048576, t.termLength()); assertEquals(1179654, t.termBuffer().length); // Test for slow growth to a long term t = new TermAttributeImpl(); buf = new StringBuilder("a"); for (int i = 0; i < 20000; i++) { String content = buf.toString(); t.setTermBuffer(content); assertEquals(content.length(), t.termLength()); assertEquals(content, t.term()); buf.append("a"); } assertEquals(20000, t.termLength()); assertEquals(20167, t.termBuffer().length); // Test for slow growth to a long term t = new TermAttributeImpl(); buf = new StringBuilder("a"); for (int i = 0; i < 20000; i++) { String content = buf.toString(); t.setTermBuffer(content); assertEquals(content.length(), t.termLength()); assertEquals(content, t.term()); buf.append("a"); } assertEquals(20000, t.termLength()); assertEquals(20167, t.termBuffer().length); }