Package components.stack
Class Stack3<T>
java.lang.Object
components.stack.StackSecondary<T>
components.stack.Stack3<T>
- Type Parameters:
T
- type ofStack
entries
- All Implemented Interfaces:
Stack<T>
,StackKernel<T>
,Standard<Stack<T>>
,Iterable<T>
Stack
represented as a Sequence
of entries, with
implementations of primary methods.- Abstraction Relation (interpretation mapping between $this and this):
this = $this.entries
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
clear()
Resetsthis
to an initial value.iterator()
final int
length()
Reports length ofthis
.Returns a new object with the same dynamic type asthis
, having an initial value.final T
pop()
Removesx
from the top ofthis
.final void
Addsx
to the top ofthis
.final T
replaceTop
(T x) Replaces the top ofthis
withx
, and returns the old top.final T
top()
Reports the top ofthis
.final void
transferFrom
(Stack<T> source) Setsthis
to the incoming value ofsource
, and resetssource
to an initial value; the declaration notwithstanding, the dynamic type ofsource
must be the same as the dynamic type ofthis
.Methods inherited from class components.stack.StackSecondary
equals, flip, hashCode, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Stack3
public Stack3()No-argument constructor.
-
-
Method Details
-
newInstance
Description copied from interface:Standard
Returns a new object with the same dynamic type asthis
, having an initial value. If the typeT
has a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, then the value of the new returned object satisfies the contract of the constructor call that was used to initializethis
.- Returns:
- new object "like"
this
with an initial value
-
clear
Description copied from interface:Standard
Resetsthis
to an initial value. If the typeT
has a no-argument constructor, thenthis
satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, thenthis
satisfies the contract of the constructor call that was used to initialize#this
. -
transferFrom
Description copied from interface:Standard
Setsthis
to the incoming value ofsource
, and resetssource
to an initial value; the declaration notwithstanding, the dynamic type ofsource
must be the same as the dynamic type ofthis
. If the typeT
has a no-argument constructor, thensource
satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, thensource
satisfies the contract of the constructor call that was used to initialize#source
.- Parameters:
source
- object whose value is to be transferred
-
push
Description copied from interface:StackKernel
Addsx
to the top ofthis
.- Parameters:
x
- the entry to be added
-
pop
Description copied from interface:StackKernel
Removesx
from the top ofthis
.- Returns:
- the entry removed
-
length
Description copied from interface:StackKernel
Reports length ofthis
.- Returns:
- the length of
this
-
iterator
-
top
Description copied from interface:Stack
Reports the top ofthis
. -
replaceTop
Description copied from interface:Stack
Replaces the top ofthis
withx
, and returns the old top.- Specified by:
replaceTop
in interfaceStack<T>
- Overrides:
replaceTop
in classStackSecondary<T>
- Parameters:
x
- the new top entry- Returns:
- the old top entry
-