DynamicTableModel extends TableModel { @Override public TableModelIterator getIterator(RectF tableRect, int totalElements) { return new TableModelIterator(this, tableRect, totalElements); } DynamicTableModel(int numColumns, int numRows);  DynamicTableModel(int numColumns, int numRows, TableOrder order); @Override TableModelIterator getIterator(RectF tableRect, int totalElements); RectF getCellRect(RectF tableRect, int numElements); int getNumRows(); void setNumRows(int numRows); int getNumColumns(); void setNumColumns(int numColumns);  }
@Test public void testIterator() throws Exception { TableModel model = new DynamicTableModel(2, 2); RectF tableRect = new RectF(0, 0, 1000, 2000); Iterator<RectF> it = model.getIterator(tableRect, 10); int iterations = 0; while(it.hasNext()) { it.next(); iterations++; } assertEquals(4, iterations); model = new DynamicTableModel(2, 0); it = model.getIterator(tableRect, 10); iterations = 0; while(it.hasNext()) { it.next(); iterations++; } assertEquals(10, iterations); }
@Test public void testRowMajorIteration() throws Exception { TableModel model = new DynamicTableModel(2, 2); RectF tableRect = new RectF(0, 0, 1000, 2000); int createdCells = 4; Iterator<RectF> it = model.getIterator(tableRect, createdCells); RectF cellRect = it.next(); assertEquals(500f, cellRect.width()); assertEquals(1000f, cellRect.height()); assertEquals(0f, cellRect.left); assertEquals(0f, cellRect.top); assertEquals(500f, cellRect.right); assertEquals(1000f, cellRect.bottom); cellRect = it.next(); assertEquals(500f, cellRect.width()); assertEquals(1000f, cellRect.height()); assertEquals(500f, cellRect.left); assertEquals(0f, cellRect.top); assertEquals(1000f, cellRect.right); assertEquals(1000f, cellRect.bottom); cellRect = it.next(); assertEquals(500f, cellRect.width()); assertEquals(1000f, cellRect.height()); assertEquals(0f, cellRect.left); assertEquals(1000f, cellRect.top); assertEquals(500f, cellRect.right); assertEquals(2000f, cellRect.bottom); cellRect = it.next(); assertEquals(500f, cellRect.width()); assertEquals(1000f, cellRect.height()); assertEquals(500f, cellRect.left); assertEquals(1000f, cellRect.top); assertEquals(1000f, cellRect.right); assertEquals(2000f, cellRect.bottom); }
@Test public void testColumnMajorIteration() throws Exception { TableModel model = new DynamicTableModel(2, 2, TableOrder.COLUMN_MAJOR); RectF tableRect = new RectF(0, 0, 1000, 2000); int createdCells = 4; Iterator<RectF> it = model.getIterator(tableRect, createdCells); RectF cellRect = it.next(); assertEquals(500f, cellRect.width()); assertEquals(1000f, cellRect.height()); assertEquals(0f, cellRect.left); assertEquals(0f, cellRect.top); assertEquals(500f, cellRect.right); assertEquals(1000f, cellRect.bottom); cellRect = it.next(); assertEquals(500f, cellRect.width()); assertEquals(1000f, cellRect.height()); assertEquals(0f, cellRect.left); assertEquals(1000f, cellRect.top); assertEquals(500f, cellRect.right); assertEquals(2000f, cellRect.bottom); cellRect = it.next(); assertEquals(500f, cellRect.width()); assertEquals(1000f, cellRect.height()); assertEquals(500f, cellRect.left); assertEquals(0f, cellRect.top); assertEquals(1000f, cellRect.right); assertEquals(1000f, cellRect.bottom); cellRect = it.next(); assertEquals(500f, cellRect.width()); assertEquals(1000f, cellRect.height()); assertEquals(500f, cellRect.left); assertEquals(1000f, cellRect.top); assertEquals(1000f, cellRect.right); assertEquals(2000f, cellRect.bottom); }
@Test public void testSingleRowIteration() throws Exception { TableModel model = new DynamicTableModel(0, 1); RectF tableRect = new RectF(0, 0, 1000, 1000); int createdCells = 4; Iterator<RectF> it = model.getIterator(tableRect, createdCells); RectF cellRect = it.next(); assertEquals(250f, cellRect.width()); assertEquals(1000f, cellRect.height()); assertEquals(0f, cellRect.left); assertEquals(0f, cellRect.top); assertEquals(250f, cellRect.right); assertEquals(1000f, cellRect.bottom); cellRect = it.next(); assertEquals(250f, cellRect.width()); assertEquals(1000f, cellRect.height()); assertEquals(250f, cellRect.left); assertEquals(0f, cellRect.top); assertEquals(500f, cellRect.right); assertEquals(1000f, cellRect.bottom); cellRect = it.next(); assertEquals(250f, cellRect.width()); assertEquals(1000f, cellRect.height()); assertEquals(500f, cellRect.left); assertEquals(0f, cellRect.top); assertEquals(750f, cellRect.right); assertEquals(1000f, cellRect.bottom); cellRect = it.next(); assertEquals(250f, cellRect.width()); assertEquals(1000f, cellRect.height()); assertEquals(750f, cellRect.left); assertEquals(0f, cellRect.top); assertEquals(1000f, cellRect.right); assertEquals(1000f, cellRect.bottom); }