Primer commit
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
# Eclipse
|
||||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
|
||||
# Compilación Java
|
||||
bin/
|
||||
target/
|
||||
*.class
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
# Sistema operativo
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
@@ -0,0 +1,69 @@
|
||||
package org.palomafp.aadd.inm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.palomafp.aadd.inm.dao.IContinenteDAO;
|
||||
import org.palomafp.aadd.inm.dao.IPaisDAO;
|
||||
import org.palomafp.aadd.inm.dao.impl.ContinenteDaoCSV;
|
||||
import org.palomafp.aadd.inm.dao.impl.PaisDaoText;
|
||||
import org.palomafp.aadd.inm.model.Pais;
|
||||
|
||||
/**
|
||||
*
|
||||
* AppPrincipal: Clase que realiza el tratamiento de un fichero con información
|
||||
* de países usando patrón DAO.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 24 sept 2026
|
||||
*
|
||||
*/
|
||||
|
||||
public class GestorMapaMundi {
|
||||
|
||||
public static void main(String[] args) {
|
||||
GestorMapaMundi app = new GestorMapaMundi();
|
||||
|
||||
int identificadorPais = 105;
|
||||
Pais pais = app.obtenerPaisPorIdentificador(identificadorPais);
|
||||
|
||||
// Imprimir la información del país en la consola.
|
||||
System.out.println(textoAImprimir(pais));
|
||||
|
||||
System.out.println("----------------------------------------------------");
|
||||
|
||||
String codigoContinente = "04";
|
||||
List<Pais> listaPaises = app.obtenerListaPaisesPorContinente(codigoContinente);
|
||||
// Imprimir la información de los paises en la consola.
|
||||
if (listaPaises != null) {
|
||||
for (Pais pais2 : listaPaises) {
|
||||
System.out.println(textoAImprimir(pais2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Pais obtenerPaisPorIdentificador(int identificador) {
|
||||
Pais pais = null;
|
||||
|
||||
IContinenteDAO continenteDAO = new ContinenteDaoCSV();
|
||||
IPaisDAO paisDAO = new PaisDaoText(continenteDAO);
|
||||
pais = paisDAO.obtenerPaisPorID(identificador);
|
||||
|
||||
return pais;
|
||||
}
|
||||
|
||||
private List<Pais> obtenerListaPaisesPorContinente(String codContinente) {
|
||||
List<Pais> listaPaises = null;
|
||||
|
||||
IContinenteDAO continenteDAO = new ContinenteDaoCSV();
|
||||
IPaisDAO paisDAO = new PaisDaoText(continenteDAO);
|
||||
listaPaises = paisDAO.obtenerPaisesPorContinente(codContinente);
|
||||
|
||||
return listaPaises;
|
||||
}
|
||||
|
||||
private static String textoAImprimir(Pais pais) {
|
||||
String texto = String.format("%s (%s), con capital en %s pertenece a %s", pais.getNombre(), pais.getIdentificador(), pais.getCapital(),
|
||||
pais.getContinente().getNombre(), pais.getContinente().getCodigo());
|
||||
return texto;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.palomafp.aadd.inm.dao;
|
||||
|
||||
import org.palomafp.aadd.inm.model.Continente;
|
||||
|
||||
/**
|
||||
*
|
||||
* IPaisDAO: Interfaz que contiene los métodos para obtener información de continentes desde un origen de datos.
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 26 sept 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public interface IContinenteDAO {
|
||||
Continente obtenerContinentePorCodigo(String codigoContinente);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.palomafp.aadd.inm.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.palomafp.aadd.inm.model.Pais;
|
||||
|
||||
/**
|
||||
*
|
||||
* IPaisDAO: Interfaz que contiene los métodos para obtener información de países desde un origen de datos.
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 26 sept 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public interface IPaisDAO {
|
||||
Pais obtenerPaisPorID(int identificador);
|
||||
|
||||
List<Pais> obtenerPaisesPorContinente(String codContinente);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.palomafp.aadd.inm.dao.impl;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.palomafp.aadd.inm.dao.IContinenteDAO;
|
||||
import org.palomafp.aadd.inm.model.Continente;
|
||||
|
||||
/**
|
||||
*
|
||||
* PaisDaoText: Clase que realiza la implementación de la interfaz IContinenteDAO para
|
||||
* obtener información de continentes desde un origen de datos basado en texto.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 26 sept 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class ContinenteDaoCSV implements IContinenteDAO {
|
||||
private static final String RUTA_FICHERO = "C:\\Users\\ineva\\INM\\tmp\\aadd\\fic05\\informacion_continentes.csv";
|
||||
|
||||
@Override
|
||||
public Continente obtenerContinentePorCodigo(String codigoContinente) {
|
||||
Continente continenteEncontrado = null;
|
||||
|
||||
File ficheroContinentes= new File(RUTA_FICHERO);
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(ficheroContinentes));) {
|
||||
|
||||
// Nos saltamos la primera línea que contiene los nombres de los campos.
|
||||
if (reader.ready()) {
|
||||
reader.readLine();
|
||||
}
|
||||
|
||||
while (reader.ready()) {
|
||||
String linea = reader.readLine();
|
||||
|
||||
String[] camposPais = linea.split("#");
|
||||
String codContinente = camposPais[1].trim().replace("\"", "");
|
||||
|
||||
// Comprobamos si el código de continente coincide con el que estamos
|
||||
// buscando.
|
||||
if (codContinente.equals(codigoContinente)) {
|
||||
String nombreContinente = camposPais[2].trim().replace("\"", "");
|
||||
|
||||
continenteEncontrado = new Continente();
|
||||
continenteEncontrado.setCodigo(codigoContinente);
|
||||
continenteEncontrado.setNombre(nombreContinente);
|
||||
|
||||
break; // Salimos del bucle ya que hemos encontrado el continente.
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println(e);;
|
||||
}
|
||||
|
||||
return continenteEncontrado;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package org.palomafp.aadd.inm.dao.impl;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.palomafp.aadd.inm.dao.IContinenteDAO;
|
||||
import org.palomafp.aadd.inm.dao.IPaisDAO;
|
||||
import org.palomafp.aadd.inm.model.Continente;
|
||||
import org.palomafp.aadd.inm.model.Pais;
|
||||
|
||||
/**
|
||||
*
|
||||
* PaisDaoText: Clase que realiza la implementación de la interfaz IPaisDAO para
|
||||
* obtener información de países desde un origen de datos basado en texto.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 26 sept 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class PaisDaoText implements IPaisDAO {
|
||||
private static final String RUTA_FICHERO = "C:\\Users\\ineva\\INM\\tmp\\aadd\\fic04\\informacion_paises.txt";
|
||||
private IContinenteDAO continenteDao;
|
||||
|
||||
public PaisDaoText(IContinenteDAO continenteDao) {
|
||||
this.continenteDao = (ContinenteDaoCSV) continenteDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pais obtenerPaisPorID(int identificador) {
|
||||
Pais paisEncontrado = null;
|
||||
|
||||
File ficheroPaises = new File(RUTA_FICHERO);
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(ficheroPaises));) {
|
||||
|
||||
while (reader.ready()) {
|
||||
String linea = reader.readLine();
|
||||
|
||||
// Nos saltamos las líneas que comienzan con el carácter #, que son comentarios.
|
||||
if (linea.trim().startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] camposPais = linea.split(",");
|
||||
|
||||
String idPais = camposPais[1].trim();
|
||||
// Comprobamos si el identificador del país coincide con el que estamos
|
||||
// buscando.
|
||||
if (Integer.parseInt(idPais) == identificador) {
|
||||
String codigoContinente = camposPais[0].trim().replace("\"", "");
|
||||
String nombrePais = camposPais[2].trim().replace("\"", "");
|
||||
String capitalPais = camposPais[3].trim().replace("\"", "");
|
||||
|
||||
paisEncontrado = obtenerPaisDeLinea(codigoContinente, Integer.parseInt(idPais), nombrePais, capitalPais);
|
||||
|
||||
break; // Salimos del bucle ya que hemos encontrado el país.
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println(e);;
|
||||
}
|
||||
|
||||
return paisEncontrado;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pais> obtenerPaisesPorContinente(String codContinente) {
|
||||
List<Pais> listaPaisesEncontrados = null;
|
||||
|
||||
File ficheroPaises = new File(RUTA_FICHERO);
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(ficheroPaises));) {
|
||||
|
||||
while (reader.ready()) {
|
||||
String linea = reader.readLine();
|
||||
|
||||
// Nos saltamos las líneas que comienzan con el carácter #, que son comentarios.
|
||||
if (linea.trim().startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] camposPais = linea.split(",");
|
||||
|
||||
String codigoContinente = camposPais[0].trim().replace("\"", "");
|
||||
if (codigoContinente.equals(codContinente)) {
|
||||
// La primera vez que entramos en este bloque, inicializamos la lista de países
|
||||
// encontrados.
|
||||
if (listaPaisesEncontrados == null) {
|
||||
listaPaisesEncontrados = new ArrayList<Pais>();
|
||||
}
|
||||
String idPais = camposPais[1].trim();
|
||||
String nombrePais = camposPais[2].trim().replace("\"", "");
|
||||
String capitalPais = camposPais[3].trim().replace("\"", "");
|
||||
|
||||
Pais pais = obtenerPaisDeLinea(codigoContinente, Integer.parseInt(idPais), nombrePais, capitalPais);
|
||||
|
||||
listaPaisesEncontrados.add(pais);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return listaPaisesEncontrados;
|
||||
}
|
||||
private Pais obtenerPaisDeLinea(String codigoContinente, int identificador, String nombrePais, String capitalPais) {
|
||||
// Obtenemos el objeto Continente a partir del código.
|
||||
Continente continente = continenteDao.obtenerContinentePorCodigo(codigoContinente);
|
||||
|
||||
Pais pais = new Pais();
|
||||
pais.setIdentificador(identificador);
|
||||
pais.setNombre(nombrePais);
|
||||
pais.setCapital(capitalPais);
|
||||
pais.setContinente(continente);
|
||||
|
||||
return pais;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.palomafp.aadd.inm.model;
|
||||
|
||||
/**
|
||||
*
|
||||
* Continente: Clase que se asocia a la información de un continente.
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 24 sept 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class Continente {
|
||||
private String codigo;
|
||||
private String 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 "Continente [codigo=" + codigo + ", nombre=" + nombre + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.palomafp.aadd.inm.model;
|
||||
|
||||
/**
|
||||
*
|
||||
* Pais Clase que se asocia a la información de un país.
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 24 sept 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
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 + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user