From a8b0ca938f5eb2891d86c812c4b80102e1c5688e Mon Sep 17 00:00:00 2001 From: richie Date: Wed, 4 Sep 2019 10:10:43 +0800 Subject: [PATCH] =?UTF-8?q?DataModel=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fanruan/api/data/open/BaseDataModel.java | 28 ++++++++++++++++ .../fanruan/api/err/TableDataException.java | 18 +++++++++++ .../api/data/open/BaseTableDataTest.java | 32 ++++--------------- 3 files changed, 53 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/fanruan/api/data/open/BaseDataModel.java create mode 100644 src/main/java/com/fanruan/api/err/TableDataException.java diff --git a/src/main/java/com/fanruan/api/data/open/BaseDataModel.java b/src/main/java/com/fanruan/api/data/open/BaseDataModel.java new file mode 100644 index 0000000..3a03e3f --- /dev/null +++ b/src/main/java/com/fanruan/api/data/open/BaseDataModel.java @@ -0,0 +1,28 @@ +package com.fanruan.api.data.open; + +import com.fanruan.api.err.TableDataException; +import com.fr.data.AbstractDataModel; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-09-04 + * 二维表模型 + */ +public abstract class BaseDataModel extends AbstractDataModel { + + @Override + public abstract int getColumnCount() throws TableDataException; + + @Override + public abstract String getColumnName(int rowIndex) throws TableDataException; + + @Override + public abstract int getRowCount() throws TableDataException; + + @Override + public abstract Object getValueAt(int rowIndex, int columnIndex) throws TableDataException; + + @Override + public abstract void release() throws Exception; +} diff --git a/src/main/java/com/fanruan/api/err/TableDataException.java b/src/main/java/com/fanruan/api/err/TableDataException.java new file mode 100644 index 0000000..690c1b2 --- /dev/null +++ b/src/main/java/com/fanruan/api/err/TableDataException.java @@ -0,0 +1,18 @@ +package com.fanruan.api.err; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-09-04 + * 数据集异常 + */ +public class TableDataException extends com.fr.general.data.TableDataException { + + public TableDataException(String s) { + super(s); + } + + public TableDataException(String s, Throwable throwable) { + super(s, throwable); + } +} diff --git a/src/test/java/com/fanruan/api/data/open/BaseTableDataTest.java b/src/test/java/com/fanruan/api/data/open/BaseTableDataTest.java index 9d2891a..a979832 100644 --- a/src/test/java/com/fanruan/api/data/open/BaseTableDataTest.java +++ b/src/test/java/com/fanruan/api/data/open/BaseTableDataTest.java @@ -1,13 +1,10 @@ package com.fanruan.api.data.open; import com.fr.general.data.DataModel; -import com.fr.measure.metric.DBMetric; import com.fr.script.Calculator; import org.junit.Assert; import org.junit.Test; -import java.util.Iterator; - /** * @author richie * @version 10.0 @@ -21,6 +18,10 @@ public class BaseTableDataTest { DemoTableData tableData = new DemoTableData(); DataModel model = tableData.createDataModel(calculator); Object r = model.getValueAt(0, 0); + Assert.assertTrue(model.hasRow(0)); + Assert.assertFalse(model.hasRow(1)); + Assert.assertEquals(1, model.getColumnCount()); + Assert.assertEquals(1, model.getRowCount()); Assert.assertEquals("abc", r); } @@ -29,14 +30,10 @@ public class BaseTableDataTest { @Override public DataModel createDataModel(Calculator calculator) { - return new DataModel() { - @Override - public int getColumnCount() { - return 1; - } + return new BaseDataModel() { @Override - public int getColumnIndex(String s) { + public int getColumnCount() { return 1; } @@ -61,23 +58,8 @@ public class BaseTableDataTest { } @Override - public void release() { - - } + public void release() throws Exception { - @Override - public Iterator getDataIterator() { - return null; - } - - @Override - public Object getIteratorDataByColumn(Object o, int i) { - return null; - } - - @Override - public DBMetric getMetric() { - return null; } }; }