Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. public void readInput() {
  2.         // Leggo la linea
  3.         String line = s.nextLine();
  4.         // splitto la prima volta per il valore
  5.         String[] sub = line.split(" ");
  6.  
  7.         // splitto la seconda volta per prendere L'intero
  8.         String[] sub1 = sub[0].split("");
  9.  
  10.         boolean value;
  11.  
  12.         String number = "";
  13.  
  14.         for (int i = 1; i < sub[0].length() - 1; i++) {
  15.             number += sub1[i];
  16.         }
  17.  
  18.         Integer id = Integer.parseInt(number);
  19.  
  20.         if (sub[1].equals("True"))
  21.             value = true;
  22.         else
  23.             value = false;
  24.  
  25.         // inizializzo la radice
  26.         boolWithId root = new boolWithId(value, id);
  27.  
  28.         Node<boolWithId> N1 = new Node<boolWithId>(root);
  29.         tree.setRootElement(N1);
  30.         nodes.add(N1);
  31.  
  32.         // fin quando ha nodi in input leggo.
  33.         while (s.hasNextLine()) {
  34.  
  35.             line = s.nextLine();
  36.  
  37.             // splitto la prima volta per le singole sottostringhe
  38.             sub = line.split(" ");
  39.  
  40.             // splitto la seconda volta per prendere L'intero
  41.             sub1 = sub[0].split("");
  42.  
  43.             String number1 = "";
  44.  
  45.             for (int i = 1; i < sub[0].length() - 1; i++) {
  46.                 number1 += sub1[i];
  47.             }
  48.  
  49.             id = Integer.parseInt(number1);
  50.  
  51.             if (sub[1].equals("True"))
  52.                 value = true;
  53.             else
  54.                 value = false;
  55.  
  56.             boolWithId n = new boolWithId(value, id);
  57.             Node<boolWithId> N = new Node<boolWithId>(n);
  58.  
  59.             Integer idToAssign = Integer.parseInt(sub[3]);
  60.             nodes.add(N);
  61.  
  62.             for (Node<boolWithId> b : nodes) {
  63.                 if (b.getData().getId() == idToAssign) {
  64.  
  65.                
  66.  
  67.                     if (sub[4].equals("<"))
  68.                         b.insertChildAt(0, N);
  69.                     else if (sub[4].equals(">")) {
  70.                         if (b.getNumberOfChildren() == 0) {
  71.                             b.insertChildAt(0, N);
  72.  
  73.                         } else
  74.                             b.insertChildAt(1, N);
  75.  
  76.                     }
  77.  
  78.                 }
  79.  
  80.             }
  81.  
  82.         }
  83.  
  84.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement