adams.data.conversion
Class TransposeSpreadSheet

java.lang.Object
  extended by adams.core.ConsoleObject
      extended by adams.core.option.AbstractOptionHandler
          extended by adams.data.conversion.AbstractConversion
              extended by adams.data.conversion.AbstractSpreadSheetConversion
                  extended by adams.data.conversion.TransposeSpreadSheet
All Implemented Interfaces:
CleanUpHandler, Debuggable, Destroyable, OptionHandler, QuickInfoSupporter, ShallowCopySupporter<AbstractConversion>, SizeOfHandler, 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: 6289 $
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
Serialized Form

Field Summary
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
 
Fields inherited from class adams.core.option.AbstractOptionHandler
m_DebugLevel, m_OptionManager
 
Constructor Summary
TransposeSpreadSheet()
           
 
Method Summary
 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  Object[][] transpose(Object[][] 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, getInput, getOutput, getOwner, getQuickInfo, reset, setInput, setOwner, shallowCopy, shallowCopy
 
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, debug, debug, debugLevelTipText, destroy, finishInit, getDebugLevel, getOptionManager, initialize, isDebugOn, newOptionManager, setDebugLevel, toCommandLine, toString
 
Methods inherited from class adams.core.ConsoleObject
getDebugging, getSystemErr, getSystemOut, sizeOf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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.

Constructor Detail

TransposeSpreadSheet

public TransposeSpreadSheet()
Method Detail

globalInfo

public String globalInfo()
Returns a string describing the object.

Specified by:
globalInfo in class AbstractOptionHandler
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 interface OptionHandler
Overrides:
defineOptions in class AbstractOptionHandler

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.

transpose

protected Object[][] transpose(Object[][] matrix)
Transposes the matrix.

Parameters:
matrix - the matrix to transose
Returns:
the tranposed 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 class AbstractSpreadSheetConversion
Parameters:
input - the incoming spreadsheet
Returns:
the converted data
Throws:
Exception - if something goes wrong with the conversion


Copyright © 2012 University of Waikato, Hamilton, NZ. All Rights Reserved.