add console.table

This commit is contained in:
Looly 2020-10-14 18:09:12 +08:00
parent 1b4424f7fa
commit 97d48dde0b
3 changed files with 57 additions and 37 deletions

View File

@ -53,9 +53,9 @@ public class Console {
* @since 5.4.3
*/
public static void log(Object obj1, Object... otherObjs) {
if(ArrayUtil.isEmpty(otherObjs)){
if (ArrayUtil.isEmpty(otherObjs)) {
log(obj1);
} else{
} else {
log(buildTemplateSplitBySpace(otherObjs.length + 1), ArrayUtil.insert(otherObjs, 0, obj1));
}
}
@ -97,11 +97,22 @@ public class Console {
* @param values
* @since 5.4.3
*/
private static void logInternal(String template, Object... values){
private static void logInternal(String template, Object... values) {
log(null, template, values);
}
// --------------------------------------------------------------------------------- print
/**
* 打印表格到控制台
*
* @param consoleTable 控制台表格
* @since 5.4.5
*/
public static void table(ConsoleTable consoleTable) {
print(consoleTable.toString());
}
/**
* System.out.print()方法打印控制台日志
*
@ -121,9 +132,9 @@ public class Console {
* @since 5.4.3
*/
public static void print(Object obj1, Object... otherObjs) {
if(ArrayUtil.isEmpty(otherObjs)){
if (ArrayUtil.isEmpty(otherObjs)) {
print(obj1);
} else{
} else {
print(buildTemplateSplitBySpace(otherObjs.length + 1), ArrayUtil.insert(otherObjs, 0, obj1));
}
}
@ -174,7 +185,7 @@ public class Console {
* @param values
* @since 5.4.3
*/
private static void printInternal(String template, Object... values){
private static void printInternal(String template, Object... values) {
out.print(StrUtil.format(template, values));
}
@ -210,9 +221,9 @@ public class Console {
* @since 5.4.3
*/
public static void error(Object obj1, Object... otherObjs) {
if(ArrayUtil.isEmpty(otherObjs)){
if (ArrayUtil.isEmpty(otherObjs)) {
error(obj1);
} else{
} else {
error(buildTemplateSplitBySpace(otherObjs.length + 1), ArrayUtil.insert(otherObjs, 0, obj1));
}
}
@ -312,7 +323,7 @@ public class Console {
* @param count 变量数量
* @return 模板
*/
private static String buildTemplateSplitBySpace(int count){
private static String buildTemplateSplitBySpace(int count) {
return StrUtil.repeatAndJoin(TEMPLATE_VAR, count, StrUtil.SPACE);
}

View File

@ -35,6 +35,16 @@ public class ConsoleTable {
*/
private List<Integer> columnCharNumber;
/**
* 创建ConsoleTable对象
*
* @return ConsoleTable
* @since 5.4.5
*/
public static ConsoleTable create(){
return new ConsoleTable();
}
/**
* 添加头信息
*
@ -101,7 +111,7 @@ public class ConsoleTable {
/**
* 填充表头或者表体信息
*
* @param sb
* @param sb 内容
* @param list 表头列表或者表体列表
*/
private void fillRow(StringBuilder sb, List<List<String>> list) {

View File

@ -1,12 +1,11 @@
package cn.hutool.core.lang;
import org.junit.Ignore;
import org.junit.Test;
public class ConsoleTableTest {
@Test
@Ignore
// @Ignore
public void printTest() {
ConsoleTable t = new ConsoleTable();
t.addHeader("姓名", "年龄");