/**
   * Compute the subset of rows which should be shown on the screen. Note that the tabling
   * parameters should be set properly before this method is called!
   */
  public void computeDisplay() {
    ArrayList displayRows;
    Set temprows = new HashSet();

    // *****************
    // FILTER BY KEYWORD
    // *****************

    // the filter is considered to have been executed if the keyword filter
    // bit is on,
    // and if there is at least one keyword to search by
    boolean filterExecuted = false;

    displayRows = new ArrayList();
    if (filtered) {

      String[] keywords = null;
      if (keywordFilter != null) {
        if (keywordFilter.startsWith(" ")) {
          // the search allows the user to implement a search such as " 20 " thus
          // searching only for space char-20-space char alone, not 1920, for example
          keywords = new String[] {keywordFilter};
        } else {
          // split the keywords on a space character
          keywords = keywordFilter.split("\\s");
        }
      }

      if (keywords != null) {
        for (int j = 0; j < keywords.length; j++) {
          String keyword = keywords[j];
          if (keyword == null || "".equals(keyword)) {
            continue;
          }

          keyword = keyword.toLowerCase();

          filterExecuted = true;

          loopRows:
          for (int i = 0; i < rows.size(); i++) {
            EntityBeanRow row = (EntityBeanRow) rows.get(i);

            String searchString = row.getSearchString().toLowerCase();
            // If the keyword matches the whole search string, return a match
            if (searchString.equalsIgnoreCase(keyword)) {
              temprows.add(row);
              // continue searching the next row
              continue loopRows;
            }
            // if the searchString contains "-" chars such as ATS-120-5
            // then split the searchString on
            // that character, and determine if any components of the split result match the
            // keyword; SEE issue 2640

            if (searchString.contains("-")) {

              // The searchString is the combination of the subject's primary
              // and secondary identifiers

              // First split the search string on a space, to accomodate
              // substring searches on a search string like subject id - secondary id
              String[] newSearchString = searchString.split(" ");

              String[] subStrings = null;
              // each component is half of a string like "subject id  secondary id"
              for (String component : newSearchString) {
                // if the entire split searchString matches  the keyword...
                //  if (component.indexOf(keyword) >= 0){
                if (component.equalsIgnoreCase(keyword)) {
                  temprows.add(row);
                  // continue searching the next row
                  continue loopRows;
                }

                // if the component does contain a "-" but the entire
                // component does not match the keyword
                subStrings = component.split("-");
                for (String innerStr : subStrings) {
                  // An exact match has been requested here; see 2640
                  // This allows the breaking up of ids like ATS-120-5 and
                  // and exact seaches on the separate parts like 120
                  if (innerStr.equalsIgnoreCase(keyword)) {
                    temprows.add(row);
                  }
                }
              }
              // continue to the next row, because the searchString contained a "-",
              // and the keyword was searched for in both ways, with and without
              // splitting on "-"
              continue;
            } // end searchString.contains("-")
            // the search string doesn't contain "-"
            if (searchString.indexOf(keyword) >= 0) {
              temprows.add(row);
            }
          } // end of loop iterating over rows
        } // end of loop iterating over keywords
      }
      Iterator it = temprows.iterator();
      while (it.hasNext()) {
        displayRows.add(it.next());
      }
    } // end of filtering by keywords

    if (!filterExecuted) {
      displayRows = rows;
    }

    // this seems redundant, since we set the rows property below before
    // returning from the method
    // the reason for this call is to reset the totalNumPages property,
    // to reflect the number of rows that matched the search terms (if any)
    setRows(displayRows);

    // *************
    // SORT THE ROWS
    // *************

    for (int i = 0; i < displayRows.size(); i++) {
      EntityBeanRow row = (EntityBeanRow) displayRows.get(i);
      row.setSortingColumn(sortingColumnInd);
      row.setAscendingSort(ascendingSort);
      displayRows.set(i, row);
    }
    Collections.sort(displayRows);

    // ****************
    // APPLY PAGINATION
    // ****************
    if (paginated) {
      if (currPageNumber < 1) {
        currPageNumber = 1;
      }
      if (currPageNumber > totalPageNumbers && totalPageNumbers > 0) {
        currPageNumber = totalPageNumbers;
      }

      int firstInd = (currPageNumber - 1) * NUM_ROWS_PER_PAGE;
      int lastInd = currPageNumber * NUM_ROWS_PER_PAGE;
      lastInd = lastInd > displayRows.size() ? displayRows.size() : lastInd;

      // JRWS>> This block added to catch issue 1223, where searching a
      // large list of studies fails when search criteria result in zero
      // studies in the list, but you are on the third page of the list
      // when you perform the search
      if (firstInd > lastInd && lastInd == 0) {
        firstInd = 0;
      }

      ArrayList currPage = new ArrayList(displayRows.subList(firstInd, lastInd));

      // it's important not to use setRows here
      // calling setRows will change totalNumPages to be the number of
      // pages in currPage (always 1)
      // we don't want to change totalNumPages since it'll screw up the
      // display of "Previous" and "Next" page links
      rows = currPage;
    } else {
      rows = displayRows;
    }
  }
  /**
   * Compute the subset of rows which should be shown on the screen. Note that the tabling
   * parameters should be set properly before this method is called!
   */
  public void computeDisplay() {
    ArrayList displayRows;
    Set temprows = new HashSet();

    // *****************
    // FILTER BY KEYWORD
    // *****************

    // the filter is considered to have been executed if the keyword filter
    // bit is on,
    // and if there is at least one keyword to search by
    boolean filterExecuted = false;

    displayRows = new ArrayList();
    if (filtered) {
      String[] keywords = keywordFilter.split("\\s");

      if (keywords != null) {
        for (int j = 0; j < keywords.length; j++) {
          String keyword = keywords[j];
          if (keyword == null || "".equals(keyword)) {
            continue;
          }

          keyword = keyword.toLowerCase();

          filterExecuted = true;

          for (int i = 0; i < rows.size(); i++) {
            EntityBeanRow row = (EntityBeanRow) rows.get(i);

            String searchString = row.getSearchString().toLowerCase();

            if (searchString.indexOf(keyword) >= 0) {
              temprows.add(row);
            }
          } // end of loop iterating over rows
        } // end of loop iterating over keywords
      }
      Iterator it = temprows.iterator();
      while (it.hasNext()) {
        displayRows.add(it.next());
      }
    } // end of filtering by keywords

    if (!filterExecuted) {
      displayRows = rows;
    }

    // this seems redundant, since we set the rows property below before
    // returning from the method
    // the reason for this call is to reset the totalNumPages property,
    // to reflect the number of rows that matched the search terms (if any)
    setRows(displayRows);

    // *************
    // SORT THE ROWS
    // *************

    for (int i = 0; i < displayRows.size(); i++) {
      EntityBeanRow row = (EntityBeanRow) displayRows.get(i);
      row.setSortingColumn(sortingColumnInd);
      row.setAscendingSort(ascendingSort);
      displayRows.set(i, row);
    }
    Collections.sort(displayRows);

    // ****************
    // APPLY PAGINATION
    // ****************
    if (paginated) {
      if (currPageNumber < 1) {
        currPageNumber = 1;
      }
      if (currPageNumber > totalPageNumbers && totalPageNumbers > 0) {
        currPageNumber = totalPageNumbers;
      }

      int firstInd = (currPageNumber - 1) * NUM_ROWS_PER_PAGE;
      int lastInd = currPageNumber * NUM_ROWS_PER_PAGE;
      lastInd = lastInd > displayRows.size() ? displayRows.size() : lastInd;

      // JRWS>> This block added to catch issue 1223, where searching a
      // large list of studies fails when search criteria result in zero
      // studies in the list, but you are on the third page of the list
      // when you perform the search
      if (firstInd > lastInd && lastInd == 0) {
        firstInd = 0;
      }

      ArrayList currPage = new ArrayList(displayRows.subList(firstInd, lastInd));

      // it's important not to use setRows here
      // calling setRows will change totalNumPages to be the number of
      // pages in currPage (always 1)
      // we don't want to change totalNumPages since it'll screw up the
      // display of "Previous" and "Next" page links
      rows = currPage;
    } else {
      rows = displayRows;
    }
  }