de.vandermeer.asciitable.v2.render.RenderUtilities Maven / Gradle / Ivy
/* Copyright 2014 Sven van der Meer
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.vandermeer.asciitable.v2.render;
import de.vandermeer.asciilist.AsciiList;
import de.vandermeer.asciitable.commons.ArrayTransformations;
import de.vandermeer.asciitable.v2.row.ContentRow;
import de.vandermeer.asciitable.v2.row.RuleRow;
import de.vandermeer.asciitable.v2.row.V2_Row;
import de.vandermeer.asciitable.v2.themes.V2_RowTheme;
/**
* Utilities for manipulating tables and table rows.
*
* @author Sven van der Meer <[email protected]>
* @version v1.0.0 build 160319 (19-Mar-16) for Java 1.7
* @since v0.0.5
*/
public abstract class RenderUtilities {
/**
* Creates a content array, that is an array with columns.
* It will wrap lines and normalize the array.
* @param columns the original columns
* @param width the width of the columns
* @param padding column padding
* @return a fully processed and normalized content array
*/
public static final String[][] createContentArray(Object[] columns, int[] width, int[] padding){
String[][] ret = new String[width.length][];
int length = 0;
for(int i=0; i0){
length = length - padding[i] * 2;
}
if(o instanceof AsciiList){
//an AsciiList can render to width already, set width and render and process rendered string
ret[i] = ArrayTransformations.PROCESS_CONTENT(((AsciiList)o).setWidth(length).render());
}
else{
//get content first (does many forms of line breaks)
String [] content = ArrayTransformations.PROCESS_CONTENT(o);
//now wrap lines per line in the processed content array
ret[i] = ArrayTransformations.WRAP_LINES(length, content);
}
length = 0;
}
//equal number of strings per column
ret = ArrayTransformations.NORMALISE_ARRAY(width.length, ret);
//flip so that each normalized array row is a table column
ret = ArrayTransformations.FLIP_ARRAY(ret);
return ret;
}
/**
* Returns the border types for a bottom rule, regardless of the actual type of the given row.
* @param prev the previous row in the table
* @param row the original row
* @param colNumbers number of columns in the table
* @return array of border types, null if none could be created
*/
public static final BorderType[] getBorderTypes_BottomRule(ProcessedRow prev, V2_Row row, int colNumbers){
BorderType[] ret = null;
if(!(row instanceof RuleRow)){
return ret;
}
ret = new BorderType[colNumbers+1];
for(int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy