Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
p2
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Han Zhang
p2
Commits
2534033d
Commit
2534033d
authored
9 years ago
by
Adam Blank
Browse files
Options
Downloads
Plain Diff
Merge branch 'change-worklist-tostring' into 'master'
Make WorkList's toString method non-consuming See merge request !2
parents
46c5dfd5
09aecbea
Branches
master
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cse332/interfaces/worklists/WorkList.java
+14
-13
14 additions, 13 deletions
src/cse332/interfaces/worklists/WorkList.java
with
14 additions
and
13 deletions
src/cse332/interfaces/worklists/WorkList.java
+
14
−
13
View file @
2534033d
...
...
@@ -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.
*
* @postcondition hasWork() is false
* Returns some basic information about this particular worklist.
*
* 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
();
}
}
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