Package org.moeaframework.util.format
Class TabularData<T>
java.lang.Object
org.moeaframework.util.format.TabularData<T>
- Type Parameters:
T
- the type of records (rows)
- All Implemented Interfaces:
Displayable
Formats and displays tabular data.
-
Constructor Summary
ConstructorDescriptionTabularData
(Iterable<T> dataSource) Creates a new tabular data object using the given data source. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a column to this data.void
addFormatter
(Formatter<?> formatter) Adds a formatter.void
display
(PrintStream out) Displays the contents of this object to the given output stream.protected String
Reads the value of the specified column and formats it as a string.protected String
formatValue
(Object value) Formats the value using the default formatter, if available, or withObject.toString()
.void
Removes any existing formatters.void
Saves the data to a CSV file.void
Writes the data formatted as CSV.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.moeaframework.util.format.Displayable
display
-
Constructor Details
-
TabularData
Creates a new tabular data object using the given data source.- Parameters:
dataSource
- the source of data
-
-
Method Details
-
addFormatter
Adds a formatter. This will be used to format any values matching the formatter's type (seeFormatter.getType()
.- Parameters:
formatter
- the default formatter
-
removeAllFormatters
public void removeAllFormatters()Removes any existing formatters. -
addColumn
Adds a column to this data. The columns will be displayed in the order they are added.- Parameters:
column
- the column
-
format
Reads the value of the specified column and formats it as a string.- Parameters:
row
- the record (row) to read fromcolumn
- the column to read from- Returns:
- the formatted value
-
formatValue
Formats the value using the default formatter, if available, or withObject.toString()
.- Parameters:
value
- the value to format- Returns:
- the formatted value
-
display
Description copied from interface:Displayable
Displays the contents of this object to the given output stream. This method does not close the underlying stream; the caller is responsible for disposing it.- Specified by:
display
in interfaceDisplayable
- Parameters:
out
- the output stream
-
saveCSV
Saves the data to a CSV file.- Parameters:
file
- the resulting file- Throws:
IOException
- if an I/O error occurred while writing the file
-
toCSV
Writes the data formatted as CSV.- Parameters:
out
- the output writer- Throws:
IOException
- if an I/O error occurred while writing the data
-