1: import java.util.ArrayList;

2: import java.util.List;

3:

6:

7: public final class DataTable {

8:

9: private DataRowCollection rows; //用于保存DataRow的集合对象

10: private DataColumnCollection columns; //用于保存DataColumn的对象

11: private String tableName; //表名

12: private boolean readOnly = false;

13: private int nextRowIndex = 0;

14: private DataExpression dataExpression;

15: private Object tag;

16:

17: public DataTable() {

18: this.columns = new DataColumnCollection();

19: this.rows = new DataRowCollection();

20: this.rows.setColumns(columns);

21: dataExpression = new DataExpression(this);

22: }

23:

24: public DataTable(String dataTableName) {

25: this();

26: this.tableName = dataTableName;

27: }

28:

29: public int getTotalCount() {

30: return rows.size();

31: }

32:

33: public boolean isReadOnly() {

34: return this.readOnly;

35: }

36:

37: public void setReadOnly(boolean readOnly) {

38: this.readOnly = readOnly;

39: }

40:

41: /**

42: * 功能描述: 返回表名

43: * @param

44: */

45: public String getTableName() {

46: return this.tableName;

47: }

48:

49: /**

50: * 功能描述: 设置表名

51: * @param

52: */

53: public void setTableName(String tableName) {

54: this.tableName = tableName;

55: }

56:

57: /**

58: * 功能描述: 返回该表引用的封装类

59: * @param

60: * @return: DataRowCollection

61: */

62: public DataRowCollection getRows() {

63: return this.rows;

64: }

65:

66: public DataColumnCollection getColumns() {

67: return this.columns;

68: }

69:

70: /**

71: * 功能描述: 获取指定行指定列的数据

72: * @param

73: * @return: Object

74: */

75:

76: public Object getValue(int row,

77: String colName) {

78: return this.rows.get(row).getValue(colName);

79: }

80:

81: public Object getValue(int row,

82: int col) {

83: return this.rows.get(row).getValue(col);

84: }

85:

86: /**

87: * 功能描述: 为该表数据新建一行

88: * @param

89: * @return: DataRow

90: */

91: public DataRow newRow() throws Exception {

92: DataRow tempRow = new DataRow(this);

93: nextRowIndex = nextRowIndex < this.rows.size() ? this.rows.size()

94: : nextRowIndex;

95: tempRow.setColumns(this.columns);

96: tempRow.setRowIndex(nextRowIndex++);

97: return tempRow;

98: }

99:

100: public void setValue(int row,

101: int col,

102: Object value) {

103: this.rows.get(row).setValue(col, value);

104: }

105:

106: public void setValue(int row,

107: String colName,

108: Object value) {

109: this.rows.get(row).setValue(colName, value);

110: }

111:

112: /**

113: * @param tag

114: */

115: public void setTag(Object tag) {

116: this.tag = tag;

117: }

118:

119: /**

120: * @return the tag

121: */

122: public Object getTag() {

123: return tag;

124: }

125:

126: public DataColumn addColumn(String columnName,

127: int dataType) throws Exception {

128: return this.columns.addColumn(columnName, dataType);

129: }

130:

131: public boolean addRow(DataRow row) throws Exception {

132: if (row.getRowIndex() > this.rows.size())

133: row.setRowIndex(this.rows.size());

134: return this.rows.add(row);

135: }

136:

137: //以下为数据表扩展方法实现集合

138: /**

139: * 功能描述: 返回符合过滤条件的数据行集合,并返回

140: * @param

141: * @return: DataTable

142: */

143: public List select(String filterString) {

144: List rows = new ArrayList();

145: if (StringUtil.isNotEmpty(filterString)) {

146: for (Object row : this.rows) {

147: DataRow currentRow = (DataRow) row;

148: if ((Boolean) dataExpression.compute(filterString,

149: currentRow.getItemMap())) {

150: rows.add(currentRow);

151: }

152: }

153: return rows;

154: } else {

155: return this.rows;

156: }

157: }

158:

159: /**

160: * 功能描述: 对当前表进行查询 过滤,并返回指定列集合拼装的DataTable对象

161: * @param

162: * @return: DataTable

163: */

164: public DataTable select(String filterString,

165: String[] columns,

166: boolean distinct) throws Exception {

167: DataTable result = new DataTable();

168: List rows = select(filterString);

169: //构造表结构

170: for (String c : columns) {

171: DataColumn dc = this.columns.get(c);

172: DataColumn newDc = new DataColumn(dc.getColumnName(),

173: dc.getDataType());

174: newDc.setCaptionName(dc.getCaptionName());

175: result.columns.add(newDc);

176: }

177: //填充数据

178: for (DataRow r : rows) {

179: DataRow newRow = result.newRow();

180: newRow.copyFrom(r);

181: result.addRow(newRow);

182: }

183: return result;

184: }

185:

186: public DataTable select(String tableName,

187: String selectField,

188: String filterString,

189: String groupField) {

190: DataTable result = new DataTable();

191: //

192: return result;

193: }

194:

195: /**

196: * 功能描述: 根据指定表达式对符合过滤条件的数据进行计算

197: * @param

198: * @return: Object

199: * @author: James Cheung

200: * @version: 2.0

201: */

202: public Object compute(String expression,

203: String filter) {

204: return dataExpression.compute(expression, select(filter));

205: }

206:

207: public Object max(String columns,

208: String filter) {

209: return null;

210: }

211:

212: public Object min(String columns,

213: String filter) {

214: return null;

215: }

216:

217: public Object avg(String columns,

218: String filter) {

219: return null;

220: }

221:

222: public Object max(String columns,

223: String filter,

224: String groupBy) {

225: return null;

226: }

227:

228: public Object min(String columns,

229: String filter,

230: String groupBy) {

231: return null;

232: }

233:

234: public Object avg(String columns,

235: String filter,

236: String groupBy) {

237: return null;

238: }

239:

240: private List getColumns(String colString) {

241: List columns = new ArrayList();

242:

243: return columns;

244: }

245: }

java返回datatable_(转)在JAVA实现DataTable对象(三)——DataTable对象实现相关推荐

  1. java返回datatable_在Java中实现.net中DataTable功能以及操作双数据库的List连接问题解决方案探究...

    前两天实现了net中DataTable功能,虽说功能不是很强大,但是完全满足了java中的多表查询,带来的编程风格改变还是存在的. 现在拿出来说下,和各位大哥探讨下. 因为我本来就是搞net的,突然来 ...

  2. java 返回js_如何基于java或js获取URL返回状态码

    这篇文章主要介绍了如何基于java或js获取URL返回状态码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参fgLAeaGAH考下 描述:使用java或者 ...

  3. java返回有什么用,java中的return this什么时候用,返回的是类里面的方法类型,还是实例类?上面的代码什么意思...

    java中的return this什么时候用,返回的是类里面的方法类型,还是实例类??下面的代码什么意思? public class RoleService extends BaseService { ...

  4. java返回列表_从Java 8中的方法返回列表?

    看起来你只需要元素的总和来检查它是奇数还是偶数.要知道这一点,就足以检查奇数元素的数量是奇数还是偶数. 您可以将输入拆分为奇数和偶数列表,并根据奇数列表的大小决定返回哪一个: public stati ...

  5. java 返回空数组_避免在Java中检查Null语句

    1.概述 通常,在Java代码中处理null变量.引用和集合很棘手.它们不仅难以识别,而且处理起来也很复杂.事实上,在编译时无法识别处理null的任何错误,会导致运行时NullPointerExcep ...

  6. java.lang.Runtime.availableProcessors返回可用处理器的Java虚拟机的数量

    1. java.lang.Runtime.availableProcessors()方法实例 java.lang.Runtime.availableProcessors() 方法返回可用处理器的Jav ...

  7. java返回图片base64_java将图片转为base64返回给前端

    本文实例为大家分享了java将图片转为base64返回给前端的具体代码,供大家参考,具体内容如下 一.controller端代码 @RequestMapping(value = "/capt ...

  8. java 拼html页面返回,java返回html标签

    java返回html标签 [2021-02-03 19:08:44]  简介: php删除html标签的方法:可以利用strip_tags函数来进行删除,如[strip_tags("Hell ...

  9. java 返回 json格式_java 如何返回json格式数据,需要技巧

    今天上午给同事调了半个小时的程序,最后发现是在后台代码的java返回json格式的数据出了个错误.因此就想到了广大的初学者一开始学习jquery的时候可能会遇到这个问题.现在我就把我的给大家分享一下, ...

最新文章

  1. 你会不会用mysql查询近7个月的数据?没有记录默认为空
  2. OpenStack AMQP与kombu
  3. windows缩放200模糊_1.8M超轻量目标检测模型NanoDet,比YOLO跑得快,上线两天Star量超200...
  4. HDU 4635(强连通分量分解
  5. 容器编排技术 -- Kubernetes kubectl create rolebinding 命令详解
  6. 重读 CenterNet,一个在Github有5.2K星标的目标检测算法
  7. .Net与 WebAssembly 随笔
  8. JavaScript 复习之 XMLHttpRequest 对象
  9. linux命令 选项,不点之Linux命令、选项及文件概念
  10. 入行GIS圈N年,看看资深GISer如何进行场景绘制?
  11. 斐波那契堆(Fibonacci heap)原理详解
  12. linux 内网ip扫描工具,C#开发:局域网IP地址扫描小工具
  13. abaqus 录制结果动画_录制和编辑动画 | Adobe Character Animator 教程
  14. 使用docker部署Nexus
  15. <math.h>中sin cos函数的用法
  16. QQ好友分组模拟小程序
  17. Github上重现DeepMind星际争霸强化学习算法的代码调试与问题
  18. c井语言python_【一点资讯】C井风靡一时的编程语言和现在最火编程语言Python!谁更强? www.yidianzixun.com...
  19. 信噪比SNR、符号信噪比Es/N0与比特信噪比Eb/N0的关系
  20. UltraEdit软件列模式的一些使用技巧

热门文章

  1. 2020年12月国产数据库排行:榜首TiDB 2.7亿融资再破纪录;openGauss晋级十强!
  2. 嘉年华回顾丨 周正中(德哥)谈谈PG怎么这么火
  3. 想了解Webpack,看这篇就够了
  4. 实践分享丨物联网操作系统中的任务管理
  5. 【深度学习系列】卷积神经网络CNN原理详解(一)——基本原理(1)
  6. ServiceComb java-chassis和CSE java-chassis的区别
  7. pve安装黑群晖直通硬盘_蜗牛星际装机教程篇三:手把手教你安装黑群晖NAS
  8. Sublime中查找重复行的正则表达式
  9. 【numpy】numpy.ones()函数
  10. NameError: name ‘__file__‘ is not defined的问题原因及解决方法