primer commit

This commit is contained in:
Isidoro Nevares Martín 2025-10-16 14:44:10 +02:00
commit 3970e5850e
15 changed files with 450 additions and 0 deletions

10
.classpath Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/bin/
*.class

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>aadd_act1_9</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View File

@ -0,0 +1,13 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=24
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=24
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=24

7
config/conf.properties Normal file
View File

@ -0,0 +1,7 @@
# Información sobre Continentes
continente.fichero.ruta=C:\\Users\\ineva\\aadd\\inm\\act14\\informacion_continentes.csv
continente.separador=\\|
# Información sobre País
pais.fichero.ruta=C:\\Users\\ineva\\aadd\\inm\\act14\\informacion_paises.txt
pais.separador=,

View File

@ -0,0 +1,52 @@
package es.palomafp.aadd.inm;
import java.util.List;
import es.palomafp.aadd.inm.dao.IContinenteDAO;
import es.palomafp.aadd.inm.dao.IPaisDAO;
import es.palomafp.aadd.inm.dao.impl.ContinenteDaoCSV;
import es.palomafp.aadd.inm.dao.impl.PaisDaoTXT;
import es.palomafp.aadd.inm.exception.MapaMundiException;
import es.palomafp.aadd.inm.vo.Continente;
import es.palomafp.aadd.inm.vo.Pais;
/**
*
* GestorMapaMundi: Clase que procesa el fichero con información de países y
* continentes
*
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
* @date 26 sept 2025
*/
public class GestorMapaMundi {
public static void main(String[] args) {
String codigoContinente = args[0];
IContinenteDAO iContinenteDAO = new ContinenteDaoCSV();
Continente continente;
List<Pais> listaPaises = null;
try {
continente = iContinenteDAO.obtenerContinente(codigoContinente);
System.out.println(continente);
IPaisDAO iPaisDAO = new PaisDaoTXT();
listaPaises = iPaisDAO.obtenerListaPaises(codigoContinente);
// System.out.println(listPaises);
} catch (MapaMundiException e) {
e.printStackTrace();
}
for (Pais pais : listaPaises) {
if (pais.getNombre().startsWith("S")) {
String informacionPais = "%s, capital de %s %d, pertenece al continente %s (%s)";
informacionPais = String.format(informacionPais, pais.getCapital(), pais.getNombre(),
pais.getIdentificador(), pais.getContinente().getNombre(), pais.getContinente().getCodigo());
System.out.println(informacionPais);
}
}
}
}

View File

@ -0,0 +1,39 @@
package es.palomafp.aadd.inm.config;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
/**
*
* GestorConfiguracion: Clase que se encarga de gestionar la configuración de
* los ficheros.
*
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
* @date 10 oct 2025
*
*
*/
public class GestorConfiguracion {
private static Properties propiedades = null;
// Bloque estático que se ejecuta una única vez al cargar la clase
static {
cargarPropiedadesFichero();
}
private static void cargarPropiedadesFichero() {
propiedades = new Properties();
try (FileInputStream fis = new FileInputStream("config/conf.properties")) {
propiedades.load(fis);
} catch (IOException e) {
System.err.println("No se pudo cargar el archivo de configuración.");
e.printStackTrace();
}
}
public static String getValorfromClave(String clave) {
return propiedades.getProperty(clave);
}
}

View File

@ -0,0 +1,15 @@
package es.palomafp.aadd.inm.dao;
import es.palomafp.aadd.inm.exception.MapaMundiException;
import es.palomafp.aadd.inm.vo.Continente;
/**
*
* IContinenteDAO: Interfaz que contiene las operaciones a realizar sobre un continente
*
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
* @date 2 oct 2025
*/
public interface IContinenteDAO {
Continente obtenerContinente(String codigoContinente) throws MapaMundiException;
}

View File

@ -0,0 +1,17 @@
package es.palomafp.aadd.inm.dao;
import java.util.List;
import es.palomafp.aadd.inm.exception.MapaMundiException;
import es.palomafp.aadd.inm.vo.Pais;
/**
*
* IPaisDAO: Interfaz que contiene las operaciones a realizar sobre un país
*
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
* @date 2 oct 2025
*/
public interface IPaisDAO {
List<Pais> obtenerListaPaises(String codigoContinente) throws MapaMundiException;
}

View File

@ -0,0 +1,60 @@
package es.palomafp.aadd.inm.dao.impl;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import es.palomafp.aadd.inm.config.GestorConfiguracion;
import es.palomafp.aadd.inm.dao.IContinenteDAO;
import es.palomafp.aadd.inm.exception.MapaMundiException;
import es.palomafp.aadd.inm.vo.Continente;
/**
*
* ContinenteDaoCSV: Clase que implementa las operaciones del interfaz IPaisDAO
*
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
* @date 2 oct 2025
*/
public class ContinenteDaoCSV implements IContinenteDAO {
private final static String RUTA_FICHERO_CONTINENTES = GestorConfiguracion.getValorfromClave("continente.fichero.ruta");
private final static String SEPARADOR_CONTINENTES = GestorConfiguracion.getValorfromClave("continente.separador");
private File fichero = new File(RUTA_FICHERO_CONTINENTES);
@Override
public Continente obtenerContinente(String codigoContinente) throws MapaMundiException {
Continente continente = null;
try (BufferedReader bf = new BufferedReader(new FileReader(fichero))) {
String linea;
bf.readLine(); // Saltamos la línea de cabecera.
while ((linea = bf.readLine()) != null) {
// Procesar información del Continente
String[] camposContinente = linea.split(SEPARADOR_CONTINENTES);
String codContinente = camposContinente[0].trim().replace("\"", "");
String nombreContinente = camposContinente[1].trim().replace("\"", "");
if (codigoContinente != null && codigoContinente.equals(codContinente)) {
// Se crea objeto continente cuando coincide con el código
continente = new Continente();
continente.setCodigo(codigoContinente);
continente.setNombre(nombreContinente);
}
}
} catch (
FileNotFoundException e) {
System.err.println("Fichero no encontrado: " + RUTA_FICHERO_CONTINENTES);
throw new MapaMundiException(e, MapaMundiException.ERROR_BUSQUEDA, getClass());
} catch (IOException e) {
System.err.println("Error al leer el fichero: " + RUTA_FICHERO_CONTINENTES);
throw new MapaMundiException(e, MapaMundiException.ERROR_BUSQUEDA, getClass());
}
return continente;
}
}

View File

@ -0,0 +1,77 @@
package es.palomafp.aadd.inm.dao.impl;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import es.palomafp.aadd.inm.config.GestorConfiguracion;
import es.palomafp.aadd.inm.dao.IContinenteDAO;
import es.palomafp.aadd.inm.dao.IPaisDAO;
import es.palomafp.aadd.inm.exception.MapaMundiException;
import es.palomafp.aadd.inm.vo.Continente;
import es.palomafp.aadd.inm.vo.Pais;
/**
*
* PaisDaoTXT: Clase que implementa las operaciones del interfaz IPaisDAO
*
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
* @date 2 oct 2025
*/
public class PaisDaoTXT implements IPaisDAO {
private final static String RUTA_FICHERO_PAISES = GestorConfiguracion.getValorfromClave("pais.fichero.ruta");
private final static String SEPARADOR_PAISES = GestorConfiguracion.getValorfromClave("pais.separador");
private File fichero = new File(RUTA_FICHERO_PAISES);
@Override
public List<Pais> obtenerListaPaises(String codigoContinente) throws MapaMundiException{
List<Pais> listaPaises = null;
try (BufferedReader bf = new BufferedReader(new FileReader(fichero))) {
String linea;
listaPaises = new ArrayList<Pais>();
Continente continente = null;
while ((linea = bf.readLine()) != null) {
// Procesa las líneas que NO empeiecen por '--' ni por '#'
if (!(linea.startsWith("--") || linea.startsWith("#"))) {
// Procesar información del País
String[] camposPais = linea.split(SEPARADOR_PAISES);
String codContinente = camposPais[0].trim().replace("\"", "");
String identificador = camposPais[1].trim();
String nombrePais = camposPais[2].trim().replace("\"", "");
String capital = camposPais[3].trim().replace("\"", "");
if (codigoContinente.equals(codContinente)) {
if (continente == null) {
IContinenteDAO iContinenteDAO = new ContinenteDaoCSV();
continente = iContinenteDAO.obtenerContinente(codigoContinente);
}
Pais pais = new Pais();
pais.setIdentificador(Integer.parseInt(identificador));
pais.setNombre(nombrePais);
pais.setCapital(capital);
pais.setContinente(continente);
listaPaises.add(pais);
}
}
}
} catch (FileNotFoundException e) {
System.err.println("Fichero no encontrado: " + RUTA_FICHERO_PAISES);
throw new MapaMundiException(e, MapaMundiException.ERROR_BUSQUEDA, getClass());
} catch (IOException e) {
System.err.println("Error al leer el fichero: " + RUTA_FICHERO_PAISES);
throw new MapaMundiException(e, MapaMundiException.ERROR_BUSQUEDA, getClass());
}
return listaPaises;
}
}

View File

@ -0,0 +1,52 @@
package es.palomafp.aadd.inm.exception;
/**
*
* MapaMundiException: Clase que representa una excepción personalizada para la aplicación MapaMundi.
*
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
* @date 2 oct 2025
*/
public class MapaMundiException extends Exception {
private static final long serialVersionUID = 1L;
public static final long ERROR_BUSQUEDA = 0;
public static final long ERROR_CREACION = 1;
public static final long ERROR_ACTUALIZACION = 2;
public static final long ERROR_ELIMINACION = 3;
public static final long ERROR_OTRO = 4;
private long codigoError;
private String nombreClase;
@SuppressWarnings("rawtypes")
public MapaMundiException(Exception excepcion, long tipoError, Class clase) {
super(excepcion);
this.codigoError = tipoError;
this.nombreClase = clase.getName();
}
public long getCodigoError() {
return codigoError;
}
public void setCodigoError(long codigoError) {
this.codigoError = codigoError;
}
public String getNombreClase() {
return nombreClase;
}
public void setNombreClase(String nombreClase) {
this.nombreClase = nombreClase;
}
}

View File

@ -0,0 +1,35 @@
package es.palomafp.aadd.inm.vo;
/**
* Continente: Clase que se encarga de almacenar información de un Continente.
*
* @author: Isidoro Nevares Martín (IES Virgen de la Paloma)
* @date: 2 oct 2025
*/
public class Continente {
private String codigo;
private String nombre;
@Override
public String toString() {
return "Continente [codigo=" + codigo + ", 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;
}
}

View File

@ -0,0 +1,52 @@
package es.palomafp.aadd.inm.vo;
/**
* Pais: Clase que se encarga de almacenar información de un País.
*
* @author: Isidoro Nevares Martín (IES Virgen de la Paloma)
* @date: 2 oct 2025
*/
public class Pais {
private int identificador;
private String nombre;
private String capital;
private 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() {
return "Pais [identificador=" + identificador + ", nombre=" + nombre + ", capital=" + capital + ", continente="
+ continente + "]\n";
}
}