![JAR search and dependency download from the Maven repository](/logo.png)
cn.featherfly.conversion.parse.AbstractIterableParser Maven / Gradle / Ivy
package cn.featherfly.conversion.parse;
import java.lang.reflect.Array;
import java.util.Collection;
import cn.featherfly.common.constant.Chars;
import cn.featherfly.common.lang.ClassUtils;
import cn.featherfly.common.lang.CollectionUtils;
import cn.featherfly.common.lang.GenericType;
import cn.featherfly.common.lang.LangUtils;
/**
*
* 可迭代对象抽象解析器,完成可迭代对象(数组,集合)配置的解析,具体解析方式由子类实现类实现。
*
* @param 解析的目标类型描述
* @author 钟冀
*/
public abstract class AbstractIterableParser> extends AbstractParser{
// /**
// * 协议字符串常量
// */
// public static final String CLASS_PROTOCOL = "constant";
/**
*/
public AbstractIterableParser() {
}
/**
*
* 解析传入的字符串
*
* @param 返回类型
* @param content 需要解析的内容
* @param to 解析的目标类型描述
* @return 解析后的对象
*/
protected abstract T doParseContent(String content, G to);
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
protected T doParse(String content, G to) {
if (LangUtils.isEmpty(content)) {
return null;
}
try {
String splitSign = Chars.COMMA;
if (content.contains(splitSign) || isMultyType(to.getType())) {
String[] contents = content.split(splitSign);
if (to.getType().isArray()) {
Object array = Array.newInstance(to.getType(), contents.length);
for (int i = 0; i < contents.length; i++) {
String c = contents[i].trim();
Array.set(array, i, doParseContent(c, to));
}
return (T) array;
} else if (ClassUtils.isParent(Collection.class, to.getType())) {
Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy