forked from fanruan/finekit
richie
5 years ago
2 changed files with 149 additions and 0 deletions
@ -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); |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
}; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue