First Commit
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-25">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Actividad_04</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=25
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=25
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=25
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,43 @@
|
|||||||
|
package org.palomafp.aadd.npz;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.npz.dao.impl.PaisDaoFichero;
|
||||||
|
import org.palomafp.aadd.npz.model.Pais;
|
||||||
|
import org.palomafp.dam2.aadd.npz.dao.IPaisDAO;
|
||||||
|
|
||||||
|
public class GestorMapaMundi {
|
||||||
|
|
||||||
|
private IPaisDAO paisDAO = new PaisDaoFichero();
|
||||||
|
|
||||||
|
public static void main (String[] args) {
|
||||||
|
// Se delega en el main, para que sea llamado en obtenerPaisPorID y obtenerListaPaisesPorContinente
|
||||||
|
GestorMapaMundi app = new GestorMapaMundi();
|
||||||
|
|
||||||
|
int identificadorPais = 105;
|
||||||
|
Pais pais = app.obtenerPaisPorID(identificadorPais);
|
||||||
|
System.out.println(pais);
|
||||||
|
|
||||||
|
// o
|
||||||
|
// System.out.println(app.obtenerPaisPorID(105));
|
||||||
|
|
||||||
|
System.out.println("----------------------------------------------------");
|
||||||
|
|
||||||
|
String codigoContinente = "04";
|
||||||
|
List<Pais> listaPaises = app.obtenerListaPaisesPorContinente(codigoContinente);
|
||||||
|
|
||||||
|
for (Pais pais2: listaPaises) {
|
||||||
|
System.out.println(pais2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pais obtenerPaisPorID(int identificador) {
|
||||||
|
return paisDAO.obtenerPaisPorID(identificador);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Pais> obtenerListaPaisesPorContinente(String codContinente){
|
||||||
|
return paisDAO.obtenerListaPaisesPorContinente(codContinente);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package org.palomafp.aadd.npz.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.npz.model.Continente;
|
||||||
|
import org.palomafp.aadd.npz.model.Pais;
|
||||||
|
import org.palomafp.dam2.aadd.npz.dao.IPaisDAO;
|
||||||
|
|
||||||
|
public class PaisDaoFichero implements IPaisDAO{
|
||||||
|
|
||||||
|
public static final String RUTA_FICHERO = "C:\\Users\\npauc\\aadd\\fic03\\informacion_paises.txt";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pais obtenerPaisPorID(int identificador) {
|
||||||
|
Pais paisEncontrado = null;
|
||||||
|
|
||||||
|
File f = new File(RUTA_FICHERO);
|
||||||
|
|
||||||
|
if(!f.exists()){
|
||||||
|
System.out.println("No encuentro el fichero " + f.getAbsolutePath());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try(BufferedReader br = new BufferedReader(new FileReader(f))){
|
||||||
|
String linea;
|
||||||
|
while((linea = br.readLine()) != null) {
|
||||||
|
linea = linea.trim();
|
||||||
|
if(linea.isEmpty() || linea.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] camposPais = linea.split(",");
|
||||||
|
String idPais = camposPais[1].trim();
|
||||||
|
|
||||||
|
if(Integer.parseInt(idPais) == identificador ) {
|
||||||
|
String codigoContinente = camposPais[0].trim().replace("\"","");
|
||||||
|
String nombrePais = camposPais[2].trim().replace("\"", "");
|
||||||
|
String capitalPais = camposPais[3].trim().replace("\"", "");
|
||||||
|
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codigoContinente);
|
||||||
|
|
||||||
|
paisEncontrado = new Pais();
|
||||||
|
paisEncontrado.setIdentificador(Integer.parseInt(idPais));
|
||||||
|
paisEncontrado.setNombre(nombrePais);
|
||||||
|
paisEncontrado.setCapital(capitalPais);
|
||||||
|
paisEncontrado.setContinente(continente);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch(IOException e) {
|
||||||
|
System.out.println("No se puede abrir el fichero: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return paisEncontrado;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pais> obtenerListaPaisesPorContinente(String codContinente) {
|
||||||
|
|
||||||
|
List<Pais> listaPaisesEncontrados = null;
|
||||||
|
String linea;
|
||||||
|
|
||||||
|
File fPaises = new File(RUTA_FICHERO);
|
||||||
|
|
||||||
|
try(BufferedReader br = new BufferedReader(new FileReader(fPaises))){
|
||||||
|
|
||||||
|
while((linea = br.readLine()) != null) {
|
||||||
|
linea = linea.trim();
|
||||||
|
if (linea.isEmpty() || linea.startsWith("#")){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] campoPais = linea.split(",");
|
||||||
|
|
||||||
|
String codigoContinente = campoPais[0].trim().replace("\"" , "");
|
||||||
|
|
||||||
|
if(codigoContinente.equals(codContinente)) {
|
||||||
|
|
||||||
|
if(listaPaisesEncontrados == null) {
|
||||||
|
listaPaisesEncontrados = new ArrayList<Pais>();
|
||||||
|
}
|
||||||
|
|
||||||
|
String idPais = campoPais[1].trim();
|
||||||
|
String nombrePais = campoPais[2].trim().replace("\"", "");
|
||||||
|
String capitalParis = campoPais[3].trim().replace("\"", "");
|
||||||
|
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codigoContinente);
|
||||||
|
|
||||||
|
Pais pais = new Pais();
|
||||||
|
pais.setIdentificador(Integer.parseInt(idPais));
|
||||||
|
pais.setNombre(nombrePais);
|
||||||
|
pais.setCapital(capitalParis);
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
listaPaisesEncontrados.add(pais);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (IOException e) {
|
||||||
|
System.out.println("" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return listaPaisesEncontrados;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package org.palomafp.aadd.npz.model;
|
||||||
|
|
||||||
|
public class Continente {
|
||||||
|
private String codigo;
|
||||||
|
private String 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,42 @@
|
|||||||
|
package org.palomafp.aadd.npz.model;
|
||||||
|
|
||||||
|
public class Pais {
|
||||||
|
private int identificador;
|
||||||
|
private String nombre;
|
||||||
|
private String capital;
|
||||||
|
|
||||||
|
private Continente continente;
|
||||||
|
|
||||||
|
public int getIdentificado() {
|
||||||
|
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 + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.palomafp.dam2.aadd.npz.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.npz.model.Pais;
|
||||||
|
|
||||||
|
public interface IPaisDAO {
|
||||||
|
|
||||||
|
Pais obtenerPaisPorID(int identificador);
|
||||||
|
List<Pais> obtenerListaPaisesPorContinente(String codContinente);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user