Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (C) 2011 K Venkata Sudhakar
*
* 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 com.bethecoder.table.impl;
import com.bethecoder.table.ASCIITableHeader;
import com.bethecoder.table.spec.AsciiTable;
import com.bethecoder.table.spec.IASCIITableAware;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Vector;
/**
* This implementation builds the header and data rows
* by considering each column one by one in the format of 'FFFF...' (border format).
* While rendering the last column, it closes the table.
* It takes +3 characters to render each column.
* These three characters include two white spaces at left and right side of
* the max length string in the column and one char(|) for table formatting.
*
* @author K Venkata Sudhakar ([email protected])
* @version 1.0
*
*/
public class SimpleTable implements AsciiTable {
@Override
public void printTable(String[] header, String[][] data) {
printTable(header, DEFAULT_HEADER_ALIGN, data, DEFAULT_DATA_ALIGN);
}
@Override
public void printTable(String[] header, String[][] data, int dataAlign) {
printTable(header, DEFAULT_HEADER_ALIGN, data, dataAlign);
}
@Override
public void printTable(String[] header, int headerAlign, String[][] data, int dataAlign) {
System.out.println(getTable(header, headerAlign, data, dataAlign));
}
@Override
public String getTable(String[] header, String[][] data) {
return getTable(header, DEFAULT_HEADER_ALIGN, data, DEFAULT_DATA_ALIGN);
}
@Override
public String getTable(String[] header, String[][] data, int dataAlign) {
return getTable(header, DEFAULT_HEADER_ALIGN, data, dataAlign);
}
@Override
public String getTable(String[] header, int headerAlign, String[][] data, int dataAlign) {
ASCIITableHeader[] headerObjs = new ASCIITableHeader[0];
if (header != null && header.length > 0) {
headerObjs = new ASCIITableHeader[header.length];
for (int i = 0 ; i < header.length ; i ++) {
headerObjs[i] = new ASCIITableHeader(header[i], dataAlign, headerAlign);
}
}
return getTable(headerObjs, data);
}
public void printTable(ASCIITableHeader[] headerObjs, String[][] data) {
System.out.println(getTable(headerObjs, data));
}
@Override
public String getTable(IASCIITableAware asciiTableAware) {
ASCIITableHeader[] headerObjs = new ASCIITableHeader[0];
String[][] data = new String[0][0];
List