Commit 927ae32d authored by Michael Lee's avatar Michael Lee
Browse files

Port documentation changes for worklist interfaces

parent 988d8e2f
package cse332.interfaces.worklists;
/**
* A subclass of WorkList that stores its elements in FIFO order.
* All subclasses of this class implicitly agree to the contract to
* be a FIFO queue. That is, add() must add to the "end" and
* next() must remove from the "beginning".
*
* A subclass of WorkList that stores its elements in FIFO order. All subclasses
* of this class implicitly agree to the contract to be a FIFO queue. That is,
* addWork() must add to the "end" and next() must remove from the "beginning".
*
* @author Adam Blank
* @param <E> the type of elements in the worklist
* @param <E>
* the type of elements in the worklist
*/
public abstract class FIFOWorkList<E> extends WorkList<E> {}
public abstract class FIFOWorkList<E> extends WorkList<E> {
}
package cse332.interfaces.worklists;
/**
* A subclass of WorkList that stores its elements in LIFO order.
* All subclasses of this class implicitly agree to the contract to
* be a LIFO queue. That is, add() must add to the "top" and
* next() must remove from the "top".
*
* A subclass of WorkList that stores its elements in LIFO order. All subclasses
* of this class implicitly agree to the contract to be a LIFO queue. That is,
* addWork() must add to the "top" and next() must remove from the "top".
*
* @author Adam Blank
* @param <E> the type of elements in the worklist
* @param <E>
* the type of elements in the worklist
*/
public abstract class LIFOWorkList<E> extends WorkList<E> {}
public abstract class LIFOWorkList<E> extends WorkList<E> {
}
package cse332.interfaces.worklists;
/**
* A subclass of WorkList that stores its elements in priority order.
* All subclasses of this class implicitly agree to the contract to be a
* priority queue. The "priority" of an element should be determined via
* compareTo(). The direction (min or max) is up to the implementation.
*
* A subclass of WorkList that stores its elements in priority order. All
* subclasses of this class implicitly agree to the contract to be a priority
* queue. The "priority" of an element should be determined via compareTo(). The
* direction (min or max) is up to the implementation.
*
* @author Adam Blank
*
* @param <E> the type of elements in the worklist; must be comparable
* @param <E>
* the type of elements in the worklist; must be comparable
*/
public abstract class PriorityWorkList<E extends Comparable<E>> extends WorkList<E> {}
public abstract class PriorityWorkList<E> extends WorkList<E> {
}
package cse332.interfaces.worklists;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* An object that stores work to be done in some specified order. This class should never be
* sub-classed directly. Further sub=classes indicate exactly how the elements should be
* handled.
*
* An object that stores work to be done in some specified order. This class
* should never be sub-classed directly. Further sub=classes indicate exactly
* how the elements should be handled.
*
* @author Adam Blank
* @param <E> the type of elements in the worklist
* @param <E>
* the type of elements in the worklist
*/
public abstract class WorkList<E> implements Iterable<E> {
public WorkList() {}
public WorkList() {
}
/**
* Returns true iff this worklist has any remaining work
*
*
* @return true iff there is at least one piece of work in the worklist.
*/
public boolean hasWork() {
return this.size() > 0;
}
/**
* Adds work to the worklist. This method should conform to any additional contracts that
* the particular type of worklist has.
*
* @param work the work to add to the worklist
* Adds work to the worklist. This method should conform to any additional
* contracts that the particular type of worklist has.
*
* @param work
* the work to add to the worklist
*/
public abstract void add(E work);
/**
* Returns a view to the next element of the worklist.
*
*
* @precondition hasWork() is true
* @postcondition return(peek()) is return(next())
* @postcondition the structure of this worklist remains unchanged.
* @throws NoSuchElementException if hasWork() is false
* @return the next element in this worklist
* @throws NoSuchElementException
* if hasWork() is false
* @return the next element in this worklist
*/
public abstract E peek();
/**
* Returns and removes the next element of the worklist
*
* Returns and removes the next element of the worklist
*
* @precondition hasWork() is true
* @postcondition return(next()) + after(next()) == before(next())
* @postcondition after(size()) + 1 == before(size())
* @throws NoSuchElementException if hasWork() is false
* @postcondition after(size()) + 1 == before(size())
* @throws NoSuchElementException
* if hasWork() is false
* @return the next element in this worklist
*/
public abstract E next();
/**
* Returns the number of elements of work remaining in this worklist
*
*
* @return the size of this worklist
*/
public abstract int size();
/**
* Resets this worklist to the same state it was in right after construction.
* Resets this worklist to the same state it was in right after
* construction.
*/
public abstract void clear();
private class WorkListIterator implements Iterator<E> {
@Override
public boolean hasNext() {
......@@ -80,12 +87,14 @@ public abstract class WorkList<E> implements Iterable<E> {
public Iterator<E> iterator() {
return new WorkListIterator();
}
/**
* Note that the toString() method of a WorkList _consumes_ the WorkList. This
* can lead to odd and unpredictable behavior.
* Note that the toString() method of a WorkList _consumes_ the WorkList.
* This can lead to odd and unpredictable behavior.
*
* @postcondition hasWork() is false
*/
@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append("[");
......
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