⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagebypage.java

📁 Oracle的J2EE Sample
💻 JAVA
字号:
/*
 * @author  : Pushkala
 * @version : 1.0
 *
 * Development Environment : Oracle9i JDeveloper
 *
 * Name of the File : PageByPage.java
 *
 * Creation / Modification History
 *    Pushkala        05-Jul-2002        Created
 *
 */
package oracle.otnsamples.ibfbs.trademanagement.ejb;

// Utility imports
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * This class is called from TradeManagementSessionFacadeBean
 * to return a mini collection of specified number of records
 *
 * @version 1.0
 * @since   1.0
 */
public class PageByPage {

  /** Has Previous records */
  private boolean hasPrev = true;

  /** Has Next records */
  private boolean hasNext = true;

  /**
   * Default empty constructor
   * @since 1.0
   */
  public PageByPage() {}

  /**
   * This method returns the value of hasPrev as a String
   *
   * @return The String value of hasPrev
   * @since 1.0
   */
  public String hasPrevRecords() {
    if (hasPrev)
      return "true";
    else
      return "false";
  }

  /**
   * This method returns the value of hasNext as a String
   *
   * @return The String value of hasNext
   * @since 1.0
   */
  public String hasNextRecords() {
    if (hasNext)
      return "true";
    else
      return "false";
  }

  /**
   * This method takes an input List and with the input record number
   * and the lines per page, creates a new mini Collection and returns
   * it to the calling method. This helps in restricting the number
   * of records returned to the client program.
   *
   * @param allRecords   List of all the records
   * @param recNum       Record Number
   * @param linesPerPage Number of Lines Per Page
   * @return The Mini Collection of records
   * @since 1.0
   */
  public Collection getCollection(List allRecords,
                                  String recNum,
                                  int linesPerPage) {
    Collection miniSet     = null;           // Instantiate a mini Collection
    int        recordNum   = Integer.parseInt(recNum);  // Record Number
    int        firstRecord = recordNum - 1;  // Start with input record number

    // If we are at the first record, no Previous records,
    // so set the boolean variable accordingly
    if (firstRecord == 0) {
      hasPrev = false;
    } else {
      hasPrev = true;
    }

    // Last record number is first record +
    // The Number of lines to be displayed per page
    int lastRecord = firstRecord + linesPerPage;

    if (lastRecord >= allRecords.size()) {
      lastRecord = allRecords.size();
      hasNext = false;
    } else {
      hasNext = true;
    }

    // Create the mini collection with subset of elements from the input List
    miniSet = new ArrayList(allRecords.subList(firstRecord, lastRecord));
    // The above method adds the elements with firstRecord Inclusive
    // and lastRecord Exclusive

    // Return the mini collection
    return miniSet;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -