Skip to content
Snippets Groups Projects
Commit 2534033d authored by Adam Blank's avatar Adam Blank
Browse files

Merge branch 'change-worklist-tostring' into 'master'

Make WorkList's toString method non-consuming



See merge request !2
parents 46c5dfd5 09aecbea
No related branches found
No related tags found
No related merge requests found
...@@ -89,22 +89,23 @@ public abstract class WorkList<E> implements Iterable<E> { ...@@ -89,22 +89,23 @@ public abstract class WorkList<E> implements Iterable<E> {
} }
/** /**
* Note that the toString() method of a WorkList _consumes_ the WorkList. * Returns some basic information about this particular worklist.
* This can lead to odd and unpredictable behavior. *
* * Calling this method does not consume the worklist.
* @postcondition hasWork() is false *
* @return a string representation of this worklist
*/ */
@Override @Override
public String toString() { public String toString() {
StringBuilder result = new StringBuilder(); if (this.hasWork()) {
result.append("["); return String.format("%s(size = %d, peek = %s)",
while (this.hasWork()) { this.getClass().getSimpleName(),
result.append(this.next().toString() + ", "); this.size(),
} this.peek());
if (result.length() > 1) { } else {
result.replace(result.length() - 2, result.length(), ""); return String.format("%s(size = %d)",
this.getClass().getSimpleName(),
this.size());
} }
result.append("]");
return result.toString();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment