Browse Source
* 'master' of https://cloud.finedevelop.com/scm/~zhaojunzhe/finekit: javadoc接口 DataModel接口 去掉异常 数据集插件接口+单元测试 # Conflicts: # src/main/java/com/fanruan/api/err/TableDataException.javapull/19/head
zjz1993
5 years ago
4 changed files with 201 additions and 7 deletions
@ -0,0 +1,60 @@
|
||||
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 { |
||||
|
||||
/** |
||||
* 获取数据集的列数 |
||||
* |
||||
* @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; |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -1,14 +1,18 @@
|
||||
package com.fanruan.api.err; |
||||
|
||||
/** |
||||
* 和数据集工具有关的异常 |
||||
* */ |
||||
public class TableDataException extends com.fr.general.data.TableDataException{ |
||||
public TableDataException(String msg){ |
||||
super(msg); |
||||
* @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 msg, Throwable error){ |
||||
super(msg, error); |
||||
public TableDataException(String s, Throwable throwable) { |
||||
super(s, throwable); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,67 @@
|
||||
package com.fanruan.api.data.open; |
||||
|
||||
import com.fr.general.data.DataModel; |
||||
import com.fr.script.Calculator; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
/** |
||||
* @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.assertTrue(model.hasRow(0)); |
||||
Assert.assertFalse(model.hasRow(1)); |
||||
Assert.assertEquals(1, model.getColumnCount()); |
||||
Assert.assertEquals(1, model.getRowCount()); |
||||
Assert.assertEquals("abc", r); |
||||
} |
||||
|
||||
|
||||
private static class DemoTableData extends BaseTableData { |
||||
|
||||
@Override |
||||
public DataModel createDataModel(Calculator calculator) { |
||||
return new BaseDataModel() { |
||||
|
||||
@Override |
||||
public int getColumnCount() { |
||||
return 1; |
||||
} |
||||
|
||||
@Override |
||||
public String getColumnName(int i) { |
||||
return "test"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean hasRow(int i) { |
||||
return i < 1; |
||||
} |
||||
|
||||
@Override |
||||
public int getRowCount() { |
||||
return 1; |
||||
} |
||||
|
||||
@Override |
||||
public Object getValueAt(int i, int i1) { |
||||
return "abc"; |
||||
} |
||||
|
||||
@Override |
||||
public void release() throws Exception { |
||||
|
||||
} |
||||
}; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue