Exemple #1
0
 /** Load data. */
 private ArrayList loadData() {
   try {
     ArrayList vos = new ArrayList();
     BufferedReader br =
         new BufferedReader(new InputStreamReader(new FileInputStream("orders.txt")));
     String line = null;
     SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
     OrdersVO vo = null;
     String[] t = null;
     while ((line = br.readLine()) != null) {
       t = line.split(";");
       vo = new OrdersVO();
       vos.add(vo);
       vo.setOrderDate(sdf.parse(t[0]));
       vo.setCategory(t[1]);
       vo.setSubCategory(t[2]);
       vo.setCountry(t[3]);
       vo.setZone(t[4]);
       vo.setAgent(t[5]);
       vo.setItem(t[6]);
       vo.setSellQty(new BigDecimal(t[7]));
       vo.setSellAmount(new BigDecimal(t[8]));
     }
     br.close();
     return vos;
   } catch (Exception ex) {
     ex.printStackTrace();
     return new ArrayList();
   }
 }
Exemple #2
0
  /** Create data. */
  private void createData() {
    try {
      String[] categories = new String[] {"Hardware", "Software"};
      String[][] subCategories =
          new String[][] {
            {"PC", "Monitor", "Printer"},
            {"O.S.", "IDEs", "Office Appl.", "Database", "Games", "Other SW"}
          };
      String[] agents = new String[] {"Agent 1", "Agent 2", "Agent 3"};
      String[] countries = new String[] {"Italy", "France", "Germany", "Other"};
      String[][] zones =
          new String[][] {
            {"North Italy", "Center Italy", "South Italy"},
            {"Paris", "Outside Paris"},
            {"East", "West"},
            {"Iberica Peninsula", "U.K. & Ireland", "Be.Ne.Lux.", "East Europe"}
          };
      HashMap items = new HashMap();
      items.put("PC", new String[] {"Dell", "HP"});
      items.put("Monitor", new String[] {"LG", "Sony", "Philips"});
      items.put("Printer", new String[] {"HP", "Epson"});
      items.put("O.S.", new String[] {"Windows", "Linux", "Mac"});
      items.put("IDEs", new String[] {"JBuilder", "IBM RAD", "MS Visual Studio .NET"});
      items.put("Office Appl.", new String[] {"MS Office 2007", "Open Office"});
      items.put("Database", new String[] {"Oracle", "MS SQLServer", "Sybase", "IBM DB2"});
      items.put("Games", new String[] {"Need4Speed", "Fifa"});
      items.put("Other SW", new String[] {"Norton AV", "Photoshop"});

      FileOutputStream out = new FileOutputStream("orders.txt");
      String line = null;
      int i = 0;
      Calendar cal = Calendar.getInstance();
      cal.set(cal.YEAR, 2007);
      cal.set(cal.MONTH, 0);
      cal.set(cal.DAY_OF_MONTH, 1);
      cal.set(cal.HOUR_OF_DAY, 0);
      cal.set(cal.MINUTE, 0);
      cal.set(cal.SECOND, 0);
      cal.set(cal.MILLISECOND, 0);
      long t = cal.getTimeInMillis();
      SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
      String date = null;
      int maxRows = 2000000;
      String[] ii = null;
      String[] sub = null;
      String[] z = null;
      do {
        date = sdf.format(new java.util.Date(t));
        for (int k1 = 0; k1 < categories.length; k1++) {
          sub = subCategories[k1];
          for (int k2 = 0; k2 < sub.length; k2++) {
            if (i >= maxRows) break;
            for (int k3 = 0; k3 < countries.length; k3++) {
              z = zones[k3];
              for (int k4 = 0; k4 < z.length; k4++)
                for (int k5 = 0; k5 < agents.length; k5++) {
                  if (i >= maxRows) break;
                  ii = (String[]) items.get(sub[k2]);
                  for (int k6 = 0; k6 < ii.length; k6++) {
                    if (i >= maxRows) break;

                    line =
                        date
                            + ";"
                            + categories[k1]
                            + ";"
                            + sub[k2]
                            + ";"
                            + countries[k3]
                            + ";"
                            + z[k4]
                            + ";"
                            + agents[k5]
                            + ";"
                            + ii[k6]
                            + ";"
                            + new BigDecimal(Math.random() * 10)
                                .setScale(0, BigDecimal.ROUND_HALF_UP)
                            + ";"
                            + new BigDecimal(Math.random() * 1000)
                                .setScale(2, BigDecimal.ROUND_HALF_UP)
                            + ";"
                            + "\n";
                    out.write(line.getBytes());
                    out.flush();
                    i++;
                  }
                }
            }
          }
        }
        t += 86400000;
      } while (i < maxRows);
      out.close();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }