Primer Commit
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
bin/
|
||||
.settings/
|
||||
.classpath
|
||||
.project
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.palomafp.aadd.aqv;
|
||||
|
||||
import java.util.List;
|
||||
import org.palomafp.aadd.aqv.dao.IPaisDAO;
|
||||
import org.palomafp.aadd.aqv.dao.impl.PaisDAOImpl;
|
||||
import org.palomafp.aadd.aqv.model.Pais;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
IPaisDAO paisDAO = new PaisDAOImpl();
|
||||
|
||||
List<Pais> listaPaises = paisDAO.obtenerTodos();
|
||||
|
||||
for (Pais pais : listaPaises) {
|
||||
System.out.println(pais.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.palomafp.aadd.aqv.dao;
|
||||
|
||||
import java.util.List;
|
||||
import org.palomafp.aadd.aqv.model.Continente;
|
||||
|
||||
public interface IContinenteDAO {
|
||||
List<Continente> obtenerTodos();
|
||||
|
||||
Continente obtenerPorCodigo(String codigo);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.palomafp.aadd.aqv.dao;
|
||||
|
||||
import java.util.List;
|
||||
import org.palomafp.aadd.aqv.model.Pais;
|
||||
|
||||
public interface IPaisDAO {
|
||||
|
||||
List<Pais> obtenerTodos();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.palomafp.aadd.aqv.dao.impl;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.palomafp.aadd.aqv.dao.IContinenteDAO;
|
||||
import org.palomafp.aadd.aqv.model.Continente;
|
||||
|
||||
public class ContinenteDAOImpl implements IContinenteDAO {
|
||||
private static final String RUTA_FICHERO = "C:\\Users\\aadd\\fic05\\informacion_paises.txt";
|
||||
|
||||
@Override
|
||||
public List<Continente> obtenerTodos() {
|
||||
List<Continente> continentes = new ArrayList<>();
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(RUTA_FICHERO))) {
|
||||
String linea;
|
||||
while ((linea = br.readLine()) != null) {
|
||||
if (linea.trim().isEmpty() || linea.startsWith("#"))
|
||||
continue;
|
||||
|
||||
String[] partes = linea.split(",");
|
||||
String codigo = partes[0].replace("\"", "").trim();
|
||||
String nombre = partes[1].replace("\"", "").trim();
|
||||
|
||||
continentes.add(new Continente(codigo, nombre));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error al leer continentes: " + e.getMessage());
|
||||
}
|
||||
return continentes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Continente obtenerPorCodigo(String codigo) {
|
||||
for (Continente c : obtenerTodos()) {
|
||||
if (c.getCodigo().equals(codigo)) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.palomafp.aadd.aqv.dao.impl;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.palomafp.aadd.aqv.dao.IContinenteDAO;
|
||||
import org.palomafp.aadd.aqv.dao.IPaisDAO;
|
||||
import org.palomafp.aadd.aqv.model.Continente;
|
||||
import org.palomafp.aadd.aqv.model.Pais;
|
||||
|
||||
public class PaisDAOImpl implements IPaisDAO {
|
||||
private static final String RUTA_FICHERO = "C:\\Users\\aadd\\fic05\\informacion_paises.txt";
|
||||
private IContinenteDAO continenteDAO;
|
||||
|
||||
public PaisDAOImpl() {
|
||||
this.continenteDAO = new ContinenteDAOImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pais> obtenerTodos() {
|
||||
List<Pais> paises = new ArrayList<>();
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(RUTA_FICHERO))) {
|
||||
String linea;
|
||||
while ((linea = br.readLine()) != null) {
|
||||
if (linea.trim().isEmpty() || linea.startsWith("#"))
|
||||
continue;
|
||||
|
||||
String[] partes = linea.split(",");
|
||||
String codigoContinente = partes[0].replace("\"", "").trim();
|
||||
int id = Integer.parseInt(partes[1].trim());
|
||||
String nombre = partes[2].replace("\"", "").trim();
|
||||
String capital = partes[3].replace("\"", "").trim();
|
||||
|
||||
Continente continente = continenteDAO.obtenerPorCodigo(codigoContinente);
|
||||
|
||||
paises.add(new Pais(id, nombre, capital, continente));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error al leer países: " + e.getMessage());
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("Error al parsear el identificador: " + e.getMessage());
|
||||
}
|
||||
return paises;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.palomafp.aadd.aqv.model;
|
||||
|
||||
public class Continente {
|
||||
private String codigo;
|
||||
private String nombre;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.palomafp.aadd.aqv.model;
|
||||
|
||||
public class Pais {
|
||||
private int identificador;
|
||||
private String nombre;
|
||||
private String nombreCapital;
|
||||
private Continente continente;
|
||||
|
||||
public Pais(int identificador, String nombre, String nombreCapital, Continente continente) {
|
||||
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() {
|
||||
return nombre + " (" + identificador + "), con capital en " + nombreCapital + " pertenece a "
|
||||
+ continente.getNombre() + " (" + continente.getCodigo() + ")";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user