This commit is contained in:
+14
-17
@@ -10,9 +10,9 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class MultiLineString {
|
||||
|
||||
|
||||
String newLine = System.getProperty("line.separator");
|
||||
|
||||
|
||||
public String stringConcatenation() {
|
||||
return "Get busy living"
|
||||
.concat(newLine)
|
||||
@@ -22,7 +22,7 @@ public class MultiLineString {
|
||||
.concat(newLine)
|
||||
.concat("--Stephen King");
|
||||
}
|
||||
|
||||
|
||||
public String stringJoin() {
|
||||
return String.join(newLine,
|
||||
"Get busy living",
|
||||
@@ -30,7 +30,7 @@ public class MultiLineString {
|
||||
"get busy dying.",
|
||||
"--Stephen King");
|
||||
}
|
||||
|
||||
|
||||
public String stringBuilder() {
|
||||
return new StringBuilder()
|
||||
.append("Get busy living")
|
||||
@@ -42,7 +42,7 @@ public class MultiLineString {
|
||||
.append("--Stephen King")
|
||||
.toString();
|
||||
}
|
||||
|
||||
|
||||
public String stringWriter() {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
PrintWriter printWriter = new PrintWriter(stringWriter);
|
||||
@@ -52,26 +52,23 @@ public class MultiLineString {
|
||||
printWriter.println("--Stephen King");
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
|
||||
public String guavaJoiner() {
|
||||
return Joiner.on(newLine).join(ImmutableList.of("Get busy living",
|
||||
"or",
|
||||
"get busy dying.",
|
||||
"--Stephen King"));
|
||||
}
|
||||
|
||||
|
||||
public String loadFromFile() throws IOException {
|
||||
return new String(Files.readAllBytes(Paths.get("src/main/resources/stephenking.txt")));
|
||||
}
|
||||
|
||||
|
||||
// public String textBlocks() {
|
||||
//
|
||||
// // THIS ONLY FOR JDK 15
|
||||
// return """
|
||||
// Get busy living
|
||||
// or
|
||||
// get busy dying.
|
||||
// --Stephen King""";
|
||||
// }
|
||||
public String textBlocks() {
|
||||
return """
|
||||
Get busy living
|
||||
or
|
||||
get busy dying.
|
||||
--Stephen King""";
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ public class MultiLineStringUnitTest {
|
||||
assertEquals(ms.stringJoin(), ms.stringBuilder());
|
||||
assertEquals(ms.stringBuilder(), ms.guavaJoiner());
|
||||
assertEquals(ms.guavaJoiner(), ms.loadFromFile());
|
||||
// assertEquals(ms.loadFromFile(), ms.textBlocks());
|
||||
assertEquals(ms.loadFromFile(), ms.textBlocks());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user