All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.bdeploy.common.cli.data.DataTableJson Maven / Gradle / Ivy

Go to download

Public API including dependencies, ready to be used for integrations and plugins.

There is a newer version: 7.3.6
Show newest version
package io.bdeploy.common.cli.data;

import java.io.PrintStream;
import java.util.List;

public class DataTableJson extends DataTableBase {

    DataTableJson(PrintStream output) {
        super(output);
    }

    @Override
    public void render() {
        out().println("[");

        for (int i = 0; i < getRows().size(); ++i) {
            List row = getRows().get(i);

            out().print("  { ");

            int colIndex = 0;
            for (int y = 0; y < row.size(); ++y) {
                DataTableColumn col = getColumns().get(colIndex);

                out().print(quote(col.getName()) + ": " + quote(row.get(y).data));

                if (y == (row.size() - 1)) {
                    if (i == (getRows().size() - 1)) {
                        out().println(" }");
                    } else {
                        out().println(" },");
                    }
                } else {
                    out().print(", ");
                }

                colIndex += row.get(y).span;
            }
        }

        out().println("]");
    }

    static String quote(String data) {
        return "\"" + data.replace("\"", "\\\"").replace("\n", "\\n").replace("\\", "\\\\") + "\"";
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy