Class Oscilloscope.IntegerFiFoCircularStack

  • Enclosing class:
    Oscilloscope

    public class Oscilloscope.IntegerFiFoCircularStack
    extends java.lang.Object
    The stack can hold a limited number of values but will never overflow. Think of the stack as a tube with a given length. If you push too many values in, the oldest will be pushed out at the end.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int bottom  
      private int capacity  
      private int[] stack  
      private int storedValues  
      private int top  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears the stack.
      int getCapacity()  
      int getLoad()  
      boolean isEmpty()  
      boolean isFull()  
      int peek​(int valueIfEmpty)
      Returns the oldest value from the stack without removing the value from the stack.
      int pop​(int valueIfEmpty)
      Returns the oldest value from the stack.
      int popNegate​(int valueIfEmpty)
      Returns the oldest value from the stack and negates the value.
      void push​(int value)
      Puts a value on the stack.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • bottom

        private int bottom
      • capacity

        private final int capacity
      • stack

        private final int[] stack
      • storedValues

        private int storedValues
      • top

        private int top
    • Constructor Detail

      • IntegerFiFoCircularStack

        public IntegerFiFoCircularStack​(int capacity)
        Creates a stack with the indicated capacity.
        Parameters:
        capacity - must be greater than 1
      • IntegerFiFoCircularStack

        public IntegerFiFoCircularStack​(int capacity,
                                        Oscilloscope.IntegerFiFoCircularStack oldStack)
        Creates stack with the indicated capacity and copies the old stack into the new stack and the old stack will be empty after this action.
        Parameters:
        capacity - must be greater than 1
        oldStack -
    • Method Detail

      • clear

        public void clear()
        Clears the stack.
      • getCapacity

        public int getCapacity()
      • getLoad

        public int getLoad()
        Returns:
        boolean
      • isEmpty

        public boolean isEmpty()
        Returns:
        boolean
      • isFull

        public boolean isFull()
        Returns:
        boolean
      • peek

        public int peek​(int valueIfEmpty)
        Returns the oldest value from the stack without removing the value from the stack. Returns the supplied entry if the stack is empty.
        Parameters:
        valueIfEmpty -
        Returns:
        int
      • pop

        public int pop​(int valueIfEmpty)
        Returns the oldest value from the stack. Returns the supplied entry if the stack is empty.
        Parameters:
        valueIfEmpty -
        Returns:
        int
      • popNegate

        public int popNegate​(int valueIfEmpty)
        Returns the oldest value from the stack and negates the value. Returns the supplied entry if the stack is empty.
        Parameters:
        valueIfEmpty -
        Returns:
        int
      • push

        public void push​(int value)
        Puts a value on the stack.
        Parameters:
        value -