Package com.unboundid.util
Class ColumnFormatter
- java.lang.Object
-
- com.unboundid.util.ColumnFormatter
-
- All Implemented Interfaces:
java.io.Serializable
@NotMutable @ThreadSafety(level=NOT_THREADSAFE) public final class ColumnFormatter extends java.lang.Object implements java.io.Serializable
This class provides a utility for formatting output in multiple columns. Each column will have a defined width and alignment. It can alternately generate output as tab-delimited text or comma-separated values (CSV).- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ColumnFormatter(boolean includeTimestamp, java.lang.String timestampFormat, OutputFormat outputFormat, java.lang.String spacer, FormattableColumn... columns)Creates a column formatter that will format the provided columns.ColumnFormatter(FormattableColumn... columns)Creates a column formatter that will format the provided columns with the default settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringformatRow(java.lang.Object... columnData)Formats a row of data.FormattableColumn[]getColumns()Retrieves the set of columns for this formatter.java.lang.String[]getHeaderLines(boolean includeDashes)Obtains the lines that should comprise the column headers.OutputFormatgetOutputFormat()Retrieves the output format that will be used.java.lang.StringgetSpacer()Retrieves the spacer that will be used between columns.java.lang.StringgetTimestampFormatString()Retrieves the format string that will be used for generating timestamps.booleanincludeTimestamps()Indicates whether timestamps will be included in the output.
-
-
-
Constructor Detail
-
ColumnFormatter
public ColumnFormatter(@NotNull FormattableColumn... columns)
Creates a column formatter that will format the provided columns with the default settings.- Parameters:
columns- The columns to be formatted. At least one column must be provided.
-
ColumnFormatter
public ColumnFormatter(boolean includeTimestamp, @Nullable java.lang.String timestampFormat, @Nullable OutputFormat outputFormat, @Nullable java.lang.String spacer, @NotNull FormattableColumn... columns)
Creates a column formatter that will format the provided columns.- Parameters:
includeTimestamp- Indicates whether to insert a timestamp before the first column when generating data linestimestampFormat- The format string to use for the timestamp. It may benullif no timestamp should be included or the default format should be used. If a format is provided, then it should be one that will always generate timestamps with a constant width.outputFormat- The output format to use.spacer- The spacer to use between columns. It may benullif the default spacer should be used. This will only apply for an output format ofCOLUMNS.columns- The columns to be formatted. At least one column must be provided.
-
-
Method Detail
-
includeTimestamps
public boolean includeTimestamps()
Indicates whether timestamps will be included in the output.- Returns:
trueif timestamps should be included, orfalseif not.
-
getTimestampFormatString
@NotNull public java.lang.String getTimestampFormatString()
Retrieves the format string that will be used for generating timestamps.- Returns:
- The format string that will be used for generating timestamps.
-
getOutputFormat
@NotNull public OutputFormat getOutputFormat()
Retrieves the output format that will be used.- Returns:
- The output format for this formatter.
-
getSpacer
@NotNull public java.lang.String getSpacer()
Retrieves the spacer that will be used between columns.- Returns:
- The spacer that will be used between columns.
-
getColumns
@NotNull public FormattableColumn[] getColumns()
Retrieves the set of columns for this formatter.- Returns:
- The set of columns for this formatter.
-
getHeaderLines
@NotNull public java.lang.String[] getHeaderLines(boolean includeDashes)
Obtains the lines that should comprise the column headers.- Parameters:
includeDashes- Indicates whether to include a row of dashes below the headers if appropriate for the output format.- Returns:
- The lines that should comprise the column headers.
-
formatRow
@NotNull public java.lang.String formatRow(@NotNull java.lang.Object... columnData)
Formats a row of data. The provided data must correspond to the columns used when creating this formatter.- Parameters:
columnData- The elements to include in each row of the data.- Returns:
- A string containing the formatted row.
-
-