/* * [Quilt.java] * * Summary: Arrange an HTML table into multi columns. * * 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 initial version. */ package com.mindprod.reorg; import java.io.IOException; import static java.lang.System.*; /** * Arrange an HTML table into multi columns. *

* Reorg table for quilt into N columns. * Create a table with with multiple columns of the same data top to bottom, left to right. *

* takes a single parm on command line, # of cols in output Quilt * Input must be a single column, presorted. (strip convert -> * ) * 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. * 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 initial version. * @since 1998 */ public final class Quilt extends Common { private static final int FIRST_COPYRIGHT_YEAR = 1998; /** * copyright not displayed. */ @SuppressWarnings( { "UnusedDeclaration" } ) private static final String EMBEDDED_COPYRIGHT = "Copyright: (c) 1998-2017 Roedy Green, Canadian Mind Products, http://mindprod.com"; /** * main method * * @param args args[0] number of columns in a group, usually 1 * * @throws IOException if any problem reading or writing the html */ public static void main( String[] args ) throws IOException { int ncols = 4;// default how many cols in output try { ncols = Integer.parseInt( args[ 0 ] ); } catch ( NumberFormatException e ) { out.println( ncols + " columns" ); } // get entire table into a string. final String[][] matrix = getMatrix( IN_FILENAME ); final int rows = rows( matrix ); final int cols = cols( matrix ); displayRowAndColCounts( "unquilted input", rows, cols ); trimMatrix( matrix ); if ( ncols % cols != 0 ) { throw new IllegalArgumentException( "cols in quilt must be an even multiple of cols in the original" ); } // number of rows in the new quilted scheme, covered quotient. final int nrows = ( ( rows + ncols / cols ) - 1 ) / ( ncols / cols ); displayRowAndColCounts( "quilted output", nrows, ncols ); // create new grid nrows x ncols String[][] grid = new String[ nrows ][ ncols ]; int sourceRow = 0; // iterate through each slot of the new grid and bring over the old // one. for ( int ncol = 0; ncol < ncols; ncol += cols ) { for ( int nrow = 0; nrow < nrows; nrow++ ) { for ( int col = 0; col < cols; col++ ) { if ( sourceRow < rows ) { grid[ nrow ][ ncol + col ] = matrix[ sourceRow ][ col ]; } } // end for col sourceRow++; } // end for nrow } // end for for ncol writeMatrix( grid, "E:/temp/out.html" ); } // end main } // Quilt