|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectscranton.list.PositionalListVia2Stacks
LinkedSList implements the PositionalList interface with a pair of
stacks.
A positional list may be specified as an ordered pair this = (i, L)
where
L is an n-tuple, L = ()
or L = (a0, a1, ..., an-1, and
-1 <= i < #(L)
Initially this = (-1, ())
The first ordinate, i, is the position indicator. It is
either set to -1 to indicate the current position is undefined
or 0<= i < #(L), indicating the current active location.
Mapping:
The list specification, (i,L) maps onto the attributes in LinkedSList as follows:
If L = (), then left and current are empty.
else if i != -1,
left contains a0, ..., ai-1 with ai-1 at the top of the stack
current contains ai, ..., an-1 with ai at the top of the stack
| Field Summary | |
protected Stack |
current
For i>0, current contains ai, ..., an-1 with ai at the top of the stack |
protected Stack |
left
For i>0, left contains a0, ..., ai-1 with ai-1 at the top of the stack |
| Constructor Summary | |
PositionalListVia2Stacks()
Initialize the list as a pair of empty stacks. |
|
| Method Summary | |
boolean |
atFront()
Reports whether or not current viewing position is at front of list |
boolean |
atRear()
Reports whether or not current viewing position is at rear of list |
PositionalList |
factory()
Returns an empty PositionalList implementation of the type used in the method's application. |
void |
insert(java.lang.Object obj)
Insert obj at the current position in the list
Pre: #(L) = 0 or 0 <= i
Post: L' = #(L)+1
if #(L)=0 then i'=0, L' = (obj)
else if i>#(L)-1 then i' = #(L')-1, L' = (L, obj)
else i' = i, L' = (a0, ..., ai-1, obj, ai, ..., an-1)
Mapping: obj is pushed into the stack, current, on top of other objects in that stack |
boolean |
isEmpty()
Reports whether or not the list is empty (i.e., contains no items). |
void |
next()
Moves current viewing position one object towards the rear, if possible. |
void |
previous()
Moves current viewing position one place towards the front, if possible. |
java.lang.Object |
remove()
Removes the current item from the list |
void |
replace(java.lang.Object obj)
Replaces item at current position in the list with obj. |
void |
toFront()
Moves current viewing position to front of list Pre: none Post: L'==(), R'==(L, R) |
void |
toRear()
Moves current viewing position to rear of list Pre: none Post: L'==(L, R), R'==() |
java.lang.String |
toString()
Return a string representation of a positonal list. |
java.lang.Object |
view()
Returns a reference to the current item in list. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected Stack left
left contains a0, ..., ai-1 with ai-1 at the top of the stack
protected Stack current
current contains ai, ..., an-1 with ai at the top of the stack
| Constructor Detail |
public PositionalListVia2Stacks()
| Method Detail |
public void insert(java.lang.Object obj)
obj at the current position in the list
Pre: #(L) = 0 or 0 <= i
Post: L' = #(L)+1
if #(L)=0 then i'=0, L' = (obj)
else if i>#(L)-1 then i' = #(L')-1, L' = (L, obj)
else i' = i, L' = (a0, ..., ai-1, obj, ai, ..., an-1)
Mapping: obj is pushed into the stack, current, on top of other objects in that stack
insert in interface PositionalListobj - New item inserted at the current position.public java.lang.Object remove()
PositionalList
remove in interface PositionalListObject, the item that was removed
Pre: !atRear(), equivalently R!=()
Post: R = (r0, R')
Returns: r0public java.lang.Object view()
PositionalList
view in interface PositionalListObject, a reference to current item in list
Pre: !atRear(), equivalently R!=()
Post: this' = this
Returns: r0public void replace(java.lang.Object obj)
PositionalList
replace in interface PositionalListobj - The object replacing the current object in the list.public void toFront()
PositionalList
toFront in interface PositionalListpublic void toRear()
PositionalList
toRear in interface PositionalListpublic void previous()
PositionalList
previous in interface PositionalListpublic void next()
PositionalList
next in interface PositionalListpublic boolean atFront()
PositionalList
atFront in interface PositionalListboolean true iff current position is front
Pre: none
Post: P'==P
Returns: L==()public boolean atRear()
PositionalList
atRear in interface PositionalListboolean true iff current position is rear
Pre: none
Post: P'==P
Returns: R==()public boolean isEmpty()
PositionalList
isEmpty in interface PositionalListboolean true iff the list is empty.
Pre: none
Post: P'==P
Returns: L==() && R==()public PositionalList factory()
PositionalList
factory in interface PositionalListpublic java.lang.String toString()
PositionalList
toString in interface PositionalList
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||