Package adams.data.conversion
Class TransposeSpreadSheet
-
- All Implemented Interfaces:
AdditionalInformationHandler
,CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,QuickInfoSupporter
,ShallowCopySupporter<AbstractConversion>
,SizeOfHandler
,Stoppable
,Conversion
,Serializable
public class TransposeSpreadSheet extends AbstractSpreadSheetConversion
Transposes a spreadsheet, i.e., swaps columns with rows.
Valid options are:
-D <int> (property: debugLevel) The greater the number the more additional info the scheme may output to the console (0 = off). default: 0 minimum: 0
-use-header-as-first-column (property: useHeaderAsFirstColumn) Whether to use the current header as first column.
-use-first-column-as-header (property: useFirstColumnAsHeader) Whether to use the first column as new header.
-column-prefix <java.lang.String> (property: columnPrefix) The column prefix for the new columns if the first column is not used for the header; 1-based column index is appended. default: col-
- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected String
m_ColumnPrefix
the column prefix if the first column is not used as header.protected boolean
m_UseFirstColumnAsHeader
whether to use the first column as header.protected boolean
m_UseHeaderAsFirstColumn
whether to add the header row as first column.-
Fields inherited from class adams.data.conversion.AbstractConversion
m_Input, m_Output, m_Owner, 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 TransposeSpreadSheet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
columnPrefixTipText()
Returns the tip text for this property.protected SpreadSheet
convert(SpreadSheet input)
Performs the actual conversion.void
defineOptions()
Adds options to the internal list of options.String
getColumnPrefix()
Returns whether to use the first column as new header.boolean
getUseFirstColumnAsHeader()
Returns whether to use the first column as new header.boolean
getUseHeaderAsFirstColumn()
Returns whether to use the current header as first column.String
globalInfo()
Returns a string describing the object.void
setColumnPrefix(String value)
Sets the column prefix if the first column is not used as header.void
setUseFirstColumnAsHeader(boolean value)
Sets whether to use the first column as new header.void
setUseHeaderAsFirstColumn(boolean value)
Sets whether to use the current header as first column.protected Cell[][]
toMatrix(SpreadSheet sheet)
Turns the spreadsheet into a matrix of Cell objects (first row is header).protected Cell[][]
transpose(Cell[][] matrix)
Transposes the matrix.String
useFirstColumnAsHeaderTipText()
Returns the tip text for this property.String
useHeaderAsFirstColumnTipText()
Returns the tip text for this property.-
Methods inherited from class adams.data.conversion.AbstractSpreadSheetConversion
accepts, doConvert, generates
-
Methods inherited from class adams.data.conversion.AbstractConversion
checkData, cleanUp, convert, getAdditionalInformation, getInput, getInput, getOutput, getOutput, getOwner, getQuickInfo, reset, setInput, setOwner, shallowCopy, shallowCopy, stopExecution
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, initialize, 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.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
Field Detail
-
m_UseHeaderAsFirstColumn
protected boolean m_UseHeaderAsFirstColumn
whether to add the header row as first column.
-
m_UseFirstColumnAsHeader
protected boolean m_UseFirstColumnAsHeader
whether to use the first column as header.
-
m_ColumnPrefix
protected String m_ColumnPrefix
the column prefix if the first column is not used as 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
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractOptionHandler
-
setUseHeaderAsFirstColumn
public void setUseHeaderAsFirstColumn(boolean value)
Sets whether to use the current header as first column.- Parameters:
value
- true if to use header
-
getUseHeaderAsFirstColumn
public boolean getUseHeaderAsFirstColumn()
Returns whether to use the current header as first column.- Returns:
- true if to use header
-
useHeaderAsFirstColumnTipText
public String useHeaderAsFirstColumnTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setUseFirstColumnAsHeader
public void setUseFirstColumnAsHeader(boolean value)
Sets whether to use the first column as new header.- Parameters:
value
- true if to use column
-
getUseFirstColumnAsHeader
public boolean getUseFirstColumnAsHeader()
Returns whether to use the first column as new header.- Returns:
- true if to use column
-
useFirstColumnAsHeaderTipText
public String useFirstColumnAsHeaderTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setColumnPrefix
public void setColumnPrefix(String value)
Sets the column prefix if the first column is not used as header.- Parameters:
value
- the prefix
-
getColumnPrefix
public String getColumnPrefix()
Returns whether to use the first column as new header.- Returns:
- true if to use column
-
columnPrefixTipText
public String columnPrefixTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
toMatrix
protected Cell[][] toMatrix(SpreadSheet sheet)
Turns the spreadsheet into a matrix of Cell objects (first row is header).- Parameters:
sheet
- the spreadsheet to turn into matrix- Returns:
- the generated matrix, missing cells are depicted by null
-
transpose
protected Cell[][] transpose(Cell[][] matrix)
Transposes the matrix.- Parameters:
matrix
- the matrix to transpose- Returns:
- the transposed matrix
-
convert
protected SpreadSheet convert(SpreadSheet input) throws Exception
Performs the actual conversion.
Input spreadsheet:+----+----+----+ | c1 | c2 | c3 | +====+====+====+ | A | B | C | +----+----+----+ | D | E | F | +----+----+----+
m_UseFirstColumnAsHeader = FAH m_HeaderAsFirstColumn = HAF
!FAH & !HAF:+----+----+ | P1 | P2 | +====+====+ | A | D | +----+----+ | B | E | +----+----+ | C | F | +----+----+
FAH & !HAF:+----+----+ | A | D | +====+====+ | B | E | +----+----+ | C | F | +----+----+
!FAH & HAF:+----+----+----+ | P1 | P2 | P3 | +====+====+====+ | c1 | A | D | +----+----+----+ | c2 | B | E | +----+----+----+ | c3 | C | F | +----+----+----+
FAH & HAF:+----+----+----+ | c1 | A | D | +====+====+====+ | c2 | B | E | +----+----+----+ | c3 | C | F | +----+----+----+
- Specified by:
convert
in classAbstractSpreadSheetConversion
- Parameters:
input
- the incoming spreadsheet- Returns:
- the converted data
- Throws:
Exception
- if something goes wrong with the conversion
-
-