From 006d6465f8fbec9b1988c064cd3f0b707eded3db Mon Sep 17 00:00:00 2001 From: richie Date: Wed, 4 Sep 2019 09:58:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3+=E5=8D=95=E5=85=83=E6=B5=8B=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