Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cse332-18au
p1
Commits
548c2d71
Commit
548c2d71
authored
Jan 25, 2016
by
Michael Lee
Browse files
Make WorkList.toString non-consuming
parent
6157ce78
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cse332/interfaces/worklists/WorkList.java
View file @
548c2d71
...
...
@@ -89,22 +89,23 @@ public abstract class WorkList<E> implements Iterable<E> {
}
/**
* Note that the toString() method of a WorkList _consumes_ the WorkList.
* This can lead to odd and unpredictable behavior.
* Returns some basic information about this particular worklist.
*
* @postcondition hasWork() is false
* Calling this method does not consume the worklist.
*
* @return a string representation of this worklist
*/
@Override
public
String
toString
()
{
StringBuilder
result
=
new
StringBuilder
();
result
.
append
(
"["
);
while
(
this
.
hasWork
())
{
result
.
append
(
this
.
next
().
toString
()
+
", "
);
}
if
(
result
.
length
()
>
1
)
{
result
.
replace
(
result
.
length
()
-
2
,
result
.
length
(),
""
);
if
(
this
.
hasWork
())
{
return
String
.
format
(
"%s(size = %d, peek = %s)"
,
this
.
getClass
().
getSimpleName
(),
this
.
size
(),
this
.
peek
());
}
else
{
return
String
.
format
(
"%s(size = %d)"
,
this
.
getClass
().
getSimpleName
(),
this
.
size
());
}
result
.
append
(
"]"
);
return
result
.
toString
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment