FlatRowConverter { public static com.google.cloud.bigtable.data.v2.models.Row convertToModelRow(FlatRow row) { if (row == null || row.getCells() == null) { return null; } ImmutableList.Builder<RowCell> rowCellList = ImmutableList.builderWithExpectedSize(row.getCells().size()); for (FlatRow.Cell cell : row.getCells()) { rowCellList.add(toRowCell(cell)); } return com.google.cloud.bigtable.data.v2.models.Row.create( row.getRowKey(), rowCellList.build()); }  static Row convert(FlatRow row); static com.google.cloud.bigtable.data.v2.models.Row convertToModelRow(FlatRow row);  }
@Test public void testModelRowWithOneCell() { FlatRow.Cell cell = new FlatRow.Cell("family", toByteString("column"), 500, toByteString("value"), null); FlatRow flatRow = FlatRow.newBuilder().withRowKey(toByteString("key")).addCell(cell).build(); com.google.cloud.bigtable.data.v2.models.Row expectedRow = com.google.cloud.bigtable.data.v2.models.Row.create( flatRow.getRowKey(), Arrays.asList( RowCell.create( cell.getFamily(), cell.getQualifier(), cell.getTimestamp(), cell.getLabels(), cell.getValue()))); Assert.assertEquals(expectedRow, FlatRowConverter.convertToModelRow(flatRow)); }
@Test public void testModelRowWithMultipleCell() { FlatRow simpleRow = FlatRow.newBuilder() .withRowKey(toByteString("key")) .addCell("family1", toByteString("column"), 500, toByteString("value"), null) .addCell("family1", toByteString("column2"), 500, toByteString("value"), null) .addCell("family1", toByteString("column2"), 400, toByteString("value"), null) .addCell("family2", toByteString("column"), 500, toByteString("value"), null) .build(); List<RowCell> rowCells = new ArrayList<>(); for (FlatRow.Cell cell : simpleRow.getCells()) { rowCells.add( RowCell.create( cell.getFamily(), cell.getQualifier(), cell.getTimestamp(), cell.getLabels(), cell.getValue())); } com.google.cloud.bigtable.data.v2.models.Row row = com.google.cloud.bigtable.data.v2.models.Row.create( ByteString.copyFromUtf8("key"), rowCells); Assert.assertEquals(row, FlatRowConverter.convertToModelRow(simpleRow)); }