org.dromara.hutool.poi.csv.CsvConfig Maven / Gradle / Ivy
/*
* Copyright (c) 2013-2024 Hutool Team and hutool.cn
*
* 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 org.dromara.hutool.poi.csv;
import org.dromara.hutool.core.text.CharUtil;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* CSV基础配置项,此配置项可用于读取和写出CSV,定义了包括字段分隔符、文本包装符等符号
*
* @param 继承子类类型,用于this返回
* @author looly
* @since 4.0.5
*/
@SuppressWarnings("unchecked")
public class CsvConfig> implements Serializable {
private static final long serialVersionUID = -8069578249066158459L;
/**
* 字段分隔符,默认逗号','
*/
protected char fieldSeparator = CharUtil.COMMA;
/**
* 文本包装符,默认双引号'"'
*/
protected char textDelimiter = CharUtil.DOUBLE_QUOTES;
/**
* 注释符号,用于区分注释行,默认'#'
*/
protected Character commentCharacter = '#';
/**
* 标题别名
*/
protected Map headerAlias = new LinkedHashMap<>();
/**
* 设置字段分隔符,默认逗号','
*
* @param fieldSeparator 字段分隔符,默认逗号','
* @return this
*/
public T setFieldSeparator(final char fieldSeparator) {
this.fieldSeparator = fieldSeparator;
return (T) this;
}
/**
* 设置 文本分隔符,文本包装符,默认双引号'"'
*
* @param textDelimiter 文本分隔符,文本包装符,默认双引号'"'
* @return this
*/
public T setTextDelimiter(final char textDelimiter) {
this.textDelimiter = textDelimiter;
return (T) this;
}
/**
* 设置注释无效
* 当写出CSV时,{@link CsvWriter#writeComment(String)}将抛出异常
* 当读取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(final Character commentCharacter) {
this.commentCharacter = commentCharacter;
return (T) this;
}
/**
* 设置标题行的别名Map
*
* @param headerAlias 别名Map
* @return this
* @since 5.7.10
*/
public T setHeaderAlias(final Map headerAlias) {
this.headerAlias = headerAlias;
return (T) this;
}
/**
* 增加标题别名
*
* @param header 标题
* @param alias 别名
* @return this
* @since 5.7.10
*/
public T addHeaderAlias(final String header, final String alias) {
this.headerAlias.put(header, alias);
return (T) this;
}
/**
* 去除标题别名
*
* @param header 标题
* @return this
* @since 5.7.10
*/
public T removeHeaderAlias(final String header) {
this.headerAlias.remove(header);
return (T) this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy