From 006d6465f8fbec9b1988c064cd3f0b707eded3db Mon Sep 17 00:00:00 2001 From: richie Date: Wed, 4 Sep 2019 09:58:01 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=8E=A5=E5=8F=A3+=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fanruan/api/data/open/BaseTableData.java | 63 ++++++++++++++ .../api/data/open/BaseTableDataTest.java | 86 +++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 src/main/java/com/fanruan/api/data/open/BaseTableData.java create mode 100644 src/test/java/com/fanruan/api/data/open/BaseTableDataTest.java diff --git a/src/main/java/com/fanruan/api/data/open/BaseTableData.java b/src/main/java/com/fanruan/api/data/open/BaseTableData.java new file mode 100644 index 0000000..9a50356 --- /dev/null +++ b/src/main/java/com/fanruan/api/data/open/BaseTableData.java @@ -0,0 +1,63 @@ +package com.fanruan.api.data.open; + +import com.fr.data.AbstractParameterTableData; +import com.fr.general.data.DataModel; +import com.fr.script.Calculator; +import com.fr.stable.ParameterProvider; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-09-04 + * 插件的数据集接口 + */ +public abstract class BaseTableData extends AbstractParameterTableData { + + /** + * 实现这个方法来返回一个数据集 + * + * @param calculator 算子 + * @return 数据集二维表对象 + */ + @Override + public abstract DataModel createDataModel(Calculator calculator); + + /** + * 返回获取数据的执行对象 + * 系统取数时,调用此方法来返回一个获取数据的执行对象 + * 注意! 当数据集需要根据不同参数来多次取数时,此方法在一个计算过程中会被多次调用。 + * + * @param calculator 算子 + * @param rowCount 要获取数据的行数 + * @return 数据集二维表对象 + */ + @Override + public DataModel createDataModel(Calculator calculator, int rowCount) { + return createDataModel(calculator); + } + + /** + * 返回获取数据的执行对象 + * 系统取数时,调用此方法来返回一个获取数据的执行对象 + * 注意! 当数据集需要根据不同参数来多次取数时,此方法在一个计算过程中会被多次调用。 + * + * @param calculator 算子 + * @param name 数据集的名字 + * @return 数据集二维表对象 + */ + @Override + public DataModel createDataModel(Calculator calculator, String name) { + return createDataModel(calculator); + } + + /** + * 获取数据集中定义的参数 + * + * @param calculator 算子 + * @return 参数数组 + */ + @Override + public ParameterProvider[] getParameters(Calculator calculator) { + return super.getParameters(calculator); + } +} diff --git a/src/test/java/com/fanruan/api/data/open/BaseTableDataTest.java b/src/test/java/com/fanruan/api/data/open/BaseTableDataTest.java new file mode 100644 index 0000000..978179b --- /dev/null +++ b/src/test/java/com/fanruan/api/data/open/BaseTableDataTest.java @@ -0,0 +1,86 @@ +package com.fanruan.api.data.open; + +import com.fr.general.data.DataModel; +import com.fr.general.data.TableDataException; +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 + * Created by richie on 2019-09-04 + */ +public class BaseTableDataTest { + + @Test + public void testCreate() throws Exception { + Calculator calculator = Calculator.createCalculator(); + DemoTableData tableData = new DemoTableData(); + DataModel model = tableData.createDataModel(calculator); + Object r = model.getValueAt(0, 0); + Assert.assertEquals("abc", r); + } + + + private static class DemoTableData extends BaseTableData { + + @Override + public DataModel createDataModel(Calculator calculator) { + return new DataModel() { + @Override + public int getColumnCount() throws TableDataException { + return 1; + } + + @Override + public int getColumnIndex(String s) throws TableDataException { + return 1; + } + + @Override + public String getColumnName(int i) throws TableDataException { + return "test"; + } + + @Override + public boolean hasRow(int i) throws TableDataException { + return i < 1; + } + + @Override + public int getRowCount() throws TableDataException { + return 1; + } + + @Override + public Object getValueAt(int i, int i1) throws TableDataException { + return "abc"; + } + + @Override + 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; + } + }; + } + } +} \ No newline at end of file From b331e15152f54fceaed207433d6c1088f790fdbf Mon Sep 17 00:00:00 2001 From: richie Date: Wed, 4 Sep 2019 09:58:46 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/data/open/BaseTableDataTest.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) 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 978179b..9d2891a 100644 --- a/src/test/java/com/fanruan/api/data/open/BaseTableDataTest.java +++ b/src/test/java/com/fanruan/api/data/open/BaseTableDataTest.java @@ -1,7 +1,6 @@ package com.fanruan.api.data.open; import com.fr.general.data.DataModel; -import com.fr.general.data.TableDataException; import com.fr.measure.metric.DBMetric; import com.fr.script.Calculator; import org.junit.Assert; @@ -21,7 +20,7 @@ public class BaseTableDataTest { Calculator calculator = Calculator.createCalculator(); DemoTableData tableData = new DemoTableData(); DataModel model = tableData.createDataModel(calculator); - Object r = model.getValueAt(0, 0); + Object r = model.getValueAt(0, 0); Assert.assertEquals("abc", r); } @@ -32,37 +31,37 @@ public class BaseTableDataTest { public DataModel createDataModel(Calculator calculator) { return new DataModel() { @Override - public int getColumnCount() throws TableDataException { + public int getColumnCount() { return 1; } @Override - public int getColumnIndex(String s) throws TableDataException { + public int getColumnIndex(String s) { return 1; } @Override - public String getColumnName(int i) throws TableDataException { + public String getColumnName(int i) { return "test"; } @Override - public boolean hasRow(int i) throws TableDataException { + public boolean hasRow(int i) { return i < 1; } @Override - public int getRowCount() throws TableDataException { + public int getRowCount() { return 1; } @Override - public Object getValueAt(int i, int i1) throws TableDataException { + public Object getValueAt(int i, int i1) { return "abc"; } @Override - public void release() throws Exception { + public void release() { } From a8b0ca938f5eb2891d86c812c4b80102e1c5688e Mon Sep 17 00:00:00 2001 From: richie Date: Wed, 4 Sep 2019 10:10:43 +0800 Subject: [PATCH 3/4] =?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; } }; } From 3cd1ab9d03dfa68e22aacb71a159e938910eda24 Mon Sep 17 00:00:00 2001 From: richie Date: Wed, 4 Sep 2019 10:15:22 +0800 Subject: [PATCH 4/4] =?UTF-8?q?javadoc=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 | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/main/java/com/fanruan/api/data/open/BaseDataModel.java b/src/main/java/com/fanruan/api/data/open/BaseDataModel.java index 3a03e3f..0b25818 100644 --- a/src/main/java/com/fanruan/api/data/open/BaseDataModel.java +++ b/src/main/java/com/fanruan/api/data/open/BaseDataModel.java @@ -11,18 +11,50 @@ import com.fr.data.AbstractDataModel; */ public abstract class BaseDataModel extends AbstractDataModel { + /** + * 获取数据集的列数 + * + * @return 列数 + * @throws TableDataException 如果获取数据集列数失败,则抛出此异常 + */ @Override public abstract int getColumnCount() throws TableDataException; + /** + * 获取数据集指定列的列名 + * + * @param rowIndex 列序号 + * @return 类名 + * @throws TableDataException 如果获取列名失败,则抛出此异常 + */ @Override public abstract String getColumnName(int rowIndex) throws TableDataException; + /** + * 湖区数据集的行数 + * + * @return 行数 + * @throws TableDataException 如果获取数据集行数失败,则抛出此异常 + */ @Override public abstract int getRowCount() throws TableDataException; + /** + * 获取数据集中指定位置的值 + * + * @param rowIndex 行 + * @param columnIndex 列 + * @return 值 + * @throws TableDataException 如果获取值失败,则抛出此异常 + */ @Override public abstract Object getValueAt(int rowIndex, int columnIndex) throws TableDataException; + /** + * 释放一些构建数据集过程中占用的资源 + * + * @throws Exception 释放资源时发生错误则抛出此异常 + */ @Override public abstract void release() throws Exception; }