Exemple #1
0
  public static void ImportPortfolios(String filename, Map<String, Portfolio> pss)
      throws IOException, ParseException {
    // String filename = "ExportedPortfolios.txt";
    BufferedReader br = new BufferedReader(new FileReader(filename));
    String line = "";
    while ((line = br.readLine()) != null) {
      List<String> strings = Arrays.asList(line.split("\\|"));
      // System.out.println(strings.get(0)+" "+strings.get(1));
      String name = strings.get(0);
      String pass = decrypt(strings.get(1));

      users.put(name, pass);
      Map<String, Integer> equitie = new HashMap<String, Integer>();
      Map<String, Account> Accountt = new HashMap<String, Account>();
      List<Transaction> trans = new ArrayList<Transaction>();

      for (int i = 2; i < strings.size(); i++) {
        String s = strings.get(i);
        String[] lst = s.split(",");
        if (lst.length >= 3) {
          if (lst[0].equals("e")) {
            equitie.put(lst[1], Integer.parseInt(lst[2]));
          } else if (lst[0].equals("a")) {
            SimpleDateFormat sdf =
                new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
            Date d = sdf.parse(lst[5]);
            Account ac =
                new Account(lst[1], lst[2], Float.parseFloat(lst[3]), Float.parseFloat(lst[4]), d);
            Accountt.put(lst[2], ac);
          } else if (lst[0].equals("t")) {
            SimpleDateFormat sdf =
                new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
            Date d = sdf.parse(lst[4]);
            trans.add(new Transaction(lst[1], lst[2], Float.parseFloat(lst[3]), d));
          } else if (lst[0].equals("b")) {
            SimpleDateFormat sdf =
                new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
            Date d = sdf.parse(lst[4]);
            trans.add(
                new Transaction(
                    lst[0], sEquities.get(lst[1]), Integer.parseInt(lst[2]), lst[3], d));
          }
        }
      }
      Portfolio p = new Portfolio(name, equitie, Accountt);
      p.setTrans(trans);
      pss.put(name, p);
    }
  }