first commit
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
.settings/
|
||||
bin/
|
||||
.classpath
|
||||
.project
|
||||
*.class
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.palomafp.aadd.dta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.palomafp.aadd.dta.dao.IPaisDAO;
|
||||
import org.palomafp.aadd.dta.dao.impl.PaisDaoFichero;
|
||||
import org.palomafp.aadd.dta.model.Pais;
|
||||
|
||||
public class GestorMapaMundi {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Pais pais = obtenerPaisesPorIdentificador(105);
|
||||
|
||||
System.out.println("País encontrado:");
|
||||
System.out.println(pais);
|
||||
System.out.println();
|
||||
|
||||
List<Pais> listaPaises = obtenerListaPaisesPorContinente("04");
|
||||
|
||||
System.out.println("Países del continente 04:");
|
||||
|
||||
for (Pais p : listaPaises) {
|
||||
System.out.println(p);
|
||||
}
|
||||
}
|
||||
|
||||
public static Pais obtenerPaisesPorIdentificador(int identificador) {
|
||||
|
||||
IPaisDAO paisDao = new PaisDaoFichero();
|
||||
|
||||
Pais pais = paisDao.obtenerPaisPorID(identificador);
|
||||
|
||||
return pais;
|
||||
}
|
||||
|
||||
public static List<Pais> obtenerListaPaisesPorContinente(String codigoContinente) {
|
||||
|
||||
IPaisDAO paisDao = new PaisDaoFichero();
|
||||
|
||||
List<Pais> listaPaises = paisDao.obtenerPaisesPorContinente(codigoContinente);
|
||||
|
||||
return listaPaises;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.palomafp.aadd.dta.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.palomafp.aadd.dta.model.Pais;
|
||||
|
||||
public interface IPaisDAO {
|
||||
|
||||
Pais obtenerPaisPorID(int idPais);
|
||||
List<Pais> obtenerPaisesPorContinente(String codContinente);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package org.palomafp.aadd.dta.dao.impl;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.palomafp.aadd.dta.dao.IPaisDAO;
|
||||
import org.palomafp.aadd.dta.model.Continente;
|
||||
import org.palomafp.aadd.dta.model.Pais;
|
||||
|
||||
public class PaisDaoFichero implements IPaisDAO {
|
||||
|
||||
private static final String RUTA = "C:\\Docs\\02dam\\accesoadatos\\ud01_manejoficheros\\04fic\\informacion_paises.txt";
|
||||
|
||||
@Override
|
||||
public Pais obtenerPaisPorID(int idPais) {
|
||||
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(RUTA))) {
|
||||
|
||||
String linea;
|
||||
|
||||
while ((linea = br.readLine()) != null) {
|
||||
|
||||
if (linea.trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (linea.startsWith("#") || linea.startsWith("--")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
linea = linea.replace("\"", "");
|
||||
|
||||
String[] datos = linea.split(",");
|
||||
|
||||
String codigoContinente = datos[0].trim();
|
||||
int identificador = Integer.parseInt(datos[1].trim());
|
||||
String nombrePais = datos[2].trim();
|
||||
String capital = datos[3].trim();
|
||||
|
||||
if (identificador == idPais) {
|
||||
|
||||
Continente continente = new Continente();
|
||||
continente.setCodigo(codigoContinente);
|
||||
|
||||
Pais pais = new Pais();
|
||||
pais.setIdentificador(identificador);
|
||||
pais.setNombre(nombrePais);
|
||||
pais.setCapital(capital);
|
||||
pais.setContinente(continente);
|
||||
|
||||
return pais;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error al leer el fichero: " + e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pais> obtenerPaisesPorContinente(String codContinente) {
|
||||
|
||||
List<Pais> listaPaises = new ArrayList<>();
|
||||
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(RUTA))) {
|
||||
|
||||
String linea;
|
||||
|
||||
while ((linea = br.readLine()) != null) {
|
||||
|
||||
if (linea.trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (linea.startsWith("#") || linea.startsWith("--")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
linea = linea.replace("\"", "");
|
||||
|
||||
String[] datos = linea.split(",");
|
||||
|
||||
String codigoContinente = datos[0].trim();
|
||||
int identificador = Integer.parseInt(datos[1].trim());
|
||||
String nombrePais = datos[2].trim();
|
||||
String capital = datos[3].trim();
|
||||
|
||||
if (codigoContinente.equals(codContinente)) {
|
||||
|
||||
Continente continente = new Continente();
|
||||
continente.setCodigo(codigoContinente);
|
||||
|
||||
Pais pais = new Pais();
|
||||
pais.setIdentificador(identificador);
|
||||
pais.setNombre(nombrePais);
|
||||
pais.setCapital(capital);
|
||||
pais.setContinente(continente);
|
||||
|
||||
listaPaises.add(pais);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error al leer el fichero: " + e.getMessage());
|
||||
}
|
||||
|
||||
return listaPaises;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.palomafp.aadd.dta.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,59 @@
|
||||
package org.palomafp.aadd.dta.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) {
|
||||
this.identificador = identificador;
|
||||
this.nombre = nombre;
|
||||
this.capital = capital;
|
||||
this.continente = continente;
|
||||
}
|
||||
|
||||
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 "Pais [identificador=" + identificador
|
||||
+ ", nombre=" + nombre
|
||||
+ ", capital=" + capital
|
||||
+ ", continente=" + continente + "]";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user