@@ -1,11 +0,0 @@
|
|||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
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,8 +8,8 @@ import org.palomafp.dam2.aadd.anp.model.*;
|
|||||||
|
|
||||||
public class PaisDaoText implements IPaisDAO {
|
public class PaisDaoText implements IPaisDAO {
|
||||||
|
|
||||||
private static final String ruta =
|
private static final String ruta = "C:\\Users\\PC GAMING\\aadd\\fic03\\informacion_paises.txt";
|
||||||
"C:\\Users\\PC GAMING\\aadd\\fic05\\informacion_paises.txt";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pais obtenerPais(int identificadorPais) {
|
public Pais obtenerPais(int identificadorPais) {
|
||||||
@@ -45,6 +45,8 @@ public class PaisDaoText implements IPaisDAO {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Pais> obtenerPaisesPorContinente(
|
public List<Pais> obtenerPaisesPorContinente(
|
||||||
String codigoContinente) {
|
String codigoContinente) {
|
||||||
@@ -85,6 +87,8 @@ 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("\"", "");
|
||||||
@@ -99,11 +103,8 @@ 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 =
|
||||||
continenteDAO.obtenerContinente(codigoContinente);
|
new Continente(codigoContinente, nombre);
|
||||||
|
|
||||||
return new Pais(
|
return new Pais(
|
||||||
id,
|
id,
|
||||||
|
|||||||
@@ -10,10 +10,6 @@ public class Continente {
|
|||||||
this.nombre = nombre;
|
this.nombre = nombre;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Continente() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCodigoContinente() {
|
public String getCodigoContinente() {
|
||||||
return codigoContinente;
|
return codigoContinente;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,9 +51,12 @@ public class Pais {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return nombre + " (" + id + "), con capital en " + capital
|
return "Pais{" +
|
||||||
+ " pertenece a " + continente.getNombre()
|
"id=" + id +
|
||||||
+ " (" + continente.getCodigoContinente() + ")";
|
", nombre = '" + nombre + '\'' +
|
||||||
|
", capital = '" + capital + '\'' + "," +
|
||||||
|
continente +
|
||||||
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user