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.

ArregloCursos in estructuras.ArregloCursos is a dynamic array backed by a plain Curso[]. The initial capacity is 100 elements. When the logical size contador reaches the physical array length, a redimensionar() call creates a new array at twice the capacity and copies all elements using System.arraycopy. The class is the primary data source for Apache POI Excel export, and its obtener(int indice) method enables O(1) random access that the linked structures cannot provide.

Internal State

The class maintains two private fields:
FieldTypeDescription
cursosCurso[]Backing array, starts at length 100
contadorintLogical element count (next free index)
All positions from index 0 to contador - 1 are populated; positions contador and above are null.

Public API

1

insertar(Curso curso)

Appends the course at index contador. If contador >= cursos.length, redimensionar() is called first to double the backing array. Amortised complexity O(1).
public void insertar(Curso curso) {
    if (contador >= cursos.length) {
        redimensionar();
    }
    cursos[contador++] = curso;
}
2

obtener(int indice)

Returns the Curso at the given index with a bounds check against contador. Returns null for an out-of-range index rather than throwing. Complexity O(1).
public Curso obtener(int indice) {
    if (indice >= 0 && indice < contador) {
        return cursos[indice];
    }
    return null;
}
3

getContador()

Returns the logical size of the array — the number of currently stored courses. O(1). Used by iteration loops: for (int i = 0; i < arreglo.getContador(); i++).
4

obtenerCursos()

Collects all non-null elements from index 0 to contador - 1 into a List<Curso> and returns it. This is the method called by ExportadorExcel to stream course data into an Apache POI workbook. Complexity O(n).
public List<Curso> obtenerCursos() {
    List<Curso> lista = new ArrayList<>();
    for (int i = 0; i < contador; i++) {
        if (cursos[i] != null) {
            lista.add(cursos[i]);
        }
    }
    return lista;
}
5

buscar(String codigo)

Linear scan from index 0 to contador - 1, comparing each element’s getCodigo() with equalsIgnoreCase. Returns the first matching Curso or null. Complexity O(n).
6

eliminarPorCodigo(String codigo)

Finds the target element by linear scan, then shifts all subsequent elements one position to the left to close the gap, nulls the last occupied slot, and decrements contador. Returns true if removed, false if not found. Complexity O(n).
public boolean eliminarPorCodigo(String codigo) {
    for (int i = 0; i < contador; i++) {
        if (cursos[i] != null && cursos[i].getCodigo().equalsIgnoreCase(codigo)) {
            for (int j = i; j < contador - 1; j++) {
                cursos[j] = cursos[j + 1];
            }
            cursos[--contador] = null;
            return true;
        }
    }
    return false;
}
7

actualizarCurso(String codigo, Curso actualizado)

Locates the element by code with a linear scan and replaces it in-place with the actualizado reference. The slot index does not change. Returns true on success. Complexity O(n).
8

limpiar()

Nulls every element from index 0 to contador - 1 and resets contador to 0. Used during a full data reload from persistence.

Resize Algorithm

When the backing array is full, redimensionar() allocates a new array of double the current length and uses System.arraycopy for an efficient block copy.
private void redimensionar() {
    Curso[] nuevoArreglo = new Curso[cursos.length * 2];
    System.arraycopy(cursos, 0, nuevoArreglo, 0, cursos.length);
    cursos = nuevoArreglo;
}
Starting at 100 and doubling means the first resize produces capacity 200, the second 400, and so on. In practice the course catalogue rarely exceeds a few dozen entries, so a resize never occurs during normal operation.

ExportadorExcel Integration

ExportadorExcel.exportarCursos(ArregloCursos arreglo, File destino) calls arreglo.obtenerCursos() to obtain a List<Curso> and then iterates it with Apache POI to write each course as a row in an .xlsx workbook. ArregloCursos is the sole source for this export; ListaCursos and MatrizSemestres are not used by the exporter.
// Typical export call from the UI panel
File archivo = new File("cursos_exportados.xlsx");
ExportadorExcel.exportarCursos(arregloCursos, archivo);

Relationship with ListaCursos

ListaCursos is a parallel singly-linked list that holds references to the same Curso objects stored in ArregloCursos. The two structures do not duplicate data — they share object references. ListaCursos is used for combo-box traversal via its recorrer(Consumer<Curso>) method and for enrollment lookups via buscar(String codigo), while ArregloCursos serves iteration-by-index and Excel export.
Because both structures reference the same Curso instances, mutating a Curso field (such as calling setCodigo or setNombre) through one structure is immediately visible through the other. All structural operations (insert, delete, update) must still be applied to both structures explicitly — only field mutations propagate automatically.

Build docs developers (and LLMs) love