com.alibaba.excel.metadata.AbstractHolder Maven / Gradle / Ivy
Show all versions of easyexcel Show documentation
package com.alibaba.excel.metadata;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import com.alibaba.excel.converters.Converter;
/**
* Write/read holder
*
* @author Jiaju Zhuang
*/
public abstract class AbstractHolder implements ConfigurationHolder {
/**
* Record whether it's new or from cache
*/
private Boolean newInitialization;
/**
* You can only choose one of the {@link AbstractHolder#head} and {@link AbstractHolder#clazz}
*/
private List> head;
/**
* You can only choose one of the {@link AbstractHolder#head} and {@link AbstractHolder#clazz}
*/
private Class clazz;
/**
* Some global variables
*/
private GlobalConfiguration globalConfiguration;
/**
*
* Read key:
*
* Write key:
*/
private Map converterMap;
public AbstractHolder(BasicParameter basicParameter, AbstractHolder prentAbstractHolder) {
this.newInitialization = Boolean.TRUE;
if (basicParameter.getHead() == null && basicParameter.getClazz() == null && prentAbstractHolder != null) {
this.head = prentAbstractHolder.getHead();
} else {
this.head = basicParameter.getHead();
}
if (basicParameter.getHead() == null && basicParameter.getClazz() == null && prentAbstractHolder != null) {
this.clazz = prentAbstractHolder.getClazz();
} else {
this.clazz = basicParameter.getClazz();
}
this.globalConfiguration = new GlobalConfiguration();
if (basicParameter.getAutoTrim() == null) {
if (prentAbstractHolder == null) {
globalConfiguration.setAutoTrim(Boolean.TRUE);
} else {
globalConfiguration.setAutoTrim(prentAbstractHolder.getGlobalConfiguration().getAutoTrim());
}
} else {
globalConfiguration.setAutoTrim(basicParameter.getAutoTrim());
}
if (basicParameter.getLocale() == null) {
if (prentAbstractHolder == null) {
globalConfiguration.setLocale(Locale.getDefault());
} else {
globalConfiguration.setLocale(prentAbstractHolder.getGlobalConfiguration().getLocale());
}
} else {
globalConfiguration.setLocale(basicParameter.getLocale());
}
}
public Boolean getNewInitialization() {
return newInitialization;
}
public void setNewInitialization(Boolean newInitialization) {
this.newInitialization = newInitialization;
}
public List> getHead() {
return head;
}
public void setHead(List> head) {
this.head = head;
}
public Class getClazz() {
return clazz;
}
public void setClazz(Class clazz) {
this.clazz = clazz;
}
public GlobalConfiguration getGlobalConfiguration() {
return globalConfiguration;
}
public void setGlobalConfiguration(GlobalConfiguration globalConfiguration) {
this.globalConfiguration = globalConfiguration;
}
public Map getConverterMap() {
return converterMap;
}
public void setConverterMap(Map converterMap) {
this.converterMap = converterMap;
}
@Override
public Map converterMap() {
return getConverterMap();
}
@Override
public GlobalConfiguration globalConfiguration() {
return getGlobalConfiguration();
}
@Override
public boolean isNew() {
return getNewInitialization();
}
}