Guest User

Untitled

a guest
Apr 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. package org.eda.practica03.ejercicio01;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileReader;
  7. import java.io.FileWriter;
  8. import java.io.IOException;
  9. import java.io.PrintWriter;
  10. import java.util.StringTokenizer;
  11. import java.util.TreeMap;
  12.  
  13. import org.eda.estructurasdatos.Iterator;
  14.  
  15. public class ProcesarDirecciones {
  16.  
  17. private TreeMap<String,TreeMap<String,Integer>> ips = new TreeMap<String,TreeMap<String,Integer>> ();
  18.  
  19.  
  20. public ProcesarDirecciones() {
  21. super();
  22. this.ips = ips;
  23. }
  24.  
  25. public void cargarArchivo(String archivoEntrada) {
  26. try {
  27. File txt = new File(archivoEntrada);
  28. FileReader fr = new FileReader(txt);
  29. BufferedReader in = new BufferedReader(fr);
  30. String aux, aux2[], direccion, maq;
  31. while ((aux = in.readLine()) != null) {
  32. aux2=troceador(aux);
  33. direccion = aux2[0];
  34. maq = aux2[1];
  35. TreeMap<String,Integer> maqContador = new TreeMap<String,Integer>();
  36. maqContador.put(maq, 1);
  37. if(ips.containsKey(direccion)){
  38. if(ips.get(direccion).containsKey(maq)){
  39. Integer contador=ips.get(direccion).get(maq);
  40. contador++;
  41. ips.get(direccion).put(maq, contador);
  42. }
  43. else{
  44. ips.get(direccion).put(maq, new Integer(1));
  45. }
  46. }
  47. else{
  48. ips.put(direccion, maqContador);
  49. }
  50. }} catch (FileNotFoundException e1) {
  51. // TODO Auto-generated catch block
  52. e1.printStackTrace();
  53. } catch (IOException e) {
  54. // TODO Auto-generated catch block
  55. e.printStackTrace();
  56. }
  57.  
  58.  
  59. }
  60.  
  61. public int tamano() {
  62.  
  63. return ips.size();
  64. }
  65.  
  66. public void generarDirecciones(String archivoSalida) {
  67. FileWriter txt = new FileWriter(archivoSalida);
  68. PrintWriter writer = new PrintWriter(txt);
  69. Iterator<String,TreeMap<String,Integer>> it = ips.keySet().iterator();
  70. for()
  71. }
  72.  
  73. public void generarIncidencias(String archivoSalida) {
  74. // TODO Auto-generated method stub
  75.  
  76. }
  77. private static String[] troceador(String linea) {
  78. StringTokenizer b = new StringTokenizer(linea);
  79. int j = 0;
  80. String z[] = new String[2];
  81. while (b.hasMoreTokens()) {
  82. z[j] = b.nextToken(" ");
  83. j++;
  84. }
  85. return z;
  86. }
  87.  
  88. }
Add Comment
Please, Sign In to add comment