package com.com.test;
import org.apache.commons.lang3.math.NumberUtils;
import java.util.ArrayList;
import java.util.List;
public class StringHelper {
/**
* 分割字符串,返回数字列表
* 支持类型:Integer Long Double
* */
public static <T extends Number> List<T> parseString2NumberList(String str,String split,Class cls){
List<T> list = new ArrayList<T>();
if(str == null || str.trim().equals("")){
return list;
}
if(split == null){
throw new RuntimeException("分割字符不能为空");
}
String[] strArr = str.split(split);
String className = cls.getName();
T num = null;
for(String item:strArr){
if(!NumberUtils.isNumber(item)){
continue;
}
if(className.equals("java.lang.Integer")){
num = (T)Integer.valueOf(item);
}else if(className.equals("java.lang.Long")){
num = (T)Long.valueOf(item);
}else if(className.equals("java.lang.Double")){
num = (T)Double.valueOf(item);
}else{
return list;
}
list.add(num);
}
return list;
}
}