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 {
|
||||
|
||||
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
|
||||
public Pais obtenerPais(int identificadorPais) {
|
||||
|
||||
@@ -45,8 +45,6 @@ public class PaisDaoText implements IPaisDAO {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<Pais> obtenerPaisesPorContinente(
|
||||
String codigoContinente) {
|
||||
@@ -87,8 +85,6 @@ public class PaisDaoText implements IPaisDAO {
|
||||
return paises;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Pais convertirLineaAPais(String linea) {
|
||||
|
||||
linea = linea.replace("\"", "");
|
||||
@@ -103,8 +99,11 @@ public class PaisDaoText implements IPaisDAO {
|
||||
|
||||
String capital = datos[3].trim();
|
||||
|
||||
// DAO encargado de obtener los datos del continente
|
||||
IContinenteDAO continenteDAO = new ContinenteDaoCsv();
|
||||
|
||||
Continente continente =
|
||||
new Continente(codigoContinente, nombre);
|
||||
continenteDAO.obtenerContinente(codigoContinente);
|
||||
|
||||
return new Pais(
|
||||
id,
|
||||
@@ -113,4 +112,4 @@ public class PaisDaoText implements IPaisDAO {
|
||||
continente
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user