Actividad 5
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-25">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Ficheros_05</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>
|
||||||
|
<filteredResources>
|
||||||
|
<filter>
|
||||||
|
<id>1790934355813</id>
|
||||||
|
<name></name>
|
||||||
|
<type>30</type>
|
||||||
|
<matcher>
|
||||||
|
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||||
|
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||||
|
</matcher>
|
||||||
|
</filter>
|
||||||
|
</filteredResources>
|
||||||
|
</projectDescription>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=25
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=25
|
||||||
|
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.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=25
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,13 @@
|
|||||||
|
package org.palomafp.aadd.aez.dao;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.aez.model.Continente;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface ContinenteDAO {
|
||||||
|
List<Continente> obtenerTodos();
|
||||||
|
|
||||||
|
Map<String, Continente> obtenerTodosComoMapa();
|
||||||
|
|
||||||
|
Continente obtenerPorCodigo(String codigo);
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package org.palomafp.aadd.aez.dao;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.aez.model.Continente;
|
||||||
|
import org.palomafp.aadd.aez.model.Pais;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface PaisDAO {
|
||||||
|
List<Pais> obtenerTodos(Map<String, Continente> mapaContinentes);
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package org.palomafp.aadd.aez.dao.impl;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.aez.dao.ContinenteDAO;
|
||||||
|
import org.palomafp.aadd.aez.model.Continente;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ContinenteDAOImpl implements ContinenteDAO {
|
||||||
|
|
||||||
|
private static final String RUTA_DEFECTO = "C:\\Users\\aleja\\aadd\\fic05\\informacion_continentes.csv";
|
||||||
|
private final String rutaFichero;
|
||||||
|
|
||||||
|
public ContinenteDAOImpl() {
|
||||||
|
this.rutaFichero = RUTA_DEFECTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContinenteDAOImpl(String rutaFichero) {
|
||||||
|
this.rutaFichero = rutaFichero;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Continente> obtenerTodos() {
|
||||||
|
List<Continente> continentes = new ArrayList<>();
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(rutaFichero, StandardCharsets.UTF_8))) {
|
||||||
|
String linea;
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
if (linea.trim().isEmpty() || linea.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String[] datos = linea.split("[,;]");
|
||||||
|
if (datos.length >= 2) {
|
||||||
|
String codigo = datos[0].trim();
|
||||||
|
String nombre = datos[1].trim();
|
||||||
|
continentes.add(new Continente(codigo, nombre));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err
|
||||||
|
.println("Error al leer el fichero CSV de continentes en (" + rutaFichero + "): " + e.getMessage());
|
||||||
|
}
|
||||||
|
return continentes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Continente> obtenerTodosComoMapa() {
|
||||||
|
Map<String, Continente> mapa = new HashMap<>();
|
||||||
|
for (Continente c : obtenerTodos()) {
|
||||||
|
mapa.put(c.getCodigo(), c);
|
||||||
|
}
|
||||||
|
return mapa;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Continente obtenerPorCodigo(String codigo) {
|
||||||
|
return obtenerTodosComoMapa().get(codigo);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package org.palomafp.aadd.aez.dao.impl;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.aez.dao.PaisDAO;
|
||||||
|
import org.palomafp.aadd.aez.model.Continente;
|
||||||
|
import org.palomafp.aadd.aez.model.Pais;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PaisDAOImpl implements PaisDAO {
|
||||||
|
|
||||||
|
private static final String RUTA_DEFECTO = "C:\\Users\\aleja\\aadd\\fic05\\informacion_paises.txt";
|
||||||
|
private final String rutaFichero;
|
||||||
|
|
||||||
|
public PaisDAOImpl() {
|
||||||
|
this.rutaFichero = RUTA_DEFECTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PaisDAOImpl(String rutaFichero) {
|
||||||
|
this.rutaFichero = rutaFichero;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pais> obtenerTodos(Map<String, Continente> mapaContinentes) {
|
||||||
|
List<Pais> paises = new ArrayList<>();
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(rutaFichero, StandardCharsets.UTF_8))) {
|
||||||
|
String linea;
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
if (linea.trim().isEmpty() || linea.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String[] datos = linea.split("[,;\t]");
|
||||||
|
if (datos.length >= 4) {
|
||||||
|
// Eliminar comillas dobles y espacios sobrantes de cada campo
|
||||||
|
String idStr = datos[0].trim().replace("\"", "");
|
||||||
|
String nombre = datos[1].trim().replace("\"", "");
|
||||||
|
String capital = datos[2].trim().replace("\"", "");
|
||||||
|
String codContinente = datos[3].trim().replace("\"", "");
|
||||||
|
|
||||||
|
int id = Integer.parseInt(idStr);
|
||||||
|
Continente continente = mapaContinentes.get(codContinente);
|
||||||
|
paises.add(new Pais(id, nombre, capital, continente));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException | NumberFormatException e) {
|
||||||
|
System.err.println("Error al leer el fichero TXT de países en (" + rutaFichero + "): " + e.getMessage());
|
||||||
|
}
|
||||||
|
return paises;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package org.palomafp.aadd.aez.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 nombre + " (" + codigo + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package org.palomafp.aadd.aez.model;
|
||||||
|
|
||||||
|
public class Pais {
|
||||||
|
private int identificador;
|
||||||
|
private String nombre;
|
||||||
|
private String nombreCapital;
|
||||||
|
private Continente continente;
|
||||||
|
|
||||||
|
public Pais() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pais(int identificador, String nombre, String nombreCapital, Continente continente) {
|
||||||
|
super();
|
||||||
|
this.identificador = identificador;
|
||||||
|
this.nombre = nombre;
|
||||||
|
this.nombreCapital = nombreCapital;
|
||||||
|
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 getNombreCapital() {
|
||||||
|
return nombreCapital;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombreCapital(String nombreCapital) {
|
||||||
|
this.nombreCapital = nombreCapital;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Continente getContinente() {
|
||||||
|
return continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContinente(Continente continente) {
|
||||||
|
this.continente = continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String nombreContinente = "Desconocido";
|
||||||
|
String codigoContinente = "XX";
|
||||||
|
|
||||||
|
if (this.continente != null) {
|
||||||
|
nombreContinente = this.continente.getNombre();
|
||||||
|
codigoContinente = this.continente.getCodigo();
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.format("%s (%d) con capital en %s pertenece al continente %s (%s)", nombre, identificador,
|
||||||
|
nombreCapital, nombreContinente, codigoContinente);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package org.palomafp.aadd.dao;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.aez.dao.ContinenteDAO;
|
||||||
|
import org.palomafp.aadd.aez.dao.PaisDAO;
|
||||||
|
import org.palomafp.aadd.aez.dao.impl.ContinenteDAOImpl;
|
||||||
|
import org.palomafp.aadd.aez.dao.impl.PaisDAOImpl;
|
||||||
|
import org.palomafp.aadd.aez.model.Continente;
|
||||||
|
import org.palomafp.aadd.aez.model.Pais;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Instanciación limpia sin parámetros, utilizando las rutas por defecto en
|
||||||
|
// C:\Users\aleja\aadd\fic05
|
||||||
|
ContinenteDAO continenteDAO = new ContinenteDAOImpl();
|
||||||
|
PaisDAO paisDAO = new PaisDAOImpl();
|
||||||
|
|
||||||
|
// Cargar mapa de continentes
|
||||||
|
Map<String, Continente> mapContinentes = continenteDAO.obtenerTodosComoMapa();
|
||||||
|
|
||||||
|
// Cargar lista de países asociados a sus continentes
|
||||||
|
List<Pais> listaPaises = paisDAO.obtenerTodos(mapContinentes);
|
||||||
|
|
||||||
|
// Imprimir formateado por consola
|
||||||
|
for (Pais pais : listaPaises) {
|
||||||
|
System.out.println(pais.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user