Package adams.data.io.output
Class AutoWidthTabularSpreadSheetWriter
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.io.output.AbstractSpreadSheetWriter
-
- adams.data.io.output.AbstractSpreadSheetWriterWithMissingValueSupport
-
- adams.data.io.output.AbstractFormattedSpreadSheetWriter
-
- adams.data.io.output.AutoWidthTabularSpreadSheetWriter
-
- All Implemented Interfaces:
AdditionalInformationHandler
,Destroyable
,GlobalInfoSupporter
,EncodingSupporter
,LoggingLevelHandler
,LoggingSupporter
,LocaleSupporter
,OptionHandlingLocaleSupporter
,OptionHandler
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,NoHeaderSpreadSheetWriter
,SpreadSheetWriter
,Serializable
public class AutoWidthTabularSpreadSheetWriter extends AbstractFormattedSpreadSheetWriter implements NoHeaderSpreadSheetWriter
Outputs the spreadsheet in a simple tabular format with column widths to fit the content in each row.
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING min-user-mode: Expert
-missing <java.lang.String> (property: missingValue) The placeholder for missing values. default:
-locale <java.util.Locale> (property: locale) The locale to use for formatting the numbers. default: Default
-number-format <java.lang.String> (property: numberFormat) The format for the numbers (see java.text.DecimalFormat), use empty string for default 'double' output. default:
-encoding <adams.core.base.BaseCharset> (property: encoding) The type of encoding to use when writing using a writer, use empty string for default. default: Default
-num-spaces <int> (property: numSpaces) The number of spaces to use between columns. default: 1 minimum: 1
-new-line <java.lang.String> (property: newLine) The newline character(s) to use for the columns; use '\r' for carriage return and '\n' for line feed; Linux/Unix use '\n', Windows uses '\r\n' and old Macs use '\r'. default: \\n
-date-format <adams.data.DateFormatString> (property: dateFormat) The format for dates. default: yyyy-MM-dd more: https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
-datetime-format <adams.data.DateFormatString> (property: dateTimeFormat) The format for date/times. default: yyyy-MM-dd HH:mm:ss more: https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
-datetimemsec-format <adams.data.DateFormatString> (property: dateTimeMsecFormat) The format for date/time msecs. default: yyyy-MM-dd HH:mm:ss.SSS more: https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
-time-format <adams.data.DateFormatString> (property: timeFormat) The format for times. default: HH:mm:ss more: https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
-no-header <boolean> (property: noHeader) If enabled, no header is output. default: false
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class adams.data.io.output.AbstractSpreadSheetWriter
AbstractSpreadSheetWriter.OutputType
-
-
Field Summary
Fields Modifier and Type Field Description protected DateFormatString
m_DateFormat
the format string for the dates.protected DateFormatString
m_DateTimeFormat
the format string for the date/times.protected DateFormatString
m_DateTimeMsecFormat
the format string for the date/times msec.protected String
m_NewLine
the new line.protected boolean
m_NoHeader
whether to skip outputting the header.protected int
m_NumSpaces
the number of spaces between columns.protected DateFormatString
m_TimeFormat
the format string for the times.-
Fields inherited from class adams.data.io.output.AbstractFormattedSpreadSheetWriter
m_Formatter, m_Locale, m_NumberFormat
-
Fields inherited from class adams.data.io.output.AbstractSpreadSheetWriterWithMissingValueSupport
m_MissingValue
-
Fields inherited from class adams.data.io.output.AbstractSpreadSheetWriter
m_Encoding, m_Stopped
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description AutoWidthTabularSpreadSheetWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
dateFormatTipText()
Returns the tip date for this property.String
dateTimeFormatTipText()
Returns the tip date/time for this property.String
dateTimeMsecFormatTipText()
Returns the tip date/time for this property.void
defineOptions()
Adds options to the internal list of options.protected int[]
determineColWidths(SpreadSheet content)
Determines the column widths.protected boolean
doWrite(SpreadSheet content, Writer writer)
Performs the actual writing.SpreadSheetReader
getCorrespondingReader()
Returns, if available, the corresponding reader.DateFormatString
getDateFormat()
Returns the format for date columns.DateFormatString
getDateTimeFormat()
Returns the format for date/time columns.DateFormatString
getDateTimeMsecFormat()
Returns the format for date/time msec columns.String
getFormatDescription()
Returns a string describing the format (used in the file chooser).String[]
getFormatExtensions()
Returns the extension(s) of the format.String
getNewLine()
Returns the string used as newline.boolean
getNoHeader()
Returns whether to use a header or not.int
getNumSpaces()
Returns the number of spaces between columns.protected AbstractSpreadSheetWriter.OutputType
getOutputType()
Returns how the data is written.DateFormatString
getTimeFormat()
Returns the format for time columns.String
globalInfo()
Returns a string describing the object.String
newLineTipText()
Returns the tip text for this property.String
noHeaderTipText()
Returns the tip text for this property.String
numSpacesTipText()
Returns the tip text for this property.protected String
pad(String s, int width, boolean leftPad)
Pads a string either on the left or the right hand side with blanks.void
setDateFormat(DateFormatString value)
Sets the format for date columns.void
setDateTimeFormat(DateFormatString value)
Sets the format for date/time columns.void
setDateTimeMsecFormat(DateFormatString value)
Sets the format for date/time msec columns.void
setNewLine(String value)
Sets the string to use as newline.void
setNoHeader(boolean value)
Sets whether to use a header or not.void
setNumSpaces(int value)
Sets the number of spaces between columns.void
setTimeFormat(DateFormatString value)
Sets the format for time columns.String
timeFormatTipText()
Returns the tip time for this property.-
Methods inherited from class adams.data.io.output.AbstractFormattedSpreadSheetWriter
format, getDefaultNumberFormat, getDefaultUseSimpleNumberFormat, getLocale, getNumberFormat, localeTipText, numberFormatTipText, setLocale, setNumberFormat
-
Methods inherited from class adams.data.io.output.AbstractSpreadSheetWriterWithMissingValueSupport
getDefaultMissingValue, getMissingValue, missingValueTipText, setMissingValue
-
Methods inherited from class adams.data.io.output.AbstractSpreadSheetWriter
canCompress, doWrite, doWrite, encodingTipText, getAdditionalInformation, getDefaultFormatExtension, getEncoding, getWriters, initialize, isStopped, preWriteFile, reset, setEncoding, stopExecution, supportsCompressedOutput, write, write, write, write
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.Destroyable
destroy
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager, toCommandLine
-
Methods inherited from interface adams.data.io.output.SpreadSheetWriter
reset, write, write, write, write
-
Methods inherited from interface adams.core.Stoppable
stopExecution
-
Methods inherited from interface adams.core.StoppableWithFeedback
isStopped
-
-
-
-
Field Detail
-
m_NumSpaces
protected int m_NumSpaces
the number of spaces between columns.
-
m_NewLine
protected String m_NewLine
the new line.
-
m_DateFormat
protected DateFormatString m_DateFormat
the format string for the dates.
-
m_DateTimeFormat
protected DateFormatString m_DateTimeFormat
the format string for the date/times.
-
m_DateTimeMsecFormat
protected DateFormatString m_DateTimeMsecFormat
the format string for the date/times msec.
-
m_TimeFormat
protected DateFormatString m_TimeFormat
the format string for the times.
-
m_NoHeader
protected boolean m_NoHeader
whether to skip outputting the header.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
getFormatDescription
public String getFormatDescription()
Returns a string describing the format (used in the file chooser).- Specified by:
getFormatDescription
in interfaceSpreadSheetWriter
- Specified by:
getFormatDescription
in classAbstractSpreadSheetWriter
- Returns:
- a description suitable for displaying in the file chooser
-
getFormatExtensions
public String[] getFormatExtensions()
Returns the extension(s) of the format.- Specified by:
getFormatExtensions
in interfaceSpreadSheetWriter
- Specified by:
getFormatExtensions
in classAbstractSpreadSheetWriter
- Returns:
- the extension (without the dot!)
-
getCorrespondingReader
public SpreadSheetReader getCorrespondingReader()
Returns, if available, the corresponding reader.- Specified by:
getCorrespondingReader
in interfaceSpreadSheetWriter
- Returns:
- the reader, null if none available
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractFormattedSpreadSheetWriter
-
setNumSpaces
public void setNumSpaces(int value)
Sets the number of spaces between columns.- Parameters:
value
- the spaces
-
getNumSpaces
public int getNumSpaces()
Returns the number of spaces between columns.- Returns:
- the spaces
-
numSpacesTipText
public String numSpacesTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setNewLine
public void setNewLine(String value)
Sets the string to use as newline.- Parameters:
value
- the character(s)
-
getNewLine
public String getNewLine()
Returns the string used as newline.- Returns:
- the character(s)
-
newLineTipText
public String newLineTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setDateFormat
public void setDateFormat(DateFormatString value)
Sets the format for date columns.- Parameters:
value
- the format
-
getDateFormat
public DateFormatString getDateFormat()
Returns the format for date columns.- Returns:
- the format
-
dateFormatTipText
public String dateFormatTipText()
Returns the tip date for this property.- Returns:
- tip date for this property suitable for displaying in the gui
-
setDateTimeFormat
public void setDateTimeFormat(DateFormatString value)
Sets the format for date/time columns.- Parameters:
value
- the format
-
getDateTimeFormat
public DateFormatString getDateTimeFormat()
Returns the format for date/time columns.- Returns:
- the format
-
dateTimeFormatTipText
public String dateTimeFormatTipText()
Returns the tip date/time for this property.- Returns:
- tip date for this property suitable for displaying in the gui
-
setDateTimeMsecFormat
public void setDateTimeMsecFormat(DateFormatString value)
Sets the format for date/time msec columns.- Parameters:
value
- the format
-
getDateTimeMsecFormat
public DateFormatString getDateTimeMsecFormat()
Returns the format for date/time msec columns.- Returns:
- the format
-
dateTimeMsecFormatTipText
public String dateTimeMsecFormatTipText()
Returns the tip date/time for this property.- Returns:
- tip date for this property suitable for displaying in the gui
-
setTimeFormat
public void setTimeFormat(DateFormatString value)
Sets the format for time columns.- Parameters:
value
- the format
-
getTimeFormat
public DateFormatString getTimeFormat()
Returns the format for time columns.- Returns:
- the format
-
timeFormatTipText
public String timeFormatTipText()
Returns the tip time for this property.- Returns:
- tip time for this property suitable for displaying in the gui
-
setNoHeader
public void setNoHeader(boolean value)
Sets whether to use a header or not.- Specified by:
setNoHeader
in interfaceNoHeaderSpreadSheetWriter
- Parameters:
value
- true if to skip header
-
getNoHeader
public boolean getNoHeader()
Returns whether to use a header or not.- Specified by:
getNoHeader
in interfaceNoHeaderSpreadSheetWriter
- Returns:
- true if no header
-
noHeaderTipText
public String noHeaderTipText()
Returns the tip text for this property.- Specified by:
noHeaderTipText
in interfaceNoHeaderSpreadSheetWriter
- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getOutputType
protected AbstractSpreadSheetWriter.OutputType getOutputType()
Returns how the data is written.- Specified by:
getOutputType
in classAbstractSpreadSheetWriter
- Returns:
- the type
-
determineColWidths
protected int[] determineColWidths(SpreadSheet content)
Determines the column widths.- Parameters:
content
- the spreadsheet to use for calculation- Returns:
- the widths
-
pad
protected String pad(String s, int width, boolean leftPad)
Pads a string either on the left or the right hand side with blanks.- Parameters:
s
- the string to padwidth
- the maximum width to pad toleftPad
- whether to pad on the left or right- Returns:
- the padded string
-
doWrite
protected boolean doWrite(SpreadSheet content, Writer writer)
Performs the actual writing. The caller must ensure that the writer gets closed.- Overrides:
doWrite
in classAbstractSpreadSheetWriter
- Parameters:
content
- the spreadsheet to writewriter
- the writer to write the spreadsheet to- Returns:
- true if successfully written
-
-