ProfileDataTableModel extends AbstractTableModel implements CsvEncoder { public String toCsv() { StringWriter sw = new StringWriter(); try { encodeCsv(sw); sw.close(); } catch (IOException e) { throw new IllegalStateException(e); } return sw.toString(); } ProfileDataTableModel(String sampleName,
                                 TransectProfileData profileData,
                                 ProfilePlotPanel.DataSourceConfig dataSourceConfig); @Override int getColumnCount(); @Override String getColumnName(int column); @Override int getRowCount(); @Override Object getValueAt(int row, int column); @Override boolean isCellEditable(int rowIndex, int columnIndex); String toCsv(); @Override void encodeCsv(Writer writer);  }
@Test public void testModelCsv() throws Exception { TransectProfileData profileData = new TransectProfileDataBuilder() .raster(band) .path(path) .boxSize(dataSourceConfig.boxSize) .build(); ProfileDataTableModel tableModel = new ProfileDataTableModel(band.getName(), profileData, dataSourceConfig); String csv = tableModel.toCsv(); assertEquals("pixel_no\tpixel_x\tpixel_y\tlatitude\tlongitude\tb_mean\tb_sigma\tdata_ref\tlat_ref\tlon_ref\n" + "1\t0.0\t0.0\t\t\t0.1\t0.0\t0.3\t0\t0\n" + "2\t1.0\t0.0\t\t\t1.1\t0.0\t\t\t\n" + "3\t2.0\t0.0\t\t\t2.1\t0.0\t\t\t\n" + "4\t3.0\t0.0\t\t\t3.1\t0.0\t0.5\t0\t0\n" + "5\t2.0\t1.0\t\t\t6.1\t0.0\t\t\t\n" + "6\t1.0\t2.0\t\t\t9.1\t0.0\t\t\t\n" + "7\t0.0\t3.0\t\t\t12.1\t0.0\t0.7\t0\t0\n" + "8\t1.0\t3.0\t\t\t13.1\t0.0\t\t\t\n" + "9\t2.0\t3.0\t\t\t14.1\t0.0\t\t\t\n" + "10\t3.0\t3.0\t\t\t15.1\t0.0\t0.1\t0\t0\n", csv); }
@Test public void testModelCsvNoInBetweenPoints() throws Exception { dataSourceConfig.computeInBetweenPoints = false; TransectProfileData profileData = new TransectProfileDataBuilder() .raster(band) .path(path) .boxSize(dataSourceConfig.boxSize) .build(); ProfileDataTableModel tableModel = new ProfileDataTableModel(band.getName(), profileData, dataSourceConfig); String csv = tableModel.toCsv(); assertEquals("pixel_no\tpixel_x\tpixel_y\tlatitude\tlongitude\tb_mean\tb_sigma\tdata_ref\tlat_ref\tlon_ref\n" + "1\t0.0\t0.0\t\t\t0.1\t0.0\t0.3\t0\t0\n" + "4\t3.0\t0.0\t\t\t3.1\t0.0\t0.5\t0\t0\n" + "7\t0.0\t3.0\t\t\t12.1\t0.0\t0.7\t0\t0\n" + "10\t3.0\t3.0\t\t\t15.1\t0.0\t0.1\t0\t0\n", csv); }