/*
* [Transpose.java]
*
* Summary: transpose a table's rows and columns.
*
* Copyright: (c) 2000-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
*
* Licence: This software may be copied and used freely for any purpose but military.
* http://mindprod.com/contact/nonmil.html
*
* Requires: JDK 1.8+
*
* Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
*
* Version History:
* 1.0 1998-01-01
*/
package com.mindprod.reorg;
import java.io.IOException;
/**
* transpose a table's rows and columns.
*
* Transpose.java
* reshape a HTML table by exchanging rows and columns
* No command command line
* Must manually strip stuff ahead and after table.
* Must manually strip
* Must manually strip |
* no fancy etc. Just
in upper or lower case.
* It can't handle any grammatical errors in your HTML.
* Input from E:\temp\in.html
* Output to E:\temp\out.html all tags in lower case.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 1998-01-01
* @since 1998-01-01
*/
public final class Transpose extends Common
{
private static final int FIRST_COPYRIGHT_YEAR = 1998;
/**
* non-displaying copyright
*/
@SuppressWarnings( { "UnusedDeclaration" } )
private static final String EMBEDDED_COPYRIGHT =
"Copyright: (c) 1998-2017 Roedy Green, Canadian Mind Products, http://mindprod.com";
/**
* main
*
* @param args not used. Input always temp.in
*
* @throws java.io.IOException if any problem reading or writing the html
*/
@SuppressWarnings( { "UnnecessaryLocalVariable" } )
public static void main( String[] args ) throws IOException
{
// get entire table into a string.
final String[][] matrix = getMatrix( IN_FILENAME );
final int rows = rows( matrix );
final int cols = cols( matrix );
displayRowAndColCounts( "input", rows, cols );
trimMatrix( matrix );
final int nrows = cols;
final int ncols = rows;
displayRowAndColCounts( "output", nrows, ncols );
// create new matrix transposing rows & columns.
String[][] grid = new String[ nrows ][ ncols ];
// copy over, transposing.
for ( int col = 0; col < ncols; col++ )
{
for ( int row = 0; row < nrows; row++ )
{
grid[ row ][ col ] = matrix[ col ][ row ];
} // end for
} // end for
writeMatrix( grid, OUT_FILENAME );
} // end main
} // end Transpose
|