Primer_Fichero_05
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
bin/
|
||||||
|
.settings/
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package org.palomafp.aadd.ss;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.palomafp.aadd.ss.model.Pais;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.ss.dao.*;
|
||||||
|
import org.palomafp.aadd.ss.dao.impl.PaisDaoFichero;
|
||||||
|
|
||||||
|
public class GestorMapaMundi {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Pais pais = obtenerPaisesPorIdentificador(105);
|
||||||
|
System.out.println("Paises enconrado:");
|
||||||
|
System.out.println(pais);
|
||||||
|
|
||||||
|
System.out.println("==================================================================================");
|
||||||
|
|
||||||
|
List<Pais> listaPaises = obtnerPaisesPorCOntinente("04");
|
||||||
|
System.out.println("Paises del continente 04: ");
|
||||||
|
for(Pais p : listaPaises) {
|
||||||
|
System.out.println(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static Pais obtenerPaisesPorIdentificador(int identificador) {
|
||||||
|
|
||||||
|
IPaisDAO paisDAO = new PaisDaoFichero();
|
||||||
|
Pais pais = paisDAO.obtenerPaisPorIdentificador(identificador);
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static List<Pais> obtnerPaisesPorCOntinente(String codigoContinente){
|
||||||
|
IPaisDAO paisDAO = new PaisDaoFichero();
|
||||||
|
List<Pais> listaPaises = paisDAO.obtenerPaisesPorContinente(codigoContinente);
|
||||||
|
return listaPaises;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
System.out.println("Paises enconrado:");
|
||||||
|
System.out.println(pais);
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
System.out.println("Paises del continente 04: ");
|
||||||
|
|
||||||
|
for(Pais p : listaPaises) {
|
||||||
|
System.out.println(p);
|
||||||
|
}**/
|
||||||
|
//Pais pais = new Pais();
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package org.palomafp.aadd.ss.dao;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.ss.model.Continente;
|
||||||
|
|
||||||
|
public interface IContinenteDAO {
|
||||||
|
|
||||||
|
Continente obtenerContinentePorCodContinente(String codContinente);
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.palomafp.aadd.ss.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.ss.model.Pais;
|
||||||
|
|
||||||
|
public interface IPaisDAO {
|
||||||
|
|
||||||
|
Pais obtenerPaisPorIdentificador(int idPais);
|
||||||
|
List<Pais> obtenerPaisesPorContinente(String codContinente);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package org.palomafp.aadd.ss.dao.impl;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.ss.dao.IContinenteDAO;
|
||||||
|
import org.palomafp.aadd.ss.model.Continente;
|
||||||
|
|
||||||
|
public class ContinenteDaoFichero implements IContinenteDAO{
|
||||||
|
|
||||||
|
String ruta = "C:\\Users\\sajed\\Desktop\\2DAM\\AADD\\aadd\\fic04\\informacion_continentes.csv";
|
||||||
|
// File infoContinente = new File(ruta);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Continente obtenerContinentePorCodContinente(String codContinente) {
|
||||||
|
Continente continente = null;
|
||||||
|
try {
|
||||||
|
BufferedReader br = new BufferedReader(new FileReader(ruta));
|
||||||
|
|
||||||
|
String linea;
|
||||||
|
while((linea = br.readLine()) != null) {
|
||||||
|
if(linea.startsWith("#") || linea.isEmpty() || linea.startsWith("anyo")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
linea = linea.replace("\"", "");
|
||||||
|
|
||||||
|
String[] datos = linea.split("#");
|
||||||
|
|
||||||
|
String codigo = datos[1].trim();
|
||||||
|
String nombre = datos[2].trim();
|
||||||
|
|
||||||
|
if (codigo.equals(codContinente.trim())) {
|
||||||
|
continente = new Continente(codigo, nombre);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package org.palomafp.aadd.ss.dao.impl;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.ss.dao.IContinenteDAO;
|
||||||
|
import org.palomafp.aadd.ss.dao.IPaisDAO;
|
||||||
|
import org.palomafp.aadd.ss.model.Continente;
|
||||||
|
import org.palomafp.aadd.ss.model.Pais;
|
||||||
|
|
||||||
|
public class PaisDaoFichero implements IPaisDAO {
|
||||||
|
|
||||||
|
String ruta = "C:\\Users\\sajed\\Desktop\\2DAM\\AADD\\aadd\\fic04\\informacion_paises (3).txt";
|
||||||
|
File paises = new File(ruta);
|
||||||
|
|
||||||
|
public IContinenteDAO continenteDAO = new ContinenteDaoFichero();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pais obtenerPaisPorIdentificador(int idPais) {
|
||||||
|
Pais pais = null;
|
||||||
|
try {
|
||||||
|
BufferedReader br = new BufferedReader(new FileReader(paises));
|
||||||
|
|
||||||
|
String linea;
|
||||||
|
while((linea = br.readLine()) != null) {
|
||||||
|
if (linea.isEmpty() || linea.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
linea = linea.replace("\"", "");
|
||||||
|
String[] datos = linea.split(",");
|
||||||
|
|
||||||
|
String codigoContinente = datos[0].trim();
|
||||||
|
int idpais = Integer.parseInt(datos[1].trim());
|
||||||
|
String nombre = datos[2].trim();
|
||||||
|
String capital = datos[3].trim();
|
||||||
|
|
||||||
|
if (idpais == idPais) {
|
||||||
|
pais = new Pais();
|
||||||
|
pais.setIdentificador(idpais);
|
||||||
|
pais.setNombre(nombre);
|
||||||
|
pais.setCapital(capital);
|
||||||
|
|
||||||
|
Continente continente = continenteDAO.obtenerContinentePorCodContinente(codigoContinente);
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pais> obtenerPaisesPorContinente(String codContinente) {
|
||||||
|
|
||||||
|
List<Pais> listaPaises =new ArrayList<>();
|
||||||
|
Pais pais = null;
|
||||||
|
Continente continente = null;
|
||||||
|
try {
|
||||||
|
BufferedReader br = new BufferedReader(new FileReader(ruta));
|
||||||
|
|
||||||
|
String linea;
|
||||||
|
while((linea = br.readLine()) != null) {
|
||||||
|
if (linea.isEmpty() || linea.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
linea = linea.replace("\"", "");
|
||||||
|
String[] datos = linea.split(",");
|
||||||
|
|
||||||
|
String codigo = datos[0].trim();
|
||||||
|
int identificador = Integer.parseInt(datos[1].trim());
|
||||||
|
String nombre = datos[2].trim();
|
||||||
|
String capital = datos[3].trim();
|
||||||
|
|
||||||
|
if(codigo.equals(codContinente)) {
|
||||||
|
pais = new Pais();
|
||||||
|
pais.setIdentificador(identificador);
|
||||||
|
pais.setNombre(nombre);
|
||||||
|
pais.setCapital(capital);
|
||||||
|
|
||||||
|
continente = continenteDAO.obtenerContinentePorCodContinente(codigo);
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
listaPaises.add(pais);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return listaPaises;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package org.palomafp.aadd.ss.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 "Continente [codigo=" + codigo
|
||||||
|
+ ", nombre=" + nombre + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package org.palomafp.aadd.ss.model;
|
||||||
|
|
||||||
|
public class Pais {
|
||||||
|
|
||||||
|
private int identificador;
|
||||||
|
private String nombre;
|
||||||
|
private String capital;
|
||||||
|
private Continente continente; // Relación con Continente
|
||||||
|
|
||||||
|
public Pais() {
|
||||||
|
}
|
||||||
|
|
||||||
|
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 getCapital() {
|
||||||
|
return capital;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCapital(String capital) {
|
||||||
|
this.capital = capital;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Continente getContinente() {
|
||||||
|
return continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContinente(Continente continente) {
|
||||||
|
this.continente = continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return nombre + "(" + identificador + ") con capital en "
|
||||||
|
+ capital + " partenece sl continente " + continente.getNombre()
|
||||||
|
+ "(" + continente.getCodigo() + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user