add method

This commit is contained in:
Looly 2021-09-27 22:53:12 +08:00
parent ed85f81cea
commit 75d84b4768
5 changed files with 23 additions and 7 deletions

View File

@ -12,6 +12,7 @@
* 【extra 】 SenvenZExtractor改名为SevenZExtractor增加getFirst、get方法
* 【core 】 DateConverter修改返回java.util.Date而非DateTimeissue#I4BOAP@Gitee
* 【core 】 增加IterableIter、ComputeIter
* 【core 】 CsvConfig增加disableComment方法issue#1842@Github
### 🐞Bug修复
* 【http 】 修复HttpCookie设置cookies的方法不符合RFC6265规范问题pr#418@Gitee

View File

@ -29,7 +29,7 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
*
* @param rootId 根节点ID
* @param <T> ID类型
* @return {@link TreeBuilder}
* @return TreeBuilder
*/
public static <T> TreeBuilder<T> of(T rootId) {
return of(rootId, null);
@ -41,7 +41,7 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
* @param rootId 根节点ID
* @param config 配置
* @param <T> ID类型
* @return {@link TreeBuilder}
* @return TreeBuilder
*/
public static <T> TreeBuilder<T> of(T rootId, TreeNodeConfig config) {
return new TreeBuilder<>(rootId, config);

View File

@ -28,7 +28,7 @@ public class CsvConfig<T extends CsvConfig<T>> implements Serializable {
/**
* 注释符号用于区分注释行默认'#'
*/
protected char commentCharacter = '#';
protected Character commentCharacter = '#';
/**
* 标题别名
*/
@ -57,13 +57,25 @@ public class CsvConfig<T extends CsvConfig<T>> implements Serializable {
}
/**
* 设置 注释符号用于区分注释行
* 设置注释无效<br>
* 当写出CSV时{@link CsvWriter#writeComment(String)}将抛出异常<br>
* 当读取CSV时注释行按照正常行读取
*
* @return this
* @since 5.7.14
*/
public T disableComment() {
return setCommentCharacter(null);
}
/**
* 设置 注释符号用于区分注释行{@code null}表示忽略注释
*
* @param commentCharacter 注释符号用于区分注释行
* @return this
* @since 5.5.7
*/
public T setCommentCharacter(char commentCharacter) {
public T setCommentCharacter(Character commentCharacter) {
this.commentCharacter = commentCharacter;
return (T) this;
}

View File

@ -234,7 +234,7 @@ public final class CsvParser implements Closeable, Serializable {
if(preChar < 0 || preChar == CharUtil.CR || preChar == CharUtil.LF){
// 判断行首字符为指定注释字符的注释开始直到遇到换行符
// 行首分两种1是preChar < 0表示文本开始2是换行符后紧跟就是下一行的开始
if(c == this.config.commentCharacter){
if(null != this.config.commentCharacter && c == this.config.commentCharacter){
inComment = true;
}
}

View File

@ -6,6 +6,7 @@ import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.CharUtil;
@ -308,7 +309,8 @@ public final class CsvWriter implements Closeable, Flushable, Serializable {
}
/**
* 写出一行注释注释符号可自定义
* 写出一行注释注释符号可自定义<br>
* 如果注释符不存在则抛出异常
*
* @param comment 注释内容
* @return this
@ -316,6 +318,7 @@ public final class CsvWriter implements Closeable, Flushable, Serializable {
* @since 5.5.7
*/
public CsvWriter writeComment(String comment) {
Assert.notNull(this.config.commentCharacter, "Comment is disable!");
try {
writer.write(this.config.commentCharacter);
writer.write(comment);