io.deephaven.engine.util.HtmlTable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-engine-table Show documentation
Show all versions of deephaven-engine-table Show documentation
Engine Table: Implementation and closely-coupled utilities
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.engine.util;
import io.deephaven.engine.table.Table;
import io.deephaven.engine.table.ColumnSource;
import io.deephaven.engine.rowset.RowSet;
import io.deephaven.time.DateTimeUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.jetbrains.annotations.NotNull;
import java.time.Instant;
import java.util.Collection;
import java.util.List;
public class HtmlTable {
@NotNull
public static String html(Table source) {
List columnNames = source.getDefinition().getColumnNames();
String[] columns = columnNames.toArray(new String[columnNames.size()]);
StringBuilder out = new StringBuilder();
out.append("\n");
out.append("\n");
for (String column : columns) {
out.append("").append(column).append(" \n");
}
out.append(" \n");
final Collection extends ColumnSource> columnSources = source.getColumnSources();
for (final RowSet.Iterator ii = source.getRowSet().iterator(); ii.hasNext();) {
out.append("");
final long key = ii.nextLong();
for (ColumnSource columnSource : columnSources) {
out.append("");
final Object value = columnSource.get(key);
if (value instanceof String) {
out.append(StringEscapeUtils.escapeCsv((String) value));
} else if (value instanceof Instant) {
out.append(DateTimeUtils.formatDateTime((Instant) value, DateTimeUtils.timeZone()));
} else {
out.append(TableTools.nullToNullString(value));
}
out.append(" ");
}
out.append(" \n");
}
out.append("
\n");
return out.toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy