Class ObservableStack<T>

java.lang.Object
no.ntnu.principes.util.ObservableStack<T>
Type Parameters:
T - Type of elements stored in the stack

public class ObservableStack<T> extends Object
Stack implementation backed by an observable JavaFX list. Provides standard stack operations with observable elements for UI binding.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all elements from the stack.
    boolean
    Checks if the stack is empty.
    Returns the item at the top of the stack without removing it.
    peek(int peekIndex)
    Returns the item at a specified position relative to the top of the stack.
    pop()
    Removes and returns the item at the top of the stack.
    void
    push(T item)
    Pushes an item onto the top of the stack.
    boolean
    Removes the first occurrence of the specified element from the stack.
    int
    Returns the number of elements in the stack.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ObservableStack

      public ObservableStack()
  • Method Details

    • push

      public void push(T item)
      Pushes an item onto the top of the stack.
      Parameters:
      item - The item to add to the stack
    • pop

      public T pop()
      Removes and returns the item at the top of the stack.
      Returns:
      The item at the top of the stack
      Throws:
      EmptyStackException - If the stack is empty
    • peek

      public T peek()
      Returns the item at the top of the stack without removing it.
      Returns:
      The item at the top of the stack
      Throws:
      EmptyStackException - If the stack is empty
    • peek

      public T peek(int peekIndex)
      Returns the item at a specified position relative to the top of the stack. Index 0 is the top of the stack, -1 is one below the top, etc.
      Parameters:
      peekIndex - Relative index from the top (0 = top, negative values = below top)
      Returns:
      The item at the specified position, or null if index is out of bounds
    • isEmpty

      public boolean isEmpty()
      Checks if the stack is empty.
      Returns:
      True if the stack contains no elements, false otherwise
    • removeElement

      public boolean removeElement(T item)
      Removes the first occurrence of the specified element from the stack.
      Parameters:
      item - The element to remove
      Returns:
      True if the element was removed, false if not found
    • size

      public int size()
      Returns the number of elements in the stack.
      Returns:
      The number of elements in the stack
    • clear

      public void clear()
      Removes all elements from the stack.