Primer
This commit is contained in:
@@ -1,113 +1,25 @@
|
|||||||
package org.palomafp.dam2.aadd.anp;
|
package org.palomafp.dam2.aadd.anp;
|
||||||
|
|
||||||
import java.io.*;
|
import java.util.List;
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import org.palomafp.dam2.aadd.anp.model.Continente;
|
import org.palomafp.dam2.aadd.anp.dao.IPaisDAO;
|
||||||
|
import org.palomafp.dam2.aadd.anp.dao.impl.PaisDaoText;
|
||||||
import org.palomafp.dam2.aadd.anp.model.Pais;
|
import org.palomafp.dam2.aadd.anp.model.Pais;
|
||||||
|
|
||||||
|
|
||||||
public class GestorMapaMundi {
|
public class GestorMapaMundi {
|
||||||
|
|
||||||
private static final String ruta = "C:\\Users\\PC GAMING\\aadd\\fic03\\informacion_paises.txt";
|
private IPaisDAO paisDAO;
|
||||||
public Pais obtenerPais(int identificadorPais) {
|
|
||||||
|
|
||||||
try (BufferedReader br =
|
public GestorMapaMundi() {
|
||||||
new BufferedReader(new FileReader(ruta))) {
|
paisDAO = new PaisDaoText();
|
||||||
|
|
||||||
String linea;
|
|
||||||
|
|
||||||
while ((linea = br.readLine()) != null) {
|
|
||||||
|
|
||||||
if (linea.startsWith("#")) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (linea.trim().isEmpty()) {
|
public Pais obtenerPais(int identificador) {
|
||||||
continue;
|
return paisDAO.obtenerPais(identificador);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pais pais = convertirLineaAPais(linea);
|
public List<Pais> obtenerPaisesPorContinente(String codContinente) {
|
||||||
|
return paisDAO.obtenerPaisesPorContinente(codContinente);
|
||||||
if (pais.getId() == identificadorPais) {
|
|
||||||
return pais;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println(
|
|
||||||
"Error al leer el fichero: "
|
|
||||||
+ e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public List<Pais> obtenerPaisesPorContinente(
|
|
||||||
String codigoContinente) {
|
|
||||||
|
|
||||||
List<Pais> paises = new ArrayList<>();
|
|
||||||
|
|
||||||
try (BufferedReader br =
|
|
||||||
new BufferedReader(new FileReader(ruta))) {
|
|
||||||
|
|
||||||
String linea;
|
|
||||||
|
|
||||||
while ((linea = br.readLine()) != null) {
|
|
||||||
|
|
||||||
if (linea.startsWith("#")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (linea.trim().isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Pais pais = convertirLineaAPais(linea);
|
|
||||||
|
|
||||||
if (pais.getContinente()
|
|
||||||
.getCodigoContinente()
|
|
||||||
.equals(codigoContinente)) {
|
|
||||||
|
|
||||||
paises.add(pais);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println(
|
|
||||||
"Error al leer el fichero: "
|
|
||||||
+ e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return paises;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Pais convertirLineaAPais(String linea) {
|
|
||||||
|
|
||||||
linea = linea.replace("\"", "");
|
|
||||||
|
|
||||||
String[] datos = linea.split(",");
|
|
||||||
|
|
||||||
String codigoContinente = datos[0].trim();
|
|
||||||
|
|
||||||
int id = Integer.parseInt(datos[1].trim());
|
|
||||||
|
|
||||||
String nombre = datos[2].trim();
|
|
||||||
|
|
||||||
String capital = datos[3].trim();
|
|
||||||
|
|
||||||
Continente continente =
|
|
||||||
new Continente(codigoContinente, nombre);
|
|
||||||
|
|
||||||
return new Pais(
|
|
||||||
id,
|
|
||||||
nombre,
|
|
||||||
capital,
|
|
||||||
continente
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -121,15 +33,14 @@ public class GestorMapaMundi {
|
|||||||
if (pais != null) {
|
if (pais != null) {
|
||||||
System.out.println(pais);
|
System.out.println(pais);
|
||||||
} else {
|
} else {
|
||||||
System.out.println(
|
System.out.println("No se ha encontrado el país.");
|
||||||
"No se ha encontrado el país.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
|
||||||
System.out.println("APARTADO B");
|
System.out.println("APARTADO B");
|
||||||
|
|
||||||
List<Pais> paises =
|
List<Pais> paises = codigo.obtenerPaisesPorContinente("04");
|
||||||
codigo.obtenerPaisesPorContinente("04");
|
|
||||||
|
|
||||||
for (Pais p : paises) {
|
for (Pais p : paises) {
|
||||||
System.out.println(p);
|
System.out.println(p);
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.palomafp.dam2.aadd.anp.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.dam2.aadd.anp.model.Pais;
|
||||||
|
|
||||||
|
public interface IPaisDAO {
|
||||||
|
Pais obtenerPais(int identificador);
|
||||||
|
|
||||||
|
List<Pais> obtenerPaisesPorContinente(String codContinente);
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
package org.palomafp.dam2.aadd.anp.dao.impl;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.palomafp.dam2.aadd.anp.dao.*;
|
||||||
|
import org.palomafp.dam2.aadd.anp.model.*;
|
||||||
|
|
||||||
|
public class PaisDaoText implements IPaisDAO {
|
||||||
|
|
||||||
|
private static final String ruta = "C:\\Users\\PC GAMING\\aadd\\fic03\\informacion_paises.txt";
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pais obtenerPais(int identificadorPais) {
|
||||||
|
|
||||||
|
try (BufferedReader br =
|
||||||
|
new BufferedReader(new FileReader(ruta))) {
|
||||||
|
|
||||||
|
String linea;
|
||||||
|
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
|
||||||
|
if (linea.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (linea.trim().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pais pais = convertirLineaAPais(linea);
|
||||||
|
|
||||||
|
if (pais.getId() == identificadorPais) {
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println(
|
||||||
|
"Error al leer el fichero: "
|
||||||
|
+ e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pais> obtenerPaisesPorContinente(
|
||||||
|
String codigoContinente) {
|
||||||
|
|
||||||
|
List<Pais> paises = new ArrayList<>();
|
||||||
|
|
||||||
|
try (BufferedReader br =
|
||||||
|
new BufferedReader(new FileReader(ruta))) {
|
||||||
|
|
||||||
|
String linea;
|
||||||
|
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
|
||||||
|
if (linea.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (linea.trim().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pais pais = convertirLineaAPais(linea);
|
||||||
|
|
||||||
|
if (pais.getContinente()
|
||||||
|
.getCodigoContinente()
|
||||||
|
.equals(codigoContinente)) {
|
||||||
|
|
||||||
|
paises.add(pais);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println(
|
||||||
|
"Error al leer el fichero: "
|
||||||
|
+ e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return paises;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private Pais convertirLineaAPais(String linea) {
|
||||||
|
|
||||||
|
linea = linea.replace("\"", "");
|
||||||
|
|
||||||
|
String[] datos = linea.split(",");
|
||||||
|
|
||||||
|
String codigoContinente = datos[0].trim();
|
||||||
|
|
||||||
|
int id = Integer.parseInt(datos[1].trim());
|
||||||
|
|
||||||
|
String nombre = datos[2].trim();
|
||||||
|
|
||||||
|
String capital = datos[3].trim();
|
||||||
|
|
||||||
|
Continente continente =
|
||||||
|
new Continente(codigoContinente, nombre);
|
||||||
|
|
||||||
|
return new Pais(
|
||||||
|
id,
|
||||||
|
nombre,
|
||||||
|
capital,
|
||||||
|
continente
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user