Browse Source

DataModel接口

master
richie 5 years ago
parent
commit
a8b0ca938f
  1. 28
      src/main/java/com/fanruan/api/data/open/BaseDataModel.java
  2. 18
      src/main/java/com/fanruan/api/err/TableDataException.java
  3. 32
      src/test/java/com/fanruan/api/data/open/BaseTableDataTest.java

28
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;
}

18
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);
}
}

32
src/test/java/com/fanruan/api/data/open/BaseTableDataTest.java

@ -1,13 +1,10 @@
package com.fanruan.api.data.open; package com.fanruan.api.data.open;
import com.fr.general.data.DataModel; import com.fr.general.data.DataModel;
import com.fr.measure.metric.DBMetric;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.util.Iterator;
/** /**
* @author richie * @author richie
* @version 10.0 * @version 10.0
@ -21,6 +18,10 @@ public class BaseTableDataTest {
DemoTableData tableData = new DemoTableData(); DemoTableData tableData = new DemoTableData();
DataModel model = tableData.createDataModel(calculator); DataModel model = tableData.createDataModel(calculator);
Object r = model.getValueAt(0, 0); 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); Assert.assertEquals("abc", r);
} }
@ -29,14 +30,10 @@ public class BaseTableDataTest {
@Override @Override
public DataModel createDataModel(Calculator calculator) { public DataModel createDataModel(Calculator calculator) {
return new DataModel() { return new BaseDataModel() {
@Override
public int getColumnCount() {
return 1;
}
@Override @Override
public int getColumnIndex(String s) { public int getColumnCount() {
return 1; return 1;
} }
@ -61,23 +58,8 @@ public class BaseTableDataTest {
} }
@Override @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;
} }
}; };
} }

Loading…
Cancel
Save