📄 datalist.java
字号:
/*
*********************************************************************
* 文件 : $Workfile: DataList.java $
* 项目 : 腾龙1.2
* 公司 : 沈阳东软软件股份有限公司
* 日期 : $Date: 03-12-10 18:18 $
* 说明 :
**********************************************************************
* 版本历史:
* $Log: /4 开发工作目录/src/com/neusoft/dbmanager/DataList.java $
*
* 1 03-12-10 18:18 Lihg
*
* 1 03-12-10 8:44 Lihg
*********************************************************************
*/
package com.neusoft.dbmanager;
import java.util.*;
/**
* 用于描述查询结果对象
*
*@author <a href="mailto:lihg@neusoft.com">李红国</a>
*@created 2003年5月19日
*/
public class DataList {
/**
* 空页对象描述
*/
public final static DataList EMPTY_PAGE =
new DataList(Collections.EMPTY_LIST, 0, 0, 0);
List objects;
int startIndex;
int containingListSize;
int perPage;
int colsize;
/**
* 构造对象 DataList
*
*@param l 参数描述
*@param perPage 参数描述
*/
public DataList(List l, int perPage) {
objects = new ArrayList(l);
this.perPage = perPage;
}
/**
* 构造对象 DataList
*
*@param l 参数描述
*@param perPage 参数描述
*@param colsize 参数描述
*/
public DataList(List l, int perPage, int colsize) {
objects = new ArrayList(l);
this.perPage = perPage;
this.colsize = colsize;
}
/**
* 构造对象 DataList
*
*@param l 记录结果列表
*@param s 起始记录数
*@param cls 记录总个数
*@param count 每页显示个数
*/
public DataList(List l, int s, int cls, int count) {
objects = new ArrayList(l);
startIndex = s;
containingListSize = cls;
perPage = count;
}
public DataList( int s, int cls, int count) {
startIndex = s;
System.out.println("first----startIndex"+s);
containingListSize = cls;
perPage = count;
}
/**
* 方法描述
*
*@param i 参数描述
*@return 描述返回值信息
*/
public Item get(int i) {
return (Item) objects.get(i);
}
/**
* 方法描述
*
*@param i 参数描述
*@return 描述返回值信息
*/
public String[] getColName() {
String[] colname = null;
if (getLength() > 0) {
colname = ( (Item) objects.get(0)).getColName();
}
return colname;
}
/**
* 取得对应行和列的结果
*
*@param row 行数
*@param col 列数
*@return 描述返回值信息
*/
public String get(int row, int col) {
return ( (Item) objects.get(row)).getValue(col);
}
/**
* 取得对应行数和列名的结果
*
*@param row 行数
*@param colname 列名
*@return 描述返回值信息
*/
public String get(int row, String colname) {
return ( (Item) objects.get(row)).getValue(colname);
}
/**
* 取得对应行数和列名的结果
*
*@param row 行数
*@param colname 列名
*@return 描述返回值信息
*/
public void delete(int row) {
objects.remove(row);
}
/**
* 取得 DataList object 的属性list
*
*@return 属性 list的值
*/
public List getList() {
return objects;
}
/**
* 方法描述
*
*@return 描述返回值信息
*/
public boolean hasNextPage() {
System.out.println("hasNextPage=startIndex="+startIndex);
//return (startIndex + objects.size()) < containingListSize;
return (startIndex + perPage) < containingListSize;
}
/**
* 方法描述
*
*@return 描述返回值信息
*/
public boolean hasPreviousPage() {
System.out.println("hasPreviousPage=startIndex="+startIndex);
return startIndex > 0;
}
public boolean getHasPreviousPage() {
return hasPreviousPage();
}
public boolean getHasNextPage() {
return hasNextPage();
}
/**
* 取得 DataList object 的属性startOfNextPage
*
*@return 属性 startOfNextPage的值
*/
public int getFirstPage() {
return 0;
}
/**
* 取得 DataList object 的属性startOfNextPage
*
*@return 属性 startOfNextPage的值
*/
public int getLastPage() {
int residue = 0;
int result = 0;
if (containingListSize == 0) {
result = 0;
}
else {
residue = containingListSize % perPage;
if (residue == 0) {
result = (containingListSize / perPage - 1) * perPage;
}
else {
result = containingListSize / perPage * perPage;
}
}
return result;
}
/**
* 取得 DataList object 的属性startOfNextPage
*
*@return 属性 startOfNextPage的值
*/
public int getStartOfNextPage() {
//return start + objects.size();
int count=startIndex+perPage;
System.out.println("##################startIndex="+startIndex);
System.out.println("##################startIndex+perPage="+count);
return startIndex+perPage;
}
/**
* 取得 DataList object 的属性startOfPreviousPage
*
*@return 属性 startOfPreviousPage的值
*/
public int getStartOfPreviousPage() {
System.out.println("##################startIndex="+startIndex);
System.out.println("##################startIndex-perPage="+Math.max(startIndex - perPage, 0));
return Math.max(startIndex - perPage, 0);
}
/**
* 取得每页显示个数
*
*@return 属性 size的值
*/
public int getSize() {
return perPage;
}
/**
* 数据的实际个数
*
*@return 属性 length的值
*/
public int getLength() {
return objects.size();
}
/**
* 数据记录总数
*
*@return 属性 length的值
*/
public int getStart() {
return startIndex;
}
/**
* 数据记录总数
*
*@return 属性 length的值
*/
public int getTotal() {
return containingListSize;
}
/**
* 字段个数
*
*@return 属性 length的值
*/
public int getColSize() {
return colsize;
}
/**
* 取得总页数
* @return 属性 总页数
*/
public int getAllPageCount() {
if (containingListSize == 0) {
return 1;
}
return (containingListSize / perPage +
( (containingListSize % perPage) > 0 ? (1) : (0)));
}
/**
* 取得总页数
* @return 属性 总页数
*/
public int getPerPageCount() {
int realPerPage=perPage;
int curPage=this.getNowPage();
int pageCount=this.getAllPageCount();
if(curPage==pageCount){
realPerPage=containingListSize-perPage*(curPage-1);
}
return realPerPage;
}
/**
* 取得当前页
* @return 属性 当前页
*/
public int getNowPage() {
if (startIndex == 0) {
return 1;
}
return (startIndex / perPage + 1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -