示例#1
0
 @Test
 public void saveRow() {
   Row row = new Row(5);
   row.setCell(0, new Cell("I'm not empty", null));
   row.save(writer, options);
   Assert.assertEquals(
       writer.getBuffer().toString(),
       "{\"flagged\":false,\"starred\":false,\"cells\":[{\"v\":\"I'm not empty\"}]}");
 }
示例#2
0
 @Test
 public void saveRowWithRecordIndex() {
   Row row = new Row(5);
   row.setCell(0, new Cell("I'm not empty", null));
   when(options.containsKey("rowIndex")).thenReturn(true);
   when(options.get("rowIndex")).thenReturn(0);
   when(options.containsKey("recordIndex")).thenReturn(true);
   when(options.get("recordIndex")).thenReturn(1);
   row.save(writer, options);
   Assert.assertEquals(
       writer.getBuffer().toString(),
       "{\"flagged\":false,\"starred\":false,\"cells\":[{\"v\":\"I'm not empty\"}],\"i\":0,\"j\":1}");
 }
  @Override
  public void save(Writer writer, Properties options) throws IOException {
    writer.write("baseColumnName=");
    writer.write(_baseColumnName);
    writer.write('\n');
    writer.write("columnInsertIndex=");
    writer.write(Integer.toString(_columnInsertIndex));
    writer.write('\n');
    writer.write("columnNameCount=");
    writer.write(Integer.toString(_columnNames.size()));
    writer.write('\n');
    for (String name : _columnNames) {
      writer.write(name);
      writer.write('\n');
    }
    writer.write("columnTypeCount=");
    writer.write(Integer.toString(_columnTypes.size()));
    writer.write('\n');
    for (DBpediaType type : _columnTypes) {
      try {
        JSONWriter jsonWriter = new JSONWriter(writer);

        type.write(jsonWriter, options);
      } catch (JSONException e) {
        // ???
      }
      writer.write('\n');
    }
    writer.write("rowIndexCount=");
    writer.write(Integer.toString(_rowIndices.size()));
    writer.write('\n');
    for (Integer rowIndex : _rowIndices) {
      writer.write(rowIndex.toString());
      writer.write('\n');
    }
    writer.write("dataExtensionCount=");
    writer.write(Integer.toString(_dataExtensions.size()));
    writer.write('\n');
    for (DataExtension dataExtension : _dataExtensions) {
      if (dataExtension == null) {
        writer.write('\n');
        continue;
      }

      writer.write(Integer.toString(dataExtension.data.length));
      writer.write('\n');

      for (Object[] values : dataExtension.data) {
        for (Object value : values) {
          if (value == null) {
            writer.write("null");
          } else if (value instanceof ReconCandidate) {
            try {
              JSONWriter jsonWriter = new JSONWriter(writer);
              ((ReconCandidate) value).write(jsonWriter, options);
            } catch (JSONException e) {
              // ???
            }
          } else if (value instanceof String) {
            writer.write(JSONObject.quote((String) value));
          } else {
            writer.write(value.toString());
          }
          writer.write('\n');
        }
      }
    }

    writer.write("firstNewCellIndex=");
    writer.write(Integer.toString(_firstNewCellIndex));
    writer.write('\n');

    writer.write("newRowCount=");
    writer.write(Integer.toString(_newRows.size()));
    writer.write('\n');
    for (Row row : _newRows) {
      row.save(writer, options);
      writer.write('\n');
    }
    writer.write("oldRowCount=");
    writer.write(Integer.toString(_oldRows.size()));
    writer.write('\n');
    for (Row row : _oldRows) {
      row.save(writer, options);
      writer.write('\n');
    }
    writer.write("/ec/\n"); // end of change marker
  }