Class Stack3<T>

java.lang.Object
components.stack.StackSecondary<T>
components.stack.Stack3<T>
Type Parameters:
T - type of Stack entries
All Implemented Interfaces:
Stack<T>, StackKernel<T>, Standard<Stack<T>>, Iterable<T>

public class Stack3<T> extends StackSecondary<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

    Constructors
    Constructor
    Description
    No-argument constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    Resets this to an initial value.
    final Iterator<T>
     
    final int
    Reports length of this.
    final Stack<T>
    Returns a new object with the same dynamic type as this, having an initial value.
    final T
    pop()
    Removes x from the top of this.
    final void
    push(T x)
    Adds x to the top of this.
    final T
    Replaces the top of this with x, and returns the old top.
    final T
    top()
    Reports the top of this.
    final void
    transferFrom(Stack<T> source)
    Sets this to the incoming value of source, and resets source to an initial value; the declaration notwithstanding, the dynamic type of source must be the same as the dynamic type of this.

    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

      public final Stack<T> newInstance()
      Description copied from interface: Standard
      Returns a new object with the same dynamic type as this, having an initial value. If the type T has a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor for T. If T 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 initialize this .
      Returns:
      new object "like" this with an initial value
    • clear

      public final void clear()
      Description copied from interface: Standard
      Resets this to an initial value. If the type T has a no-argument constructor, then this satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then this satisfies the contract of the constructor call that was used to initialize #this.
    • transferFrom

      public final void transferFrom(Stack<T> source)
      Description copied from interface: Standard
      Sets this to the incoming value of source, and resets source to an initial value; the declaration notwithstanding, the dynamic type of source must be the same as the dynamic type of this. If the type T has a no-argument constructor, then source satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then source satisfies the contract of the constructor call that was used to initialize #source.
      Parameters:
      source - object whose value is to be transferred
    • push

      public final void push(T x)
      Description copied from interface: StackKernel
      Adds x to the top of this.
      Parameters:
      x - the entry to be added
    • pop

      public final T pop()
      Description copied from interface: StackKernel
      Removes x from the top of this.
      Returns:
      the entry removed
    • length

      public final int length()
      Description copied from interface: StackKernel
      Reports length of this.
      Returns:
      the length of this
    • iterator

      public final Iterator<T> iterator()
    • top

      public final T top()
      Description copied from interface: Stack
      Reports the top of this.
      Specified by:
      top in interface Stack<T>
      Overrides:
      top in class StackSecondary<T>
      Returns:
      the top entry of this
    • replaceTop

      public final T replaceTop(T x)
      Description copied from interface: Stack
      Replaces the top of this with x, and returns the old top.
      Specified by:
      replaceTop in interface Stack<T>
      Overrides:
      replaceTop in class StackSecondary<T>
      Parameters:
      x - the new top entry
      Returns:
      the old top entry