Primer commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
package org.palomafp.aadd.tma;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.tma.model.*;
|
||||||
|
import org.palomafp.aadd.tma.GestorMapaMundi;
|
||||||
|
import org.palomafp.aadd.tma.dao.PaisDaoFichero;
|
||||||
|
import org.palomafp.aadd.tma.model.Pais;
|
||||||
|
|
||||||
|
public class GestorMapaMundi {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
try {
|
||||||
|
PaisDaoFichero pd = new PaisDaoFichero();
|
||||||
|
|
||||||
|
System.out.println(GestorMapaMundi.obtenerPaisesPorIdentificador(105));
|
||||||
|
for (Pais p : pd.obtenerPaisesPorContinente("04")) {
|
||||||
|
System.out.println(p);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Pais obtenerPaisesPorIdentificador(int identificador) throws Exception {
|
||||||
|
PaisDaoFichero pd = new PaisDaoFichero();
|
||||||
|
for (int i = 0; i < pd.getListaPais().size(); i++) {
|
||||||
|
if (pd.getListaPais().get(i).getIdentificador() == identificador) {
|
||||||
|
return pd.getListaPais().get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Continente obtenerConPorCod(String cod) throws Exception {
|
||||||
|
PaisDaoFichero pd = new PaisDaoFichero();
|
||||||
|
for (int i = 0; i < pd.getListaCon().size(); i++) {
|
||||||
|
if (pd.getListaCon().get(i).getCodigo().equals(cod)) {
|
||||||
|
return pd.getListaCon().get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package org.palomafp.aadd.tma.dao;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.tma.GestorMapaMundi;
|
||||||
|
import org.palomafp.aadd.tma.dao.impl.IPaisDAO;
|
||||||
|
import org.palomafp.aadd.tma.model.Continente;
|
||||||
|
import org.palomafp.aadd.tma.model.Pais;
|
||||||
|
|
||||||
|
public class PaisDaoFichero implements IPaisDAO {
|
||||||
|
String linea;
|
||||||
|
String[] datos;
|
||||||
|
ArrayList<Continente> listaCon = new ArrayList<Continente>();
|
||||||
|
final String RUTA = "C:\\Users\\alumnoT\\aadd\\fic03\\informacion_paises.txt";
|
||||||
|
ArrayList<Pais> listaPais = new ArrayList<Pais>();
|
||||||
|
|
||||||
|
public PaisDaoFichero() throws Exception {
|
||||||
|
BufferedReader bfr = new BufferedReader(new FileReader(this.getRUTA()));
|
||||||
|
|
||||||
|
listaCon.add(new Continente("01", "Africa"));
|
||||||
|
listaCon.add(new Continente("02", "America"));
|
||||||
|
listaCon.add(new Continente("03", "Asia"));
|
||||||
|
listaCon.add(new Continente("04", "Europa"));
|
||||||
|
listaCon.add(new Continente("05", "Oceania"));
|
||||||
|
|
||||||
|
while ((linea = bfr.readLine()) != null) {
|
||||||
|
if (!linea.startsWith("#") && !linea.startsWith("-")) {
|
||||||
|
linea = linea.replace("\"", "");
|
||||||
|
linea = linea.replace(" ", "");
|
||||||
|
datos = linea.split(",");
|
||||||
|
Continente c = obtenerConPorCod(datos[0]);
|
||||||
|
Pais p = new Pais(Integer.parseInt(datos[1]), datos[2], datos[3], c);
|
||||||
|
listaPais.add(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bfr.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Continente obtenerConPorCod(String cod) {
|
||||||
|
for (Continente con : listaCon) {
|
||||||
|
if (con.getCodigo().equals(cod)) {
|
||||||
|
return con;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pais obtenerPaisPorId(int id) throws Exception {
|
||||||
|
PaisDaoFichero pd = new PaisDaoFichero();
|
||||||
|
for (int i = 0; i < pd.getListaPais().size(); i++) {
|
||||||
|
if (pd.getListaPais().get(i).getIdentificador() == id) {
|
||||||
|
return pd.getListaPais().get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Pais> obtenerPaisesPorContinente(String codCon) throws Exception {
|
||||||
|
ArrayList<Pais> listaPaisCon = new ArrayList<Pais>();
|
||||||
|
PaisDaoFichero pd = new PaisDaoFichero();
|
||||||
|
for (int i = 0; i < pd.getListaPais().size(); i++) {
|
||||||
|
if (pd.getListaPais().get(i).getContinente().getCodigo().equals(codCon)) {
|
||||||
|
listaPaisCon.add(pd.getListaPais().get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return listaPaisCon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLinea() {
|
||||||
|
return linea;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLinea(String linea) {
|
||||||
|
this.linea = linea;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getDatos() {
|
||||||
|
return datos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDatos(String[] datos) {
|
||||||
|
this.datos = datos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Continente> getListaCon() {
|
||||||
|
return listaCon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListaCon(ArrayList<Continente> listaCon) {
|
||||||
|
this.listaCon = listaCon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRUTA() {
|
||||||
|
return RUTA;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Pais> getListaPais() {
|
||||||
|
return listaPais;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListaPais(ArrayList<Pais> listaPais) {
|
||||||
|
this.listaPais = listaPais;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.palomafp.aadd.tma.dao.impl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.tma.model.Pais;
|
||||||
|
|
||||||
|
public interface IPaisDAO {
|
||||||
|
|
||||||
|
Pais obtenerPaisPorId(int id) throws Exception;
|
||||||
|
|
||||||
|
ArrayList<Pais> obtenerPaisesPorContinente(String codCon) throws Exception;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package org.palomafp.aadd.tma.model;
|
||||||
|
|
||||||
|
public class Continente {
|
||||||
|
private String codigo;
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
public Continente(String cod, String nombre) {
|
||||||
|
this.setCodigo(cod);
|
||||||
|
this.setNombre(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() {
|
||||||
|
String imprimir = "Continente [codigo=" + this.codigo + ", nombre=" + this.nombre + "]";
|
||||||
|
return imprimir;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package org.palomafp.aadd.tma.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.tma.GestorMapaMundi;
|
||||||
|
|
||||||
|
public class Pais {
|
||||||
|
private int identificador;
|
||||||
|
private String nombre;
|
||||||
|
private String capital;
|
||||||
|
private Continente continente;
|
||||||
|
|
||||||
|
public Pais() {
|
||||||
|
this.identificador = 0;
|
||||||
|
this.nombre = null;
|
||||||
|
this.capital = null;
|
||||||
|
this.continente = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pais(int int1, String string, String string2, Continente string3) throws Exception {
|
||||||
|
this.setIdentificador(int1);
|
||||||
|
this.setNombre(string);
|
||||||
|
this.setCapital(string2);
|
||||||
|
this.continente = string3;
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
String imprimir = "Pais [identificador=" + this.identificador + ", nombre=" + this.nombre + ", capital="
|
||||||
|
+ this.capital + ", continente=" + this.continente.toString() + "]";
|
||||||
|
|
||||||
|
return imprimir;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user