diff --git a/src/main/java/edu/unl/cse/bohn/StringBox.java b/src/main/java/edu/unl/cse/bohn/StringBox.java index 7847fdab8ec050bb26c4eaa8b1f2dcfb35630b2b..90d73158ab701bf314883ba385a1e588e6a5be8d 100644 --- a/src/main/java/edu/unl/cse/bohn/StringBox.java +++ b/src/main/java/edu/unl/cse/bohn/StringBox.java @@ -32,10 +32,12 @@ public class StringBox { * is printed with <code>System.out.println()</code> then it will leave the cursor on the 24th line, where the * user can enter their input without scrolling the top of the string off the screen.</p> * - * <p>Alternatively, you might create a 24x80 StringBox using {@link #StringBox(int, int)}. If the string is printed + * <p>Alternatively, you might create a StringBox using <code>StringBox(24,80)</code>. If the string is printed * with <code>System.out.print()</code> then it will leave the cursor at the end of the 24th line without scrolling * the top of the string off of the screen. This particular style would be useful if you place the prompt on the * 24th line.</p> + * + * @see #StringBox(int, int) */ public StringBox() { this(23, 80); // standard terminal is 24x80, but leave room for the user's input @@ -73,12 +75,13 @@ public class StringBox { * and the lines will be left-justified. Any portions of the string that would be placed outside the StringBox's * defined boundaries will be silently truncated.</p> * - * <p>Equivalent to {@link #placeStringAlignTopLeft(String, int, int)}</p> + * <p>Equivalent to <code>placeStringAlignTopLeft(string, topRow, leftColumn)</code>.</p> * * @param string the string to be placed in the StringBox * @param topRow the row on which the first line of the string should be placed * @param leftColumn the column in which the first character of each row should be placed * @return the current StringBox object, suitable for chained calls + * @see #placeStringAlignTopLeft(String, int, int) */ public StringBox placeString(String string, int topRow, int leftColumn) { return placeStringAlignTopLeft(string, topRow, leftColumn); @@ -162,17 +165,27 @@ public class StringBox { return placeStringAlignTopRight(string, bottomRow - strings.length + 1, rightColumn); } + /** + * <p>Generates the string that the client code produced by calling {@link #placeString(String, int, int)} and + * its related methods. Any unused lines between the last line of text and the bottom of the StringBox will be + * filled with newLines so that when the string is printed, the previous string will fully scroll off of the screen. + * + * <p>Equivalent to <code>toString(true)</code>.</p> + * + * @return the string built by calls to {@link #placeString(String, int, int)} and its related methods + * @see #toString(boolean) + */ @Override public String toString() { - return toString(false); + return toString(true); } /** - * <p>Generates the string that the client code produced by calling {@link #placeString(String, int, int)} and + * Generates the string that the client code produced by calling {@link #placeString(String, int, int)} and * its related methods. If this method's argument is <code>true</code>, then any unused lines between the last line * of text and the bottom of the StringBox will be filled with newLines so that when the string is printed, the * previous string will fully scroll off of the screen. If the argument is <code>false</code>, then the returned - * string will stop after the last line of text.</p> + * string will stop after the last line of text. * * @param padToHeight indicates whether newlines should be placed after the last line of text * @return the string built by calls to {@link #placeString(String, int, int)} and its related methods @@ -238,7 +251,7 @@ public class StringBox { stringBuilder.setLength(rightEdge); } return this; - } // TODO: handle leftColumn < 0 + } public StringRow placeSubstringAlignRight(String string, int rightColumn) { String modifiedString = string diff --git a/src/test/java/edu/unl/cse/bohn/StringBoxTest.java b/src/test/java/edu/unl/cse/bohn/StringBoxTest.java index ca2310774b5a274afc90bae457168010f32e0edd..5dd45784ec9185c1c7c44a571aed4445b5e2a41c 100644 --- a/src/test/java/edu/unl/cse/bohn/StringBoxTest.java +++ b/src/test/java/edu/unl/cse/bohn/StringBoxTest.java @@ -197,7 +197,7 @@ public class StringBoxTest { int column = 10; String expectedOutput = "\n\n foo"; // Act - String actualOutput = stringBox.placeString(input, row, column).toString(); + String actualOutput = stringBox.placeString(input, row, column).toString(false); // Assert assertEquals(expectedOutput, actualOutput); } @@ -239,7 +239,7 @@ public class StringBoxTest { .placeStringAlignBottomLeft(inputs[1], rows[1], columns[1]) .placeStringAlignTopRight(inputs[2], rows[2], columns[2]) .placeStringAlignBottomRight(inputs[3], rows[3], columns[3]) - .toString(true); + .toString(); // Assert assertEquals(expectedOutput, actualOutput); } @@ -262,7 +262,7 @@ public class StringBoxTest { int column = 10; String expectedOutput = " bar"; // Act - String actualOutput = stringBox.placeString(input, row, column).toString(); + String actualOutput = stringBox.placeString(input, row, column).toString(false); // Assert assertEquals(expectedOutput, actualOutput); }