Primer commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
# Compilados de Java
|
||||||
|
*.class
|
||||||
|
bin/
|
||||||
|
|
||||||
|
# Configuración de Eclipse
|
||||||
|
.project
|
||||||
|
.classpath
|
||||||
|
.settings/
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package org.palomafp.aadd.smmb;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.smmb.dao.impl.PaisDaoFichero;
|
||||||
|
import org.palomafp.aadd.smmb.dao.IPaisDAO;
|
||||||
|
import org.palomafp.aadd.smmb.model.Pais;
|
||||||
|
|
||||||
|
public class GestorMapaMundi {
|
||||||
|
|
||||||
|
private IPaisDAO paisDao = new PaisDaoFichero();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
GestorMapaMundi app = new GestorMapaMundi();
|
||||||
|
|
||||||
|
Pais pais = app.obtenerPaisesPorIdentificador(105);
|
||||||
|
|
||||||
|
if (pais != null) {
|
||||||
|
System.out.println(pais);
|
||||||
|
} else {
|
||||||
|
System.out.println("No se encontraron coincidencias");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
|
||||||
|
List<Pais> paises = app.obtenerListaPaisesPorContinente("04");
|
||||||
|
|
||||||
|
if (!paises.isEmpty()) {
|
||||||
|
for(Pais p: paises) {
|
||||||
|
System.out.println(p);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("No se encontraron coincidencias");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pais obtenerPaisesPorIdentificador(int identificador) {
|
||||||
|
return paisDao.obtenerPaisPorID(identificador);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Pais> obtenerListaPaisesPorContinente(String continente){
|
||||||
|
return paisDao.obtenerPaisesPorContinente(continente);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.palomafp.aadd.smmb.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.smmb.model.Continente;
|
||||||
|
|
||||||
|
public interface IContinenteDAO {
|
||||||
|
|
||||||
|
public Continente obtenerContinentePorID(String idContinente);
|
||||||
|
//public List<Continente> obtenerPaisesPorContinente(String codContinente);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.palomafp.aadd.smmb.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.smmb.model.Pais;
|
||||||
|
|
||||||
|
public interface IPaisDAO {
|
||||||
|
|
||||||
|
public Pais obtenerPaisPorID(int idPais);
|
||||||
|
public List<Pais> obtenerPaisesPorContinente(String codContinente);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package org.palomafp.aadd.smmb.dao.impl;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.smmb.dao.IContinenteDAO;
|
||||||
|
import org.palomafp.aadd.smmb.model.Continente;
|
||||||
|
|
||||||
|
public class ContinenteDaoFichero implements IContinenteDAO{
|
||||||
|
|
||||||
|
private final File FICHERO_CONTINENTES = new File
|
||||||
|
("D:/Documentos/DAM 2/AC - Acceso a Datos/Practicas/aadd/fic05/informacion_continentes.csv");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Continente obtenerContinentePorID(String idCont) {
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(FICHERO_CONTINENTES))){
|
||||||
|
|
||||||
|
String linea = "";
|
||||||
|
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
|
||||||
|
if(!linea.trim().startsWith("a") && !linea.trim().isEmpty()) {
|
||||||
|
|
||||||
|
String[] campos = linea.split("#");
|
||||||
|
|
||||||
|
String codContinente = campos[1].trim();
|
||||||
|
|
||||||
|
if (codContinente.equals(idCont)) {
|
||||||
|
|
||||||
|
String nombre = campos[2].trim();
|
||||||
|
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codContinente);
|
||||||
|
continente.setNombre(nombre);
|
||||||
|
|
||||||
|
return continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (IOException e){
|
||||||
|
System.err.println("Error leyendo el fichero: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package org.palomafp.aadd.smmb.dao.impl;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.smmb.dao.IPaisDAO;
|
||||||
|
import org.palomafp.aadd.smmb.dao.IContinenteDAO;
|
||||||
|
import org.palomafp.aadd.smmb.model.Pais;
|
||||||
|
import org.palomafp.aadd.smmb.model.Continente;
|
||||||
|
|
||||||
|
public class PaisDaoFichero implements IPaisDAO {
|
||||||
|
|
||||||
|
private final File FICHERO_PAISES = new File(
|
||||||
|
"D:/Documentos/DAM 2/AC - Acceso a Datos/Practicas/aadd/fic05/informacion_paises.txt");
|
||||||
|
|
||||||
|
private IContinenteDAO continenteDao = new ContinenteDaoFichero();
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pais obtenerPaisPorID(int id) {
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(FICHERO_PAISES))) {
|
||||||
|
|
||||||
|
String linea = "";
|
||||||
|
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
|
||||||
|
if (!linea.trim().startsWith("#") && !linea.trim().isEmpty()) {
|
||||||
|
|
||||||
|
String[] campos = linea.split(",");
|
||||||
|
|
||||||
|
int idPais = Integer.parseInt(campos[1].trim());
|
||||||
|
|
||||||
|
if (idPais == id) {
|
||||||
|
|
||||||
|
String codigoContinente = campos[0].trim().replace("\"", "");
|
||||||
|
String nombrePais = campos[2].trim().replace("\"", "");
|
||||||
|
String capitalPais = campos[3].trim().replace("\"", "");
|
||||||
|
|
||||||
|
|
||||||
|
Continente continente = continenteDao.obtenerContinentePorID(codigoContinente);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Pais pais = new Pais();
|
||||||
|
pais.setIdentificador(idPais);
|
||||||
|
pais.setNombre(nombrePais);
|
||||||
|
pais.setNombreCapital(capitalPais);
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Error leyendo el fichero: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pais> obtenerPaisesPorContinente(String id) {
|
||||||
|
List<Pais> paises = new ArrayList<>();
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(FICHERO_PAISES))) {
|
||||||
|
|
||||||
|
String linea = "";
|
||||||
|
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
|
||||||
|
if (!linea.trim().startsWith("#") && !linea.trim().isEmpty()) {
|
||||||
|
|
||||||
|
String[] campos = linea.split(",");
|
||||||
|
|
||||||
|
String codigoContinente = campos[0].trim().replace("\"", "");
|
||||||
|
|
||||||
|
|
||||||
|
if (codigoContinente.equals(id)) {
|
||||||
|
|
||||||
|
int idPais = Integer.parseInt(campos[1].trim());
|
||||||
|
String nombrePais = campos[2].trim().replace("\"", "");
|
||||||
|
String capitalPais = campos[3].trim().replace("\"", "");
|
||||||
|
|
||||||
|
Pais pais = new Pais();
|
||||||
|
|
||||||
|
Continente continente = continenteDao.obtenerContinentePorID(codigoContinente);
|
||||||
|
|
||||||
|
pais.setIdentificador(idPais);
|
||||||
|
pais.setNombre(nombrePais);
|
||||||
|
pais.setNombreCapital(capitalPais);
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
paises.add(pais);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Error leyendo el fichero: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return paises;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package org.palomafp.aadd.smmb.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Continente implements Serializable{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private String codigo;
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
public Continente() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 this.nombre + " (" + this.codigo + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package org.palomafp.aadd.smmb.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Pais implements Serializable{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private int identificador;
|
||||||
|
private String nombre;
|
||||||
|
private String nombreCapital;
|
||||||
|
private Continente 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 getNombreCapital() {
|
||||||
|
return nombreCapital;
|
||||||
|
}
|
||||||
|
public void setNombreCapital(String capital) {
|
||||||
|
this.nombreCapital = capital;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContinente(Continente continente) {
|
||||||
|
this.continente = continente;
|
||||||
|
}
|
||||||
|
public Continente getContinente() {
|
||||||
|
return continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.nombre + " (" + this.identificador + ") con capital en " + this.nombreCapital +
|
||||||
|
" pertenece al continente " + this.continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user