primer commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
# Ignorar la carpeta de compilados
|
||||||
|
bin/
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Ignorar archivos de configuración de Eclipse
|
||||||
|
.settings/
|
||||||
|
.project
|
||||||
|
.classpath
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
module Ficheros_03 {
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package org.palomafp.dam2.aadd.jx.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.palomafp.dam2.aadd.jx.model.Pais;
|
||||||
|
|
||||||
|
public interface IPaisDAO {
|
||||||
|
Pais obtenerPaisPorId(int idPais);
|
||||||
|
List<Pais> obtenerPaisesPorContinente(String codContinente);
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package org.palomafp.dam2.aadd.jx.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.dam2.aadd.jx.dao.IPaisDAO;
|
||||||
|
import org.palomafp.dam2.aadd.jx.model.Continente;
|
||||||
|
import org.palomafp.dam2.aadd.jx.model.Pais;
|
||||||
|
|
||||||
|
public class PaisDaoFichero implements IPaisDAO {
|
||||||
|
|
||||||
|
private static final String RUTA_FICHERO = "C:\\Users\\alumnoT\\aadd\\fic03\\informacion_paises.txt";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pais obtenerPaisPorId(int idPais) {
|
||||||
|
File fichero = new File(RUTA_FICHERO);
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(fichero))) {
|
||||||
|
String linea;
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
if (!linea.startsWith("#")) {
|
||||||
|
String[] partes = linea.replace("\"", "").split(",");
|
||||||
|
int idComparar = Integer.parseInt(partes[1].trim());
|
||||||
|
|
||||||
|
if (idComparar == idPais) {
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(partes[0].trim());
|
||||||
|
|
||||||
|
Pais pais = new Pais();
|
||||||
|
pais.setContinente(continente);
|
||||||
|
pais.setIdentificador(idComparar);
|
||||||
|
pais.setNombre(partes[2].trim());
|
||||||
|
pais.setCapital(partes[3].trim()); // Asegúrate de usar setNombreCapital
|
||||||
|
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pais> obtenerPaisesPorContinente(String codContinente) {
|
||||||
|
File fichero = new File(RUTA_FICHERO);
|
||||||
|
List<Pais> lpaises = new ArrayList<>();
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(fichero))) {
|
||||||
|
String linea;
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
if (!linea.startsWith("#")) {
|
||||||
|
String[] partes = linea.replace("\"", "").split(",");
|
||||||
|
|
||||||
|
if (partes[0].trim().equals(codContinente)) {
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codContinente);
|
||||||
|
|
||||||
|
Pais pais = new Pais();
|
||||||
|
pais.setContinente(continente);
|
||||||
|
pais.setNombre(partes[2].trim());
|
||||||
|
pais.setCapital(partes[3].trim());
|
||||||
|
pais.setIdentificador(Integer.parseInt(partes[1].trim()));
|
||||||
|
|
||||||
|
lpaises.add(pais);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return lpaises;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package org.palomafp.dam2.aadd.jx.model;
|
||||||
|
|
||||||
|
public class Continente {
|
||||||
|
|
||||||
|
private String codigo;
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
// Constructores
|
||||||
|
public Continente() {
|
||||||
|
|
||||||
|
}
|
||||||
|
public Continente(String codigo) {
|
||||||
|
super();
|
||||||
|
this.codigo = codigo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Getters y setters
|
||||||
|
public String getCodigo() {
|
||||||
|
return codigo;
|
||||||
|
}
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCodigo(String codigo) {
|
||||||
|
this.codigo = codigo;
|
||||||
|
}
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generamos el método toString
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Continente [codigo=" + codigo + ", nombre=" + nombre + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.palomafp.dam2.aadd.jx.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.dam2.aadd.jx.dao.IPaisDAO;
|
||||||
|
import org.palomafp.dam2.aadd.jx.dao.impl.PaisDaoFichero;
|
||||||
|
import org.palomafp.dam2.aadd.jx.model.Pais;
|
||||||
|
|
||||||
|
public class GestorMapaMundi {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
IPaisDAO paisDao = new PaisDaoFichero();
|
||||||
|
|
||||||
|
Pais pais = paisDao.obtenerPaisPorId(105);
|
||||||
|
System.out.println("Pais encontrado¡¡");
|
||||||
|
System.out.println(pais);
|
||||||
|
|
||||||
|
System.out.println(" Lista de países del continente.");
|
||||||
|
List<Pais> paises = paisDao.obtenerPaisesPorContinente("04");
|
||||||
|
for (Pais p : paises) {
|
||||||
|
System.out.println(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package org.palomafp.dam2.aadd.jx.model;
|
||||||
|
|
||||||
|
public class Pais {
|
||||||
|
|
||||||
|
private int identificador;
|
||||||
|
private String nombre;
|
||||||
|
private String capital;
|
||||||
|
private Continente continente;
|
||||||
|
|
||||||
|
|
||||||
|
public Pais() {
|
||||||
|
|
||||||
|
}
|
||||||
|
public Pais(int identificador, String nombre, String capital, Continente continente) {
|
||||||
|
super();
|
||||||
|
this.identificador = identificador;
|
||||||
|
this.nombre = nombre;
|
||||||
|
this.capital = capital;
|
||||||
|
this.continente = continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getIdentificador() {
|
||||||
|
return identificador;
|
||||||
|
}
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
public String getCapital() {
|
||||||
|
return capital;
|
||||||
|
}
|
||||||
|
public Continente getContinente() {
|
||||||
|
return continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdentificador(int identificador) {
|
||||||
|
this.identificador = identificador;
|
||||||
|
}
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
public void setCapital(String capital) {
|
||||||
|
this.capital = capital;
|
||||||
|
}
|
||||||
|
public void setContinente(Continente continente) {
|
||||||
|
this.continente = continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Pais [identificador=" + identificador + ", nombre=" + nombre + ", capital=" + capital + ", continente="
|
||||||
|
+ continente + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user