/* * [Unquilt.java] * * Summary: unravel a quilt table into a table of a single column or column group/pair. * * Copyright: (c) 1998-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; import static java.lang.System.*; /** * unravel a quilt table into a table of a single column or column group/pair. *

* Convert an Quilted table back to a single column. * Must manually strip stuff ahead and after table. * Must manually strip
* Must manually strip * no fancy etc. Just in upper or lower case. * does not deal with rowspan or colspan. * It can't handle any grammatical errors in your HTML. * Does not resort. * 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 Unquilt extends Common { private static final int FIRST_COPYRIGHT_YEAR = 2003; /** * undisplayed copyright */ @SuppressWarnings( { "UnusedDeclaration" } ) private static final String EMBEDDED_COPYRIGHT = "Copyright: (c) 2003-2017 Roedy Green, Canadian Mind Products, http://mindprod.com"; /** * main * * @param args [0] byrows to unquilt by rows. No ability do undo double column quilts yet. byrows is not implemented * either. * * @throws java.io.IOException if any problem reading or writing the html */ public static void main( String[] args ) throws IOException { if ( args.length > 0 && args[ 0 ].equalsIgnoreCase( "byrows" ) ) { out.println( "byrows is not yet implemented" ); System.exit( 1 ); } // get entire table into a string. final String[][] matrix = getMatrix( IN_FILENAME ); final int rows = rows( matrix ); final int cols = cols( matrix ); displayRowAndColCounts( "quilted input", rows, cols ); trimMatrix( matrix ); // New result shape final int nrows = rows * cols; final int ncols = 1; displayRowAndColCounts( "unquilted output", nrows, ncols ); // create new matrix with 1 columns. String[][] grid = new String[ nrows ][ ncols ]; int targetRow = 0; for ( int col = 0; col < cols; col++ ) { for ( int row = 0; row < rows; row++ ) { grid[ targetRow++ ][ 0 ] = matrix[ row ][ col ]; } // end for } // end for writeMatrix( grid, OUT_FILENAME ); } // end main } // end Unquilt