Commit 548c2d71 authored by Michael Lee's avatar Michael Lee
Browse files

Make WorkList.toString non-consuming

parent 6157ce78
......@@ -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();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment