Class DataTableBase

java.lang.Object
io.bdeploy.common.cli.data.DataTableBase
All Implemented Interfaces:
DataTable, RenderableResult
Direct Known Subclasses:
DataTableCsv, DataTableJson, DataTableText

public abstract class DataTableBase extends Object implements DataTable
Base class for DataTable implementations.
  • Constructor Details

    • DataTableBase

      protected DataTableBase(PrintStream output)
      Parameters:
      output - the output to render to.
  • Method Details

    • out

      protected PrintStream out()
      Returns:
      the output to render to.
    • getCaption

      protected String getCaption()
      Returns:
      the set caption or null if there should be no caption.
    • getRows

      protected List<List<DataTableCell>> getRows()
      Returns:
      all currently defined data rows. Each row contains a series of cells whos accumulated span must equal the number of columns.
    • getFooters

      protected List<String> getFooters()
      Returns:
      all curreclty defined footers.
    • ellipsis

      protected String ellipsis(String data, int limit)
      Parameters:
      data - the original data
      limit - the length limit
      Returns:
      the original data limited to the given length minus 3 characters plus '...' appended.
    • expand

      protected String expand(String data, int width)
      Parameters:
      data - the original data
      width - the width to expand the string to.
      Returns:
      the original data in a string of exactly width length. The data is either filled up with spaces, or shortened according to ellipsis(String, int).
    • setCaption

      public DataTable setCaption(String caption)
      Specified by:
      setCaption in interface DataTable
      Parameters:
      caption - The caption of the table. The caption row is hidden if no caption is set.
    • setIndentHint

      public DataTable setIndentHint(int hint)
      Specified by:
      setIndentHint in interface DataTable
      Parameters:
      hint - by how much to indent the rendered table. This is just a hint and may be ignored depending on the output format.
    • setLineWrapHint

      public DataTable setLineWrapHint(boolean wrap)
      Specified by:
      setLineWrapHint in interface DataTable
      Parameters:
      wrap - whether overflow should be cut off or wrapped into an additional line in the table. This is just a hint and may be ignored depending on the output format.
    • setWordBreakHint

      public DataTable setWordBreakHint(boolean allowBreak)
      Specified by:
      setWordBreakHint in interface DataTable
      Parameters:
      allowBreak - if true breaking words apart is allowed. If false (default) breaking words is only allowed if a single word cannot fit within a column.
    • setHideHeadersHint

      public DataTable setHideHeadersHint(boolean hide)
      Specified by:
      setHideHeadersHint in interface DataTable
      Parameters:
      hide - whether to hide column headers. This is just a hint and may be ignored depending on the output format.
    • addHorizontalRuler

      public DataTable addHorizontalRuler()
      Description copied from interface: DataTable
      Add a horizontal ruler row at the current position.
      Specified by:
      addHorizontalRuler in interface DataTable
    • column

      public DataTable column(String label, int preferredWidth)
      Description copied from interface: DataTable
      Adds a column to the table. All columns must be added before adding actual data.
      Specified by:
      column in interface DataTable
      Parameters:
      label - the label of the column, used for human readable formats.
      preferredWidth - the preferred width in characters.
    • column

      public DataTable column(DataTableColumn column)
      Description copied from interface: DataTable
      Adds a column to the table. All columns must be added before adding actual data.
      Specified by:
      column in interface DataTable
      Parameters:
      column - the column definition.
    • getColumns

      public List<DataTableColumn> getColumns()
      Specified by:
      getColumns in interface DataTable
      Returns:
      all previously registered columns.
    • row

      public DataTable row(List<DataTableCell> list)
      Specified by:
      row in interface DataTable
      Parameters:
      list - a series of cells which make up a row in the table.
    • row

      public DataTableRowBuilder row()
      Description copied from interface: DataTable
      Creates a builder which will insert a row into the table when its build() method is called.
      Specified by:
      row in interface DataTable
    • addFooter

      public DataTable addFooter(String footer)
      Specified by:
      addFooter in interface DataTable
      Parameters:
      footer - a footer, e.g. a hint for a column label. Footers are only rendered in human readable formats.
    • setExitCode

      public DataTable setExitCode(ExitCode exitCode)
      Specified by:
      setExitCode in interface DataTable
      Parameters:
      exitCode - indicates whether operation was successful or had any errors.
    • getExitCode

      public ExitCode getExitCode()
      Specified by:
      getExitCode in interface RenderableResult