Este es el primer commit
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
|||||||
|
# --- Directorios de compilación (binarios) ---
|
||||||
|
bin/
|
||||||
|
|
||||||
|
# --- Archivos de configuración de Eclipse ---
|
||||||
|
.metadata/
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings/
|
||||||
|
|
||||||
|
# --- Archivos de configuración de VS Code ---
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# --- Archivos temporales y del sistema ---
|
||||||
|
*.log
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# Información de países
|
||||||
|
# Se muestra información del código de continente, identificador de país, nombre del país junto con su capital
|
||||||
|
"01",1, "Angola", "Luanda"
|
||||||
|
"02",62, "Brasil", "Brasilia"
|
||||||
|
"02",63, "Canadá", "Ottawa"
|
||||||
|
"02",64, "Chile", "Santiago De Chile"
|
||||||
|
"02",65, "Colombia", "Bogotá"
|
||||||
|
# Otra lista de países
|
||||||
|
"03",92, "Afganistán", "Kabul"
|
||||||
|
"03",93, "Arabia Saudita", "Riad"
|
||||||
|
"03",105, "Filipinas", "Manila"
|
||||||
|
"03",106, "India", "Nueva Delhi"
|
||||||
|
"03",136, "Vietnam", "Hanoi"
|
||||||
|
"04",147, "Bulgaria", "Sofía"
|
||||||
|
"04",152, "España", "Madrid"
|
||||||
|
"04",181, "Suecia", "Estocolmo"
|
||||||
|
# La parte final de países
|
||||||
|
"04",182, "Suiza", "Berna"
|
||||||
|
"05",185, "Australia", "Canberra"
|
||||||
|
"05",186, "Fiyi", "Suva"
|
||||||
|
"05",187, "Islas Marshall", "Majuro"
|
||||||
|
"05",196, "Tonga", "Nuku'alofa"
|
||||||
|
"05",197, "Tuvalu", "Funafuti"
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
module aadd_fic04 {
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package org.palomafp.aadd.jaec;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.jaec.model.Continente;
|
||||||
|
import org.palomafp.aadd.jaec.model.Pais;
|
||||||
|
import org.palomafp.aadd.jaec.dao.IPaisDAO;
|
||||||
|
import org.palomafp.aadd.jaec.dao.impl.PaisDaoText;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class GestorMapaMundi {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
GestorMapaMundi app = new GestorMapaMundi();
|
||||||
|
|
||||||
|
int identificadorPais = 105;
|
||||||
|
Pais pais = app.obtenerPaisPorIdentificador(105);
|
||||||
|
System.out.println(pais);
|
||||||
|
|
||||||
|
System.out.println("----------------------------------------------------");
|
||||||
|
|
||||||
|
String codigoContinente = "04";
|
||||||
|
List<Pais> listaPaises = app.obtenerListaPaisesPorContinente("04");
|
||||||
|
for (Pais p2 : listaPaises) {
|
||||||
|
System.out.println(p2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Pais obtenerPaisPorIdentificador(int identificador) {
|
||||||
|
Pais pais = null;
|
||||||
|
|
||||||
|
IPaisDAO paisDAO = new PaisDaoText();
|
||||||
|
pais = paisDAO.obtenerPaisPorID(identificador);
|
||||||
|
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Pais> obtenerListaPaisesPorContinente(String codContinente) {
|
||||||
|
List<Pais> listaPaises = null;
|
||||||
|
|
||||||
|
IPaisDAO paisDAO = new PaisDaoText();
|
||||||
|
listaPaises = paisDAO.obtenerPaisesPorContinente(codContinente);
|
||||||
|
|
||||||
|
return listaPaises;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package org.palomafp.aadd.jaec.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.palomafp.aadd.jaec.model.Pais;
|
||||||
|
|
||||||
|
public interface IPaisDAO {
|
||||||
|
Pais obtenerPaisPorID(int identificador);
|
||||||
|
|
||||||
|
List<Pais> obtenerPaisesPorContinente(String codContinente);
|
||||||
|
}
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
package org.palomafp.aadd.jaec.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.jaec.dao.IPaisDAO;
|
||||||
|
import org.palomafp.aadd.jaec.model.Continente;
|
||||||
|
import org.palomafp.aadd.jaec.model.Pais;
|
||||||
|
|
||||||
|
public class PaisDaoText implements IPaisDAO {
|
||||||
|
private final static String RUTA_FICHERO = "C:\\Users\\alumnoT\\eclipse-workspace\\aadd\\fic04\\informacion_paises.txt";
|
||||||
|
|
||||||
|
// Metodo para obtener un List<Pais> con objetos Pais por codigo de Continente
|
||||||
|
public List<Pais> obtenerPaisesPorContinente(String codigoContinenteBusqueda) {
|
||||||
|
File fichero = new File(RUTA_FICHERO);
|
||||||
|
List<Pais> paises = new ArrayList<Pais>();
|
||||||
|
|
||||||
|
String linea = "";
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(fichero))) {
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
// Controlamos que no empiece por # ni por --
|
||||||
|
// Controlamos que la línea no esté vacía
|
||||||
|
if (linea.trim().charAt(0) != '#' && !(linea.trim().startsWith("--")) && !linea.isEmpty()) {
|
||||||
|
String[] informacion = linea.split(",");
|
||||||
|
String codContinente = informacion[0].replace("\"", "").trim();
|
||||||
|
int idPais = Integer.parseInt(informacion[1].trim());
|
||||||
|
String nombrePais = informacion[2].replace("\"", "").trim();
|
||||||
|
String capitalPais = informacion[3].replace("\"", "").trim();
|
||||||
|
|
||||||
|
if (codigoContinenteBusqueda.compareTo(codContinente) == 0) {
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codContinente);
|
||||||
|
continente.setNombre(null);
|
||||||
|
|
||||||
|
Pais pais = new Pais();
|
||||||
|
pais.setIdentificador(idPais);
|
||||||
|
pais.setNombre(nombrePais);
|
||||||
|
pais.setCapital(capitalPais);
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
paises.add(pais);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
System.out.println(ioe.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// En caso no se encuentre nada se devuelve la lista paises vacio
|
||||||
|
return paises;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Metodo para obtener un Pais por ID
|
||||||
|
public Pais obtenerPaisPorID(int idPaisBusqueda) {
|
||||||
|
// Leo la lista de TODOS los paises
|
||||||
|
List<Pais> listaPaises = leerListaPaises();
|
||||||
|
|
||||||
|
// Busco solamente a un unico pais
|
||||||
|
for (Pais p : listaPaises) {
|
||||||
|
if (p.getIdentificador() == idPaisBusqueda) {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Si no encuentro nada devuelvo nulo
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Metodo para leer una lista de paises a partir de un fichero
|
||||||
|
// Devuelve un List<Pais> con varios objetos <Pais>
|
||||||
|
public List<Pais> leerListaPaises() {
|
||||||
|
File fichero = new File(RUTA_FICHERO);
|
||||||
|
List<Pais> paises = new ArrayList<Pais>();
|
||||||
|
|
||||||
|
String linea = "";
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(fichero))) {
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
// Controlamos que no empiece por # ni por --
|
||||||
|
// Controlamos que la línea no esté vacía
|
||||||
|
if (linea.trim().charAt(0) != '#' && !(linea.trim().startsWith("--")) && !linea.isEmpty()) {
|
||||||
|
String[] informacion = linea.split(",");
|
||||||
|
String codContinente = informacion[0].replace("\"", "").trim();
|
||||||
|
int idPais = Integer.parseInt(informacion[1].trim());
|
||||||
|
String nombrePais = informacion[2].replace("\"", "").trim();
|
||||||
|
String capitalPais = informacion[3].replace("\"", "").trim();
|
||||||
|
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codContinente);
|
||||||
|
continente.setNombre(null);
|
||||||
|
|
||||||
|
Pais pais = new Pais();
|
||||||
|
pais.setIdentificador(idPais);
|
||||||
|
pais.setNombre(nombrePais);
|
||||||
|
pais.setCapital(capitalPais);
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
paises.add(pais);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
System.out.println(ioe.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// En caso no se encuentre nada se devuelve la lista paises vacio
|
||||||
|
return paises;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package org.palomafp.aadd.jaec.model;
|
||||||
|
|
||||||
|
public class Continente {
|
||||||
|
private String codigo, nombre;
|
||||||
|
|
||||||
|
// Constructores
|
||||||
|
public Continente() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Continente(String codigo, String nombre) {
|
||||||
|
this.codigo = codigo;
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters y Setters
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// toString
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Continente [codigo=" + codigo + ", nombre=" + nombre + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package org.palomafp.aadd.jaec.model;
|
||||||
|
|
||||||
|
public class Pais {
|
||||||
|
private int identificador;
|
||||||
|
private String nombre, capital;
|
||||||
|
private Continente continente;
|
||||||
|
|
||||||
|
// Constructores
|
||||||
|
public Pais() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pais(int identificador, String nombre, String capital) {
|
||||||
|
this.identificador = identificador;
|
||||||
|
this.nombre = nombre;
|
||||||
|
this.capital = capital;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters y Setters
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// toString
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Pais [identificador=" + identificador + ", nombre=" + nombre + ", capital=" + capital + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user