This commit is contained in:
Gary Gregory 2024-09-26 08:13:55 -04:00
commit 4a8aa9e724
3 changed files with 38 additions and 30 deletions

View File

@ -223,7 +223,7 @@
<notimestamp>true</notimestamp> <notimestamp>true</notimestamp>
<links> <links>
<link>https://commons.apache.org/proper/commons-text/apidocs</link> <link>https://commons.apache.org/proper/commons-text/apidocs</link>
<link>https://docs.oracle.com/javaee/6/api</link> <link>${commons.javadoc.javaee.link}</link>
</links> </links>
<validateLinks>true</validateLinks> <validateLinks>true</validateLinks>
<archive> <archive>
@ -328,7 +328,7 @@
<notimestamp>true</notimestamp> <notimestamp>true</notimestamp>
<links> <links>
<link>https://commons.apache.org/proper/commons-text/apidocs</link> <link>https://commons.apache.org/proper/commons-text/apidocs</link>
<link>https://docs.oracle.com/javaee/6/api</link> <link>${commons.javadoc.javaee.link}</link>
</links> </links>
<validateLinks>true</validateLinks> <validateLinks>true</validateLinks>
<archive> <archive>

View File

@ -46,6 +46,13 @@ public abstract class Strings {
*/ */
private boolean nullIsLess; private boolean nullIsLess;
/**
* Constructs a new instance.
*/
private Builder() {
// empty
}
/** /**
* Gets a new {@link Strings} instance. * Gets a new {@link Strings} instance.
*/ */

View File

@ -146,38 +146,39 @@ public class StrBuilderTest extends AbstractLangTest {
@Test @Test
public void testAsReader() throws Exception { public void testAsReader() throws Exception {
final StrBuilder sb = new StrBuilder("some text"); final StrBuilder sb = new StrBuilder("some text");
Reader reader = sb.asReader(); try (Reader reader = sb.asReader()) {
assertTrue(reader.ready()); assertTrue(reader.ready());
final char[] buf = new char[40]; final char[] buf = new char[40];
assertEquals(9, reader.read(buf)); assertEquals(9, reader.read(buf));
assertEquals("some text", new String(buf, 0, 9)); assertEquals("some text", new String(buf, 0, 9));
assertEquals(-1, reader.read()); assertEquals(-1, reader.read());
assertFalse(reader.ready()); assertFalse(reader.ready());
assertEquals(0, reader.skip(2)); assertEquals(0, reader.skip(2));
assertEquals(0, reader.skip(-1)); assertEquals(0, reader.skip(-1));
assertTrue(reader.markSupported()); assertTrue(reader.markSupported());
reader = sb.asReader(); }
assertEquals('s', reader.read());
reader.mark(-1);
char[] array = new char[3]; char[] array = new char[3];
assertEquals(3, reader.read(array, 0, 3)); try (Reader reader = sb.asReader()) {
assertEquals('o', array[0]); assertEquals('s', reader.read());
assertEquals('m', array[1]); reader.mark(-1);
assertEquals('e', array[2]); assertEquals(3, reader.read(array, 0, 3));
reader.reset(); assertEquals('o', array[0]);
assertEquals(1, reader.read(array, 1, 1)); assertEquals('m', array[1]);
assertEquals('o', array[0]); assertEquals('e', array[2]);
assertEquals('o', array[1]); reader.reset();
assertEquals('e', array[2]); assertEquals(1, reader.read(array, 1, 1));
assertEquals(2, reader.skip(2)); assertEquals('o', array[0]);
assertEquals(' ', reader.read()); assertEquals('o', array[1]);
assertEquals('e', array[2]);
assertTrue(reader.ready()); assertEquals(2, reader.skip(2));
reader.close(); assertEquals(' ', reader.read());
assertTrue(reader.ready());
assertTrue(reader.ready());
reader.close();
assertTrue(reader.ready());
}
try (Reader r = sb.asReader()) { try (Reader r = sb.asReader()) {
final char[] arr = new char[3]; final char[] arr = new char[3];
assertThrows(IndexOutOfBoundsException.class, () -> r.read(arr, -1, 0)); assertThrows(IndexOutOfBoundsException.class, () -> r.read(arr, -1, 0));