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
Branches master
No related tags found
No related merge requests found
......@@ -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();
}
}
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