java.lang.Object
no.ntnu.principes.util.ObservableStack<T>
- Type Parameters:
T- Type of elements stored in the stack
Stack implementation backed by an observable JavaFX list.
Provides standard stack operations with observable elements for UI binding.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all elements from the stack.booleanisEmpty()Checks if the stack is empty.peek()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.voidPushes an item onto the top of the stack.booleanremoveElement(T item) Removes the first occurrence of the specified element from the stack.intsize()Returns the number of elements in the stack.
-
Constructor Details
-
ObservableStack
public ObservableStack()
-
-
Method Details
-
push
Pushes an item onto the top of the stack.- Parameters:
item- The item to add to the stack
-
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
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
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
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.
-