|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjpaul.DataStructs.WorkList<T>
public class WorkList<T>
WorkList is a WorkSet with FIFO order.
Good for algorithms that work on levels. The
add/extract operations have O(1)
complexity.
| Field Summary | |
|---|---|
protected java.util.LinkedList<T> |
list
List that provides the order of the elements from this workset. |
| Constructor Summary | |
|---|---|
WorkList()
|
|
| Method Summary | |
|---|---|
boolean |
add(T elem)
Adds the element elem to this
workset. |
boolean |
addAll(java.util.Collection<T> elems)
Adds all elements from elems to this
workset. |
protected void |
addToOrder(T elem)
Overrides the abstract method WorkSetAbstr.addToOrder(T). |
void |
clear()
Removes all elements from the workset. Complexity: O(1). |
boolean |
contains(T e)
Checks whether this workset contains the element
e.Complexity: O(1). |
T |
extract()
Returns the first element of this workset
(according to the order specific to this workset. |
protected T |
extractInOrder()
Overrides WorkSetAbstr.extractInOrder(). |
boolean |
isEmpty()
Checks whether this workset is empty.Complexity: O(1). |
int |
size()
Returns the size of this workset.Invariant: isEmpty() iff size() ==
0.Complexity: O(1). |
java.lang.String |
toString()
|
protected java.util.Collection<T> |
underlyingOrder()
Returns the underlying ordered collection. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected java.util.LinkedList<T> list
this workset.
| Constructor Detail |
|---|
public WorkList()
| Method Detail |
|---|
protected void addToOrder(T elem)
WorkSetAbstr.addToOrder(T). Add
elem at the tail of the list, to implement FIFO
order.
protected T extractInOrder()
WorkSetAbstr.extractInOrder(). States that
we always extract elements from the head of the list.
Therefore, subclasses define the extraction order by
overriding WorkSetAbstr.addToOrder(T).
protected java.util.Collection<T> underlyingOrder()
clear and
toString.
public boolean add(T elem)
WorkSetelem to this
workset.
add in interface WorkSet<T>true if elem was not already
in the workset. If elem was already in the
workset, the workset does not change in any way, and
add returns false.public boolean addAll(java.util.Collection<T> elems)
WorkSetelems to this
workset.
addAll in interface WorkSet<T>true if any of the added elements was not
already in this workset. Otherwise, the workset
does not change in any way, and add returns
false.public T extract()
WorkSetthis workset
(according to the order specific to this workset.
The element is removed from the workset. Throws a NoSuchElementException if
the workset is empty.
extract in interface WorkSet<T>public void clear()
WorkSet
clear in interface WorkSet<T>public boolean isEmpty()
WorkSetthis workset is empty.
isEmpty in interface WorkSet<T>public boolean contains(T e)
WorkSetthis workset contains the element
e.
contains in interface WorkSet<T>public int size()
WorkSetthis workset.isEmpty() iff size() ==
0.
size in interface WorkSet<T>public java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||