Ejemplo n.º 1
0
 public static IpnbCellRaw fromCell(@NotNull final IpnbCell cell, int nbformat) {
   final IpnbCellRaw raw = new IpnbCellRaw();
   if (cell instanceof IpnbEditableCell) {
     raw.metadata = ((IpnbEditableCell) cell).getMetadata();
   }
   if (cell instanceof IpnbMarkdownCell) {
     raw.cell_type = "markdown";
     raw.source = ((IpnbMarkdownCell) cell).getSource();
   } else if (cell instanceof IpnbCodeCell) {
     raw.cell_type = "code";
     final ArrayList<CellOutputRaw> outputRaws = new ArrayList<CellOutputRaw>();
     for (IpnbOutputCell outputCell : ((IpnbCodeCell) cell).getCellOutputs()) {
       outputRaws.add(CellOutputRaw.fromOutput(outputCell, nbformat));
     }
     raw.outputs = outputRaws;
     final Integer promptNumber = ((IpnbCodeCell) cell).getPromptNumber();
     if (nbformat == 4) {
       raw.execution_count = promptNumber != null && promptNumber >= 0 ? promptNumber : null;
       raw.source = ((IpnbCodeCell) cell).getSource();
     } else {
       raw.prompt_number = promptNumber != null && promptNumber >= 0 ? promptNumber : null;
       raw.language = ((IpnbCodeCell) cell).getLanguage();
       raw.input = ((IpnbCodeCell) cell).getSource();
     }
   } else if (cell instanceof IpnbRawCell) {
     raw.cell_type = "raw";
     raw.source = ((IpnbRawCell) cell).getSource();
   } else if (cell instanceof IpnbHeadingCell) {
     raw.cell_type = "heading";
     raw.source = ((IpnbHeadingCell) cell).getSource();
     raw.level = ((IpnbHeadingCell) cell).getLevel();
   }
   return raw;
 }
Ejemplo n.º 2
0
 @Nullable
 private static ArrayList<String> getStringOrArray(String name, JsonObject object) {
   final JsonElement jsonElement = object.get(name);
   final ArrayList<String> strings = Lists.newArrayList();
   if (jsonElement == null) return null;
   if (jsonElement.isJsonArray()) {
     final JsonArray array = jsonElement.getAsJsonArray();
     for (JsonElement element : array) {
       strings.add(element.getAsString());
     }
   } else {
     strings.add(jsonElement.getAsString());
   }
   return strings;
 }