Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Sep 26, 2024
2 parents 9e4a50d + 5a9d81b commit 4a8aa9e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
<notimestamp>true</notimestamp>
<links>
<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>
<validateLinks>true</validateLinks>
<archive>
Expand Down Expand Up @@ -328,7 +328,7 @@
<notimestamp>true</notimestamp>
<links>
<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>
<validateLinks>true</validateLinks>
<archive>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/apache/commons/lang3/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public static class Builder extends AbstractSupplier<Strings, Builder, RuntimeEx
*/
private boolean nullIsLess;

/**
* Constructs a new instance.
*/
private Builder() {
// empty
}

/**
* Gets a new {@link Strings} instance.
*/
Expand Down
63 changes: 32 additions & 31 deletions src/test/java/org/apache/commons/lang3/text/StrBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,38 +146,39 @@ public void testAsBuilder() {
@Test
public void testAsReader() throws Exception {
final StrBuilder sb = new StrBuilder("some text");
Reader reader = sb.asReader();
assertTrue(reader.ready());
final char[] buf = new char[40];
assertEquals(9, reader.read(buf));
assertEquals("some text", new String(buf, 0, 9));

assertEquals(-1, reader.read());
assertFalse(reader.ready());
assertEquals(0, reader.skip(2));
assertEquals(0, reader.skip(-1));

assertTrue(reader.markSupported());
reader = sb.asReader();
assertEquals('s', reader.read());
reader.mark(-1);
try (Reader reader = sb.asReader()) {
assertTrue(reader.ready());
final char[] buf = new char[40];
assertEquals(9, reader.read(buf));
assertEquals("some text", new String(buf, 0, 9));

assertEquals(-1, reader.read());
assertFalse(reader.ready());
assertEquals(0, reader.skip(2));
assertEquals(0, reader.skip(-1));

assertTrue(reader.markSupported());
}
char[] array = new char[3];
assertEquals(3, reader.read(array, 0, 3));
assertEquals('o', array[0]);
assertEquals('m', array[1]);
assertEquals('e', array[2]);
reader.reset();
assertEquals(1, reader.read(array, 1, 1));
assertEquals('o', array[0]);
assertEquals('o', array[1]);
assertEquals('e', array[2]);
assertEquals(2, reader.skip(2));
assertEquals(' ', reader.read());

assertTrue(reader.ready());
reader.close();
assertTrue(reader.ready());

try (Reader reader = sb.asReader()) {
assertEquals('s', reader.read());
reader.mark(-1);
assertEquals(3, reader.read(array, 0, 3));
assertEquals('o', array[0]);
assertEquals('m', array[1]);
assertEquals('e', array[2]);
reader.reset();
assertEquals(1, reader.read(array, 1, 1));
assertEquals('o', array[0]);
assertEquals('o', array[1]);
assertEquals('e', array[2]);
assertEquals(2, reader.skip(2));
assertEquals(' ', reader.read());

assertTrue(reader.ready());
reader.close();
assertTrue(reader.ready());
}
try (Reader r = sb.asReader()) {
final char[] arr = new char[3];
assertThrows(IndexOutOfBoundsException.class, () -> r.read(arr, -1, 0));
Expand Down

0 comments on commit 4a8aa9e

Please sign in to comment.