Primero
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
package org.palomafp.dam2.aadd.anp.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.dam2.aadd.anp.model.Continente;
|
||||||
|
|
||||||
|
public interface IContinenteDAO {
|
||||||
|
|
||||||
|
Continente obtenerContinente(String codigoContinente);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package org.palomafp.dam2.aadd.anp.dao.impl;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.palomafp.dam2.aadd.anp.dao.IContinenteDAO;
|
||||||
|
import org.palomafp.dam2.aadd.anp.model.Continente;
|
||||||
|
|
||||||
|
public class ContinenteDaoCsv implements IContinenteDAO {
|
||||||
|
|
||||||
|
private static final String FICHERO = "C:\\Users\\PC GAMING\\aadd\\fic05\\informacion_continentes.csv";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Continente obtenerContinente(String codigoContinente) {
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(FICHERO))) {
|
||||||
|
|
||||||
|
br.readLine();
|
||||||
|
|
||||||
|
String linea;
|
||||||
|
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
|
||||||
|
String[] datos = linea.split("#");
|
||||||
|
|
||||||
|
String codigo = datos[1].trim();
|
||||||
|
String nombre = datos[2].trim();
|
||||||
|
|
||||||
|
if (codigo.equals(codigoContinente)) {
|
||||||
|
return new Continente(codigo, nombre);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,9 +8,9 @@ import org.palomafp.dam2.aadd.anp.model.*;
|
|||||||
|
|
||||||
public class PaisDaoText implements IPaisDAO {
|
public class PaisDaoText implements IPaisDAO {
|
||||||
|
|
||||||
private static final String ruta = "C:\\Users\\PC GAMING\\aadd\\fic03\\informacion_paises.txt";
|
private static final String ruta =
|
||||||
|
"C:\\Users\\PC GAMING\\aadd\\fic05\\informacion_paises.txt";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pais obtenerPais(int identificadorPais) {
|
public Pais obtenerPais(int identificadorPais) {
|
||||||
|
|
||||||
@@ -45,8 +45,6 @@ public class PaisDaoText implements IPaisDAO {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Pais> obtenerPaisesPorContinente(
|
public List<Pais> obtenerPaisesPorContinente(
|
||||||
String codigoContinente) {
|
String codigoContinente) {
|
||||||
@@ -87,8 +85,6 @@ public class PaisDaoText implements IPaisDAO {
|
|||||||
return paises;
|
return paises;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Pais convertirLineaAPais(String linea) {
|
private Pais convertirLineaAPais(String linea) {
|
||||||
|
|
||||||
linea = linea.replace("\"", "");
|
linea = linea.replace("\"", "");
|
||||||
@@ -103,8 +99,11 @@ public class PaisDaoText implements IPaisDAO {
|
|||||||
|
|
||||||
String capital = datos[3].trim();
|
String capital = datos[3].trim();
|
||||||
|
|
||||||
|
// DAO encargado de obtener los datos del continente
|
||||||
|
IContinenteDAO continenteDAO = new ContinenteDaoCsv();
|
||||||
|
|
||||||
Continente continente =
|
Continente continente =
|
||||||
new Continente(codigoContinente, nombre);
|
continenteDAO.obtenerContinente(codigoContinente);
|
||||||
|
|
||||||
return new Pais(
|
return new Pais(
|
||||||
id,
|
id,
|
||||||
@@ -113,4 +112,4 @@ public class PaisDaoText implements IPaisDAO {
|
|||||||
continente
|
continente
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,10 @@ public class Continente {
|
|||||||
this.codigoContinente = codigoContinente;
|
this.codigoContinente = codigoContinente;
|
||||||
this.nombre = nombre;
|
this.nombre = nombre;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Continente() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public String getCodigoContinente() {
|
public String getCodigoContinente() {
|
||||||
return codigoContinente;
|
return codigoContinente;
|
||||||
|
|||||||
@@ -51,12 +51,9 @@ public class Pais {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Pais{" +
|
return nombre + " (" + id + "), con capital en " + capital
|
||||||
"id=" + id +
|
+ " pertenece a " + continente.getNombre()
|
||||||
", nombre = '" + nombre + '\'' +
|
+ " (" + continente.getCodigoContinente() + ")";
|
||||||
", capital = '" + capital + '\'' + "," +
|
|
||||||
continente +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user