コード例 #1
0
ファイル: SoftwareBo.java プロジェクト: ezPaint/Winventory
  /**
   * Retrieves a list of Software objects narrowed down to cost range
   *
   * @param results
   * @param minCost
   * @param maxCost
   * @return List of Software objects from database (Software table)
   * @throws BoException
   */
  public List<Software> searchCostRange(List<Software> results, String minCost, String maxCost)
      throws BoException {
    List<Software> costs = new ArrayList<Software>();
    List<Software> returnedResults = new ArrayList<Software>();
    try {
      if (minCost != null && maxCost != null) costs = getListByCostRange(minCost, maxCost);

      for (Software s : results) {
        for (Software c : costs) {
          if (s.equals(c)) {
            returnedResults.add(s);
            break;
          }
        }
      }

    } catch (BoException e) {
      throw new BoException(e);
    }

    return returnedResults;
  }
コード例 #2
0
ファイル: SoftwareBo.java プロジェクト: ezPaint/Winventory
  /**
   * Searches a given list of Software objects and returns only those objects that fall within a
   * specified range of dates
   *
   * @param results the list of Software objects to be searched and refined
   * @param dates the range of dates returned objects' purchased and/or expiration date should fall
   *     within
   * @return the narrowed down list of Software objects
   * @throws BoException
   */
  public List<Software> searchDateRange(List<Software> results, ArrayList<String> dates)
      throws BoException {
    // Holds ALL software objects between date ranges
    List<Software> list = new ArrayList<Software>();

    if (dates.get(0).equals("")
        && dates.get(1).equals("")
        && dates.get(2).equals("")
        && dates.get(3).equals("")) {
      return results;
    }

    List<Software> purchased = new ArrayList<Software>();
    List<Software> expired = new ArrayList<Software>();

    // Holds software based on search constraints
    List<Software> ret = new ArrayList<Software>();

    try {
      if (dates.get(2).equals("") && dates.get(3).equals("")) {
        // if only purchased dates are entered, expired should contain
        // all values in purchased
        list = getListByPurchaseRange(Date.valueOf(dates.get(0)), Date.valueOf(dates.get(1)));

      } else if (dates.get(0).equals("") && dates.get(1).equals("")) {
        // if only expired dates are entered, purchased should contain
        // all values in expired
        list = getListByExpirationRange(Date.valueOf(dates.get(2)), Date.valueOf(dates.get(3)));

      } else {
        // otherwise, purchased should contain only dates within
        // purchased range and expired should only contain dates within
        // the expired range
        purchased = getListByPurchaseRange(Date.valueOf(dates.get(0)), Date.valueOf(dates.get(1)));
        expired = getListByExpirationRange(Date.valueOf(dates.get(2)), Date.valueOf(dates.get(3)));

        // Calculates ALL software objects within the dates 'purchased' and 'expired' (intersected
        // together)
        for (Software p : purchased) {
          for (Software e : expired) {
            if (p.compareDates(e)) {
              list.add(p);
              break;
            }
          }
        }
      }

      // Narrows down software results in 'list' to include other search constrains (in addition to
      // the dates)
      for (Software p : results) {
        for (Software e : list) {
          if (p.equals(e)) {
            ret.add(e);
            break;
          }
        }
      }

    } catch (BoException e) {
      throw new BoException(e);
    }

    return ret;
  }