Advertisement
dcndrd

Untitled

Dec 17th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. package br.uefs.ecomp.Game.model;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.util.LinkedList;
  6. import java.util.Scanner;
  7.  
  8. /**
  9. * Classe responsável por ler o arquivo de configuração e tratar seus dados.
  10. *
  11. * @author Daniel Andrade
  12. * @author Cássio Santos
  13. */
  14. public class ReadSettingsFile {
  15.  
  16. File file;
  17. private final Scanner read;
  18. private final int numberOfSpots;
  19. private final LinkedList<Spot> spots;
  20. private final LinkedList<Road> roads;
  21.  
  22. public ReadSettingsFile(String path) throws FileNotFoundException {
  23. file = new File(path);
  24. read = new Scanner(file);
  25. this.numberOfSpots = read.nextInt();
  26. this.spots = new LinkedList<>();
  27. this.roads = new LinkedList<>();
  28. this.generateData();
  29. }
  30.  
  31. public int getNumberOfSpots() {
  32. return this.numberOfSpots;
  33. }
  34.  
  35. /**
  36. * Faz a leitura fo arquivo e trata os dados.
  37. *
  38. * @throws FileNotFoundException
  39. */
  40. private void generateData() throws FileNotFoundException {
  41. Scanner dRead = new Scanner(this.file);
  42. dRead.useDelimiter("\\n|;|[)]|[(]|,");
  43. dRead.next();//Tira primeiro número
  44.  
  45. Spot s;
  46. //Leitura dos lugares e das coordenadas.
  47. for (int i = 0; i < this.numberOfSpots; i++) {
  48. s = new Spot(dRead.next());
  49. dRead.next();//vazio
  50. s.setX(Integer.parseInt(dRead.next()));
  51. s.setY(Integer.parseInt(dRead.next()));
  52. spots.add(s);
  53. dRead.next();//vazio
  54. }
  55.  
  56. //Lendo e adicionando origem e destino das ligações na lista
  57. while (dRead.hasNext()) {
  58. String a = dRead.next();
  59. String b = dRead.next();
  60. this.getRoads().add(new Road(a, b));
  61. }
  62.  
  63. this.read.close();
  64. dRead.close();
  65. }
  66.  
  67. public LinkedList<Spot> getSpots() {
  68. return spots;
  69. }
  70.  
  71. public LinkedList<Road> getRoads() {
  72. return roads;
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement