updated example code StringToCharStream
This commit is contained in:
parent
7a627dff4a
commit
4c0886e304
@ -28,6 +28,23 @@ public class StringToCharStream {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IntStream getIntStreamFromCodePoints(String test) {
|
||||||
|
return test.codePoints();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IntStream getIntStreamFromChars(String test) {
|
||||||
|
return test.chars();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Stream<Character> mapIntStreamToCharStream(IntStream intStream) {
|
||||||
|
return intStream.mapToObj(c -> (char) c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Stream<String> mapIntStreamToStringStream(IntStream intStream) {
|
||||||
|
return intStream.mapToObj(c -> String.valueOf((char) c));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
new StringToCharStream();
|
new StringToCharStream();
|
||||||
|
@ -8,27 +8,26 @@ import java.util.stream.Stream;
|
|||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
public class StringToCharStreamUnitTest {
|
public class StringToCharStreamUnitTest {
|
||||||
|
|
||||||
private String testString = "Tests";
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTestString_whenChars_thenReturnIntStream() {
|
public void givenTestString_whenChars_thenReturnIntStream() {
|
||||||
|
assertThat(StringToCharStream.getIntStreamFromChars("test"), instanceOf(IntStream.class));
|
||||||
assertThat(testString.chars(), instanceOf(IntStream.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTestString_whenCodePoints_thenReturnIntStream() {
|
public void givenTestString_whenCodePoints_thenReturnIntStream() {
|
||||||
assertThat(testString.codePoints(), instanceOf(IntStream.class));
|
assertThat(StringToCharStream.getIntStreamFromCodePoints("test"), instanceOf(IntStream.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenIntStream_whenMapToObj_thenReturnCharacterStream() {
|
public void givenIntStream_whenMapToObj_thenReturnCharacterStream() {
|
||||||
Stream<Character> characterStream = testString.chars().mapToObj(c -> (char) c);
|
Stream<Character> characterStream
|
||||||
Stream<Character> characterStream1 = testString.codePoints().mapToObj(c -> (char) c);
|
= StringToCharStream.mapIntStreamToCharStream(StringToCharStream.getIntStreamFromChars("test"));
|
||||||
|
Stream<Character> characterStream1
|
||||||
|
= StringToCharStream.mapIntStreamToCharStream(StringToCharStream.getIntStreamFromCodePoints("test"));
|
||||||
assertNotNull("IntStream returned by chars() did not map to Stream<Character>", characterStream);
|
assertNotNull("IntStream returned by chars() did not map to Stream<Character>", characterStream);
|
||||||
assertNotNull("IntStream returned by codePoints() did not map to Stream<Character>", characterStream1);
|
assertNotNull("IntStream returned by codePoints() did not map to Stream<Character>", characterStream1);
|
||||||
}
|
}
|
||||||
@ -36,7 +35,7 @@ public class StringToCharStreamUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void givenIntStream_whenMapToObj_thenReturnStringStream() {
|
public void givenIntStream_whenMapToObj_thenReturnStringStream() {
|
||||||
Stream<String> stringStream
|
Stream<String> stringStream
|
||||||
= testString.codePoints().mapToObj(c -> String.valueOf((char) c));
|
= StringToCharStream.mapIntStreamToStringStream(StringToCharStream.getIntStreamFromCodePoints("test"));
|
||||||
assertNotNull(stringStream);
|
assertNotNull(stringStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
0
[B[A[B[B[B[Bssc
Normal file
0
[B[A[B[B[B[Bssc
Normal file
Loading…
x
Reference in New Issue
Block a user