Esempio n. 1
0
  public String getLegend(String[] cityMap, int[] POIs) {
    char[] ans = new char[POIs.length];

    Hashtable hash = new Hashtable();

    for (int i = 0; i < cityMap.length; i++) {
      for (int j = 0; j < cityMap[i].length(); j++) {
        char cur = cityMap[i].charAt(j);
        int k = 1;
        if (!hash.containsKey(cur)) {
          hash.put(cur, k);
        } else {
          int prev = (int) hash.get(cur);
          hash.remove(cur);
          hash.put(cur, prev + 1);
        }
      }
    }

    Enumeration vals = hash.keys();
    while (vals.hasMoreElements()) {
      char c = (char) vals.nextElement();

      for (int i = 0; i < POIs.length; i++) {
        if (hash.get(c) == POIs[i]) {
          ans[i] = c;
        }
      }
    }

    String str = new String(ans);

    return str;
  }
  // -------------------------------------------
  public static String[] mergeArrays(String[] sa1, String[] sa2) {
    if (sa1 == null) {
      sa1 = new String[0];
    }
    if (sa2 == null) {
      sa2 = new String[0];
    }
    int sa1Len = sa1.length;
    int sa2Len = sa2.length;
    Hashtable tab = new Hashtable(sa1Len + sa2Len);
    for (int i = 0; i < sa1Len; i++) {
      tab.put(sa1[i], sa1[i]);
    }
    for (int i = 0; i < sa2Len; i++) {
      tab.put(sa2[i], sa2[i]);
    }

    int len = tab.size();
    String[] res = new String[len];
    int i = 0;
    for (Enumeration e = tab.keys(); e.hasMoreElements(); ) {
      String s = (String) e.nextElement();
      res[i++] = s;
    }
    return res;
  }
  /**
   * This Method returns the 2D Array which is the list of the Items for the selected WorkOrder of
   * the Customer.
   *
   * @param workorderId - WorkOrder Id Foreign Key of WRK_ORDR_DETS table
   * @return Object[][] - 2D Array which is List of the Items for the WorkOrder
   */
  public Object[][] getWorkOrderItems(long workorderId) throws RemoteException {

    WrkOrdrDets wrkordrdts_obj = new WrkOrdrDets(conn);

    RHCCBlgKeys blgkeys_obj = new RHCCBlgKeys(conn);

    Vector workorderdetList = wrkordrdts_obj.getProductList(workorderId);

    // Hashtable BSysList = (Hashtable) USFEnv.getBillSystems();
    BlgSys blgsys = new BlgSys();

    Hashtable BSysList = (Hashtable) blgsys.searchBlgSys();

    Enumeration BSys = BSysList.keys();

    // The 2-Dimensional array to hold the Items Billing System wise.
    Object[][] prodList = new Object[BSysList.size()][workorderdetList.size() + 1];

    // The Number of Billing Systems are assumed to be equal to the
    // Static Load Billing Systems Hashtable size. The Billing Systems will
    // be in order starting from 1 and incrementing by one.
    for (int i = 0; i < BSysList.size(); i++) {
      // Set the 2D array to store the Billing System as the first element
      // of each row.
      prodList[i][0] = String.valueOf(i + 1);
    }

    // Loop throught the WorkOrder Items List and place them in the appropriate
    // positions in the 2D array.
    for (int j = 0; j < workorderdetList.size(); j++) {
      // Determine the Billing System of the Product
      Vector tmpVector = new Vector();

      WrkOrdrDets workorderObj = (WrkOrdrDets) workorderdetList.elementAt(j);

      RHCCBlgKeys bkObj =
          blgkeys_obj.searchRHCCBlgKeys(((WrkOrdrDets) workorderdetList.elementAt(j)).getRBKID());
      int bsid = (new Long(bkObj.getBsId())).intValue();

      tmpVector.addElement(bkObj);
      tmpVector.addElement(workorderObj);

      // Based on the Billing System Id retreived place the Product Object
      // in the 2D array.
      int k = 1;
      while (prodList[bsid - 1][k] != null) {
        k = k + 1;
      }
      prodList[bsid - 1][k] = tmpVector;
    }

    // Return the 2D array
    return prodList;
  }
  static void writeUsersToFile() {
    userWriter = createCSVFile("Users.dat");
    // write the list of users to file
    System.out.println("Users that are both seller and buyer BUT different ratings: ");
    Enumeration<String> keys = userList.keys();
    while (keys.hasMoreElements()) {
      String curUserID = keys.nextElement();
      String curUser[] = userList.get(curUserID);
      String userRow =
          wrapQuotations(curUser[0])
              + ","
              + curUser[1]
              + ","
              + curUser[2]
              + ","
              + wrapQuotations(curUser[3])
              + ","
              + wrapQuotations(curUser[4]);
      writeLine(userWriter, userRow);
      // if(curUser[1] != null && curUser[2] != null && !curUser[1].equals(curUser[2]))
      //    System.out.println(curUser[0]);
    }
    System.out.println("----end different ratings----");

    // System.out.println("The users that are both seller and buyer: ");
    // Enumeration<String> both = bothSellerAndBuyer.elements();
    // while(both.hasMoreElements()) {
    //    System.out.println(both.nextElement());
    // }
    // System.out.println("----end both----");

    try {
      userWriter.flush();
      userWriter.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }