Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/kenri89/PROYECTO_UTP_AED_1_1/llms.txt

Use this file to discover all available pages before exploring further.

PilaAcciones_U3 in estructuras.PilaAcciones_U3 implements a LIFO stack using a singly-linked list of internal nodes. Every enrollment operation — both registration and cancellation — pushes an AccionMatricula record onto the top. The most recently performed action is always the first one visible in the history panel. The name suffix _U3 reflects the class’s origin in Unit 3 of the AED course, where stacks are introduced as the canonical LIFO structure.

The AccionMatricula Record

AccionMatricula in estructuras.AccionMatricula is a plain data record. It captures the action type and a snapshot of the Matricula that was affected. The tipo field uses the string literals "REGISTRO" and "ELIMINACIÓN" — a third value "ACTUALIZACIÓN" is defined in the source comment but not currently emitted by the system.
public class AccionMatricula {
    private String tipo; // "REGISTRO" or "ELIMINACIÓN"
    private Matricula matricula;

    public AccionMatricula(String tipo, Matricula matricula) {
        this.tipo = tipo;
        this.matricula = matricula;
    }

    public String getTipo()       { return tipo; }
    public Matricula getMatricula() { return matricula; }
}

Public API

1

apilar(AccionMatricula accion)

Pushes a new node onto the top of the stack in O(1). The new node’s siguiente pointer is set to the current tope, then tope is updated to point to the new node.
public void apilar(AccionMatricula accion) {
    Nodo nuevo = new Nodo(accion);
    nuevo.siguiente = tope;
    tope = nuevo;
}
2

desapilar()

Pops the top element and returns its AccionMatricula. Returns null if the stack is empty — callers must null-check. Complexity O(1).
public AccionMatricula desapilar() {
    if (tope == null) return null;
    AccionMatricula accion = tope.accion;
    tope = tope.siguiente;
    return accion;
}
3

estaVacia()

Returns true when tope == null. O(1). Used as a guard before calling desapilar.
4

recorrer(Consumer<AccionMatricula> callback)

Iterates the stack from top to bottom without destructively popping any element. The caller supplies a Consumer<AccionMatricula> lambda — typically a table-row appender for the history panel. Complexity O(n).
public void recorrer(java.util.function.Consumer<AccionMatricula> callback) {
    Nodo actual = tope;
    while (actual != null) {
        callback.accept(actual.accion);
        actual = actual.siguiente;
    }
}
5

copiar()

Returns a new PilaAcciones_U3 containing the same elements in the same top-to-bottom order, without modifying the original. Uses a two-pass reverse algorithm that avoids java.util.Stack and Collections.reverse. See the algorithm explanation below.
public PilaAcciones_U3 copiar() {
    PilaAcciones_U3 auxiliar = new PilaAcciones_U3();
    PilaAcciones_U3 copia    = new PilaAcciones_U3();

    // Pass 1: push all elements into auxiliar (reverses order)
    Nodo actual = tope;
    while (actual != null) {
        auxiliar.apilar(actual.accion);
        actual = actual.siguiente;
    }

    // Pass 2: push from auxiliar into copia (re-reverses, restoring original order)
    actual = auxiliar.tope;
    while (actual != null) {
        copia.apilar(actual.accion);
        actual = actual.siguiente;
    }

    return copia;
}

Copy Algorithm Explanation

The copiar() method must produce a stack with the same top-to-bottom order as the original, but a naive single-pass push into a new stack would reverse the order because each push becomes the new top. The two-pass strategy solves this:
  1. Pass 1 — reverse into auxiliary: Traverse tope → bottom pushing each element into auxiliar. The bottom element is now auxiliar’s top.
  2. Pass 2 — reverse back into copy: Traverse auxiliar.tope → bottom pushing each element into copia. The bottom element becomes copia’s bottom again, restoring the original order.
The result is a fully independent copy where changes to either stack do not affect the other.

Session Scope

The stack instance lives inside MenuPrincipal and is passed by reference to the enrollment and cancellation panels. It is not persisted — closing the application clears the audit trail. On next launch the history panel starts empty.
Because AccionMatricula stores a direct reference to the Matricula object (not a deep copy), mutating a Matricula after pushing an action will also mutate the snapshot in the stack. Treat pushed records as read-only.

Usage Example

PilaAcciones_U3 pila = new PilaAcciones_U3();
pila.apilar(new AccionMatricula("REGISTRO",   matricula1));
pila.apilar(new AccionMatricula("ELIMINACIÓN", matricula2));

// Display all actions from most recent to oldest
pila.recorrer(a ->
    System.out.println(a.getTipo() + ": " + a.getMatricula())
);

// Safe copy for UI rendering — original stack is unmodified
PilaAcciones_U3 copia = pila.copiar();

Build docs developers (and LLMs) love