Skip to content

Commit

Permalink
新增README.md的介绍和pom.xml的完善
Browse files Browse the repository at this point in the history
  • Loading branch information
blinkfox committed Jan 13, 2019
1 parent 16a0b6f commit 7564af0
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 2 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# mini-table

> A lightweight, non-dependent Java ASCII TABLE generation library
[![HitCount](http://hits.dwyl.io/blinkfox/mini-table.svg)](http://hits.dwyl.io/blinkfox/mini-table) [![GitHub license](https://img.shields.io/github/license/blinkfox/mini-table.svg)](https://github.com/blinkfox/mini-table/blob/master/LICENSE) ![Java Version](https://img.shields.io/badge/Java-%3E%3D%206-blue.svg)

[中文文档](https://github.com/blinkfox/mini-table/blob/master/README_CN.md)

> A lightweight, no dependencies Java ASCII TABLE generation library.
## Features

- Lightweight, no dependencies (jar package only `13kb`)
- API is easy to use
- Easy to integrate or customize modifications, only one `Java` file, and code specification
81 changes: 81 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# mini-table

[![HitCount](http://hits.dwyl.io/blinkfox/mini-table.svg)](http://hits.dwyl.io/blinkfox/mini-table) [![GitHub license](https://img.shields.io/github/license/blinkfox/mini-table.svg)](https://github.com/blinkfox/mini-table/blob/master/LICENSE) ![Java Version](https://img.shields.io/badge/Java-%3E%3D%206-blue.svg)

[English Document](https://github.com/blinkfox/mini-table/blob/master/README.md)

> 一个轻量级、无任何依赖的 Java 纯文本表格(`ASCII TABLE`)生成库。
## 特性

- 轻量级、无依赖(jar包仅`13kb`
- API简单易用
- 易于集成或定制修改,仅一个[Java](https://github.com/blinkfox/mini-table/blob/master/src/main/java/com/blinkfox/minitable/MiniTable.java)文件,且代码规范

## 集成使用

### Maven集成

```xml
<dependency>
<groupId>com.blinkfox</groupId>
<artifactId>mini-table</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
```

> ****:目前版本还是`SNAPSHOT`,可直接`copy` Java 文件使用。
### API 使用

#### 示例1(无标题)

```java
String table = new MiniTable()
.addHeaders("header1", "header2")
.addDatas("col11", "col12")
.addDatas("col21", "col22")
.render();
System.out.println(table);
```

输出结果:

```bash
+---------+---------+
| header1 | header2 |
+---------+---------+
| col11 | col12 |
| col21 | col22 |
+---------+---------+
```

#### 示例2(有标题)

```java
String table = new MiniTable("The Title")
.addHeaders("Name", "Sex", "Age", "Email", "Phone")
.addDatas("LiLei", "male", 25, "[email protected]", "13809345219")
.addDatas("hanMeiMei", "female", 23, "[email protected]", "13515343853")
.addDatas("ZhangSan", "female", 32, "[email protected]", "13920199836")
.render();
System.out.println(table);
```

输出结果:

```bash
+-------------------------------------------------------------+
| The Title |
+-----------+--------+-----+--------------------+-------------+
| Name | Sex | Age | Email | Phone |
+-----------+--------+-----+--------------------+-------------+
| LiLei | male | 25 | [email protected] | 13809345219 |
| hanMeiMei | female | 23 | [email protected] | 13515343853 |
| ZhangSan | female | 32 | [email protected] | 13920199836 |
+-----------+--------+-----+--------------------+-------------+
```

## 许可证

[mini-table](https://github.com/blinkfox/mini-table) 类库遵守 [Apache License 2.0][http://www.apache.org/licenses/LICENSE-2.0] 许可证
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<name>mini-table</name>
<description>A lightweight, non-dependent Java ASCII TABLE generation library.</description>
<url>https://github.com/blinkfox/mini-table</url>

<licenses>
<license>
Expand All @@ -26,6 +27,12 @@
</developer>
</developers>

<scm>
<connection>scm:[email protected]:blinkfox/mini-table.git</connection>
<developerConnection>scm:[email protected]:blinkfox/mini-table.git</developerConnection>
<url>https://github.com/blinkfox/mini-table</url>
</scm>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/blinkfox/minitable/MiniTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ private MiniTable appendRows(RowType rowType, Object... objects) {
String value = o == null ? "null" : o.toString();
datas.add(value);

// 获取第 i 列的最大长度值,如果当前列的长度大于了以前的最大列,就覆盖最大列长度为当前的列长度.
// 获取第 i 列的最大长度值,如果该列数据不存在,就存储起来.
Integer maxColSize = this.maxColMap.get(i);
if (maxColSize == null) {
this.maxColMap.put(i, value.length());
continue;
}

// 如果当前列的长度大于了以前的最大列,就覆盖最大列长度为当前的列长度.
if (value.length() > maxColSize) {
this.maxColMap.put(i, value.length());
}
Expand Down

0 comments on commit 7564af0

Please sign in to comment.