Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
string_box
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christopher Bohn
string_box
Commits
fb57f2ea
Commit
fb57f2ea
authored
Feb 24, 2020
by
Christopher Bohn
Browse files
Options
Downloads
Patches
Plain Diff
Reversed toString() default behavior
Now by default pads the string with newlines to fill the StringBox
parent
8f8c9c98
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/edu/unl/cse/bohn/StringBox.java
+19
-6
19 additions, 6 deletions
src/main/java/edu/unl/cse/bohn/StringBox.java
src/test/java/edu/unl/cse/bohn/StringBoxTest.java
+3
-3
3 additions, 3 deletions
src/test/java/edu/unl/cse/bohn/StringBoxTest.java
with
22 additions
and
9 deletions
src/main/java/edu/unl/cse/bohn/StringBox.java
+
19
−
6
View file @
fb57f2ea
...
...
@@ -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(
S
tring,
int, int)}
</p>
* <p>Equivalent to
<code>
placeStringAlignTopLeft(
s
tring,
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
(
fals
e
);
return
toString
(
tru
e
);
}
/**
*
<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
...
...
This diff is collapsed.
Click to expand it.
src/test/java/edu/unl/cse/bohn/StringBoxTest.java
+
3
−
3
View file @
fb57f2ea
...
...
@@ -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
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment