commit c34c0846b707ba6f6ae97dccd9bbbe662407fe29 Author: luis.garcia104 Date: Fri Oct 9 15:35:11 2026 +0200 Primer commit diff --git a/1.7.pdf b/1.7.pdf new file mode 100644 index 0000000..b6a91f9 Binary files /dev/null and b/1.7.pdf differ diff --git a/Fichero_07/.classpath b/Fichero_07/.classpath new file mode 100644 index 0000000..4e29ea7 --- /dev/null +++ b/Fichero_07/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Fichero_07/.project b/Fichero_07/.project new file mode 100644 index 0000000..3c18ba9 --- /dev/null +++ b/Fichero_07/.project @@ -0,0 +1,17 @@ + + + Fichero_07 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Fichero_07/.settings/org.eclipse.core.resources.prefs b/Fichero_07/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/Fichero_07/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/Fichero_07/.settings/org.eclipse.jdt.core.prefs b/Fichero_07/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..e4acff5 --- /dev/null +++ b/Fichero_07/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,13 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=26 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=26 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=26 diff --git a/Fichero_07/bin/module-info.class b/Fichero_07/bin/module-info.class new file mode 100644 index 0000000..4a95fd7 Binary files /dev/null and b/Fichero_07/bin/module-info.class differ diff --git a/Fichero_07/bin/org/palomafp/aadd/lmga/dao/IPaisDAO.class b/Fichero_07/bin/org/palomafp/aadd/lmga/dao/IPaisDAO.class new file mode 100644 index 0000000..aacb253 Binary files /dev/null and b/Fichero_07/bin/org/palomafp/aadd/lmga/dao/IPaisDAO.class differ diff --git a/Fichero_07/bin/org/palomafp/aadd/lmga/dao/impl/PaisDaoFichero.class b/Fichero_07/bin/org/palomafp/aadd/lmga/dao/impl/PaisDaoFichero.class new file mode 100644 index 0000000..7176c19 Binary files /dev/null and b/Fichero_07/bin/org/palomafp/aadd/lmga/dao/impl/PaisDaoFichero.class differ diff --git a/Fichero_07/bin/org/palomafp/aadd/lmga/model/Continente.class b/Fichero_07/bin/org/palomafp/aadd/lmga/model/Continente.class new file mode 100644 index 0000000..e4b920b Binary files /dev/null and b/Fichero_07/bin/org/palomafp/aadd/lmga/model/Continente.class differ diff --git a/Fichero_07/bin/org/palomafp/aadd/lmga/model/Pais.class b/Fichero_07/bin/org/palomafp/aadd/lmga/model/Pais.class new file mode 100644 index 0000000..bb63de0 Binary files /dev/null and b/Fichero_07/bin/org/palomafp/aadd/lmga/model/Pais.class differ diff --git a/Fichero_07/bin/org/palomafp/dam2/aadd/lmga/GestorMapaMundi.class b/Fichero_07/bin/org/palomafp/dam2/aadd/lmga/GestorMapaMundi.class new file mode 100644 index 0000000..40b78ee Binary files /dev/null and b/Fichero_07/bin/org/palomafp/dam2/aadd/lmga/GestorMapaMundi.class differ diff --git a/Fichero_07/config/application.properties b/Fichero_07/config/application.properties new file mode 100644 index 0000000..b05bab5 --- /dev/null +++ b/Fichero_07/config/application.properties @@ -0,0 +1,5 @@ +fichero.continentes=C:\\Users\\alumnoT\\aadd\\fic05\\informacion_continentes.csv +fichero.paises=C:\\Users\\alumnoT\\aadd\\fic05\\informacion_paises.txt + +separador.continentes=# +separador.paises=, \ No newline at end of file diff --git a/Fichero_07/src/module-info.java b/Fichero_07/src/module-info.java new file mode 100644 index 0000000..c790b17 --- /dev/null +++ b/Fichero_07/src/module-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * + */ +module Fichero_03 { +} \ No newline at end of file diff --git a/Fichero_07/src/org/palomafp/aadd/lmga/dao/IPaisDAO.java b/Fichero_07/src/org/palomafp/aadd/lmga/dao/IPaisDAO.java new file mode 100644 index 0000000..de0c581 --- /dev/null +++ b/Fichero_07/src/org/palomafp/aadd/lmga/dao/IPaisDAO.java @@ -0,0 +1,15 @@ +package org.palomafp.aadd.lmga.dao; + +import org.palomafp.aadd.lmga.model.Pais; +import org.palomafp.aadd.lmga.model.Continente; +import java.util.List; + +public interface IPaisDAO { + Pais obtenerPaisPorID(int idPais); + List obtenerPaisesPorContinente(String codContinente); + List obtenerTodosLosContinentes(); + Continente obtenerContinentePorCodigo(String codContinente); + boolean insertarContinente(String codContinente, String nombreContinente); + boolean eliminarContinente(String codContinente); + boolean actualizarNombreContinente(String cod, String nuevoNombre); +} \ No newline at end of file diff --git a/Fichero_07/src/org/palomafp/aadd/lmga/dao/impl/PaisDaoFichero.java b/Fichero_07/src/org/palomafp/aadd/lmga/dao/impl/PaisDaoFichero.java new file mode 100644 index 0000000..2532449 --- /dev/null +++ b/Fichero_07/src/org/palomafp/aadd/lmga/dao/impl/PaisDaoFichero.java @@ -0,0 +1,221 @@ +package org.palomafp.aadd.lmga.dao.impl; + +import org.palomafp.aadd.lmga.dao.IPaisDAO; +import org.palomafp.aadd.lmga.model.Continente; +import org.palomafp.aadd.lmga.model.Pais; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.regex.Pattern; + +public class PaisDaoFichero implements IPaisDAO { + + private String ficheroPaises; + private String ficheroContinentes; + private String separadorContinentes; + private String separadorPaises; + + private Map mapContinentes; + + public PaisDaoFichero() { + this.mapContinentes = new HashMap<>(); + cargarConfiguracion(); + cargarContinentes(); + } + + private void cargarConfiguracion() { + Properties prop = new Properties(); + try (InputStream input = getClass().getClassLoader().getResourceAsStream("config/application.properties")) { + if (input == null) { + System.err.println("Error: No se pudo encontrar el fichero 'config/application.properties'"); + return; + } + prop.load(input); + + this.ficheroContinentes = prop.getProperty("fichero.continentes"); + this.ficheroPaises = prop.getProperty("fichero.paises"); + + this.separadorContinentes = prop.getProperty("separador.continentes", "#"); + this.separadorPaises = prop.getProperty("separador.paises", ","); + + } catch (IOException e) { + System.err.println("Error al cargar el fichero de propiedades: " + e.getMessage()); + } + } + + private void cargarContinentes() { + if (ficheroContinentes == null) return; + + try (BufferedReader reader = new BufferedReader(new FileReader(ficheroContinentes))) { + String linea; + while ((linea = reader.readLine()) != null) { + linea = linea.trim(); + if (linea.isEmpty() || linea.startsWith("anyo") || linea.startsWith(separadorContinentes)) { + continue; + } + + String[] partes = linea.split(Pattern.quote(separadorContinentes)); + if (partes.length >= 3) { + String cod = partes[1].replace("\"", "").trim(); + String nombre = partes[2].replace("\"", "").trim(); + mapContinentes.put(cod, new Continente(cod, nombre)); + } + } + } catch (IOException e) { + System.err.println("Error al leer el fichero de continentes: " + e.getMessage()); + } + } + + @Override + public List obtenerTodosLosContinentes() { + return new ArrayList<>(mapContinentes.values()); + } + + @Override + public Continente obtenerContinentePorCodigo(String codContinente) { + return mapContinentes.get(codContinente); + } + + @Override + public boolean insertarContinente(String cod, String nombre) { + if (mapContinentes.containsKey(cod)) { + return false; + } + try (FileWriter fw = new FileWriter(ficheroContinentes, true)) { + fw.write("\n2026" + separadorContinentes + cod + separadorContinentes + nombre); + mapContinentes.put(cod, new Continente(cod, nombre)); + return true; + } catch (IOException e) { + return false; + } + } + + @Override + public boolean eliminarContinente(String codContinente) { + if (!mapContinentes.containsKey(codContinente)) { + return false; + } + + try { + Path path = Paths.get(ficheroContinentes); + List lineas = Files.readAllLines(path); + List lineasFiltradas = new ArrayList<>(); + + for (String linea : lineas) { + String[] partes = linea.split(Pattern.quote(separadorContinentes)); + if (partes.length >= 2 && partes[1].replace("\"", "").trim().equals(codContinente)) { + continue; + } + lineasFiltradas.add(linea); + } + + Files.write(path, lineasFiltradas); + mapContinentes.remove(codContinente); + return true; + } catch (IOException e) { + return false; + } + } + + @Override + public boolean actualizarNombreContinente(String cod, String nuevoNombre) { + Continente c = mapContinentes.get(cod); + if (c == null) { + return false; + } + try { + Path path = Paths.get(ficheroContinentes); + List lineas = Files.readAllLines(path); + + String patronBusqueda = separadorContinentes + cod + separadorContinentes; + + for (int i = 0; i < lineas.size(); i++) { + if (lineas.get(i).contains(patronBusqueda)) { + String[] partes = lineas.get(i).split(Pattern.quote(separadorContinentes)); + lineas.set(i, partes[0] + separadorContinentes + cod + separadorContinentes + nuevoNombre); + } + } + + Files.write(path, lineas); + c.setNombre(nuevoNombre); + return true; + } catch (IOException e) { + return false; + } + } + + @Override + public Pais obtenerPaisPorID(int idPais) { + if (ficheroPaises == null) return null; + + try (BufferedReader reader = new BufferedReader(new FileReader(ficheroPaises))) { + String linea; + while ((linea = reader.readLine()) != null) { + linea = linea.trim(); + if (linea.isEmpty() || linea.startsWith("#")) { + continue; + } + + Pais pais = lineaAPais(linea); + if (pais != null && pais.getIdentificador() == idPais) { + return pais; + } + } + } catch (IOException e) { + System.err.println("Error al leer el fichero de países: " + e.getMessage()); + } + return null; + } + + @Override + public List obtenerPaisesPorContinente(String codContinente) { + List resultados = new ArrayList<>(); + if (ficheroPaises == null) return resultados; + + try (BufferedReader reader = new BufferedReader(new FileReader(ficheroPaises))) { + String linea; + while ((linea = reader.readLine()) != null) { + linea = linea.trim(); + if (linea.isEmpty() || linea.startsWith("#")) { + continue; + } + + Pais pais = lineaAPais(linea); + if (pais != null && pais.getContinente() != null && + codContinente.equals(pais.getContinente().getCodigo())) { + resultados.add(pais); + } + } + } catch (IOException e) { + System.err.println("Error al leer el fichero de países: " + e.getMessage()); + } + return resultados; + } + + private Pais lineaAPais(String linea) { + String[] partes = linea.split(Pattern.quote(separadorPaises)); + if (partes.length < 4) { + return null; + } + + String codContinente = partes[0].replace("\"", "").trim(); + int id = Integer.parseInt(partes[1].trim()); + String nombrePais = partes[2].replace("\"", "").trim(); + String capital = partes[3].replace("\"", "").trim(); + + Continente continente = mapContinentes.getOrDefault(codContinente, new Continente(codContinente, "Desconocido")); + + return new Pais(id, nombrePais, capital, continente); + } +} \ No newline at end of file diff --git a/Fichero_07/src/org/palomafp/aadd/lmga/model/Continente.java b/Fichero_07/src/org/palomafp/aadd/lmga/model/Continente.java new file mode 100644 index 0000000..56e4da2 --- /dev/null +++ b/Fichero_07/src/org/palomafp/aadd/lmga/model/Continente.java @@ -0,0 +1,35 @@ +package org.palomafp.aadd.lmga.model; + +public class Continente { + private String codigo; + private String nombre; + + public Continente() { + } + + public Continente(String codigo, String nombre) { + this.codigo = codigo; + this.nombre = nombre; + } + + public String getCodigo() { + return codigo; + } + + public void setCodigo(String codigo) { + this.codigo = codigo; + } + + public String getNombre() { + return nombre; + } + + public void setNombre(String nombre) { + this.nombre = nombre; + } + + @Override + public String toString() { + return this.nombre; + } +} diff --git a/Fichero_07/src/org/palomafp/aadd/lmga/model/Pais.java b/Fichero_07/src/org/palomafp/aadd/lmga/model/Pais.java new file mode 100644 index 0000000..1c9670f --- /dev/null +++ b/Fichero_07/src/org/palomafp/aadd/lmga/model/Pais.java @@ -0,0 +1,63 @@ + package org.palomafp.aadd.lmga.model; + + public class Pais { + private int identificador; + private String nombre; + private String capital; + private Continente continente; + + public Pais() { + } + + public Pais(int identificador, String nombre, String capital, Continente continente) { + this.identificador = identificador; + this.nombre = nombre; + this.capital = capital; + this.continente = continente; + } + + public int getIdentificador() { + return identificador; + } + + public void setIdentificador(int identificador) { + this.identificador = identificador; + } + + public String getNombre() { + return nombre; + } + + public void setNombre(String nombre) { + this.nombre = nombre; + } + + public String getCapital() { + return capital; + } + + public void setCapital(String capital) { + this.capital = capital; + } + + public Continente getContinente() { + return continente; + } + + public void setContinente(Continente continente) { + this.continente = continente; + } + + @Override + public String toString() { + + String nombreContinente = (this.continente != null && this.continente.getNombre() != null) + ? this.continente.getNombre() : "Desconocido"; + String codigoContinente = (this.continente != null && this.continente.getCodigo() != null) + ? this.continente.getCodigo() : "Desconocido"; + + + return this.nombre + " (" + this.identificador + ") con capital en " + this.capital + + " pertenece al continente " + nombreContinente + " (" + codigoContinente + ")"; + } + } diff --git a/Fichero_07/src/org/palomafp/dam2/aadd/lmga/GestorMapaMundi.java b/Fichero_07/src/org/palomafp/dam2/aadd/lmga/GestorMapaMundi.java new file mode 100644 index 0000000..11e9bd3 --- /dev/null +++ b/Fichero_07/src/org/palomafp/dam2/aadd/lmga/GestorMapaMundi.java @@ -0,0 +1,81 @@ +package org.palomafp.dam2.aadd.lmga; + +import org.palomafp.aadd.lmga.dao.IPaisDAO; +import org.palomafp.aadd.lmga.dao.impl.PaisDaoFichero; +import org.palomafp.aadd.lmga.model.Pais; +import org.palomafp.aadd.lmga.model.Continente; + +import java.util.List; + +public class GestorMapaMundi { + + private static final IPaisDAO paisDAO = new PaisDaoFichero(); + + public static void main(String[] args) { + + + + + switch(args[0]) { + case "1": + System.out.println("\nC: Obtener todos los continentes \n"); + List listaContinentes = paisDAO.obtenerTodosLosContinentes(); + + if (!listaContinentes.isEmpty()) { + for (Continente c : listaContinentes) { + System.out.println(c); + } + } else { + System.out.println("No hay continentes"); + } + break; + case "2": + + Continente continenteObtenido = obtenerContinentePorCodigo(args[1]); + if (continenteObtenido != null) { + System.out.println(continenteObtenido); + } else { + System.out.println("No se encontró ningún continente con el código: " + args[1]); + } + break; + case "3": + + if (paisDAO.insertarContinente(args[1], args[2])) { + System.out.println("Insertado correctamente."); + } else { + System.out.println("El continente ya existe o ha ocurrido un error."); + } + break; + case "4": + if (paisDAO.eliminarContinente(args[1])) { + System.out.println("Continente eliminado correctamente."); + } else { + System.out.println("El continente no existe o ha ocurrido un error."); + } + break; + case "5": + if (paisDAO.actualizarNombreContinente(args[1], args[2])) { + System.out.println("Nombre actualizado correctamente"); + } else { + System.out.println("El continente no existe o ha ocurrido un error."); + } + break; + default: + break; + } + + + } + + public static Pais obtenerPaisesPorIdentificador(int identificador) { + return paisDAO.obtenerPaisPorID(identificador); + } + + public static List obtenerListaPaisesPorContinente(String codContinente) { + return paisDAO.obtenerPaisesPorContinente(codContinente); + } + + public static Continente obtenerContinentePorCodigo(String codContinente) { + return paisDAO.obtenerContinentePorCodigo(codContinente); + } +} \ No newline at end of file diff --git a/informacion_continentes.csv b/informacion_continentes.csv new file mode 100644 index 0000000..0f5a746 --- /dev/null +++ b/informacion_continentes.csv @@ -0,0 +1,6 @@ +anyo#codigo_continente#nombre_continente +2026#01# África +2026#02 #América +2026#03#Asia +2026#04#Europa +2026#05#Oceanía \ No newline at end of file diff --git a/informacion_paises.txt b/informacion_paises.txt new file mode 100644 index 0000000..7b87853 --- /dev/null +++ b/informacion_paises.txt @@ -0,0 +1,23 @@ +# Información de países +# Se muestra información del código de continente, identificador de país, nombre del país junto con su capital +"01",1, "Angola", "Luanda" +"02",62, "Brasil", "Brasilia" +"02",63, "Canadá", "Ottawa" +"02",64, "Chile", "Santiago De Chile" +"02",65, "Colombia", "Bogotá" +# Otra lista de países +"03",92, "Afganistán", "Kabul" +"03",93, "Arabia Saudita", "Riad" +"03",105, "Filipinas", "Manila" +"03",106, "India", "Nueva Delhi" +"03",136, "Vietnam", "Hanoi" +"04",147, "Bulgaria", "Sofía" +"04",152, "España", "Madrid" +"04",181, "Suecia", "Estocolmo" +# La parte final de países +"04",182, "Suiza", "Berna" +"05",185, "Australia", "Canberra" +"05",186, "Fiyi", "Suva" +"05",187, "Islas Marshall", "Majuro" +"05",196, "Tonga", "Nuku'alofa" +"05",197, "Tuvalu", "Funafuti" \ No newline at end of file