ListUtils如何应用于长尾词的检索与优化?
- 内容介绍
- 文章标签
- 相关推荐
本文共计398个文字,预计阅读时间需要2分钟。
javaListUtils导入java.lang.reflect.Field;导入java.lang.reflect.InvocationTargetException;导入java.lang.reflect.Method;导入java.util.ArrayList;导入java.util.List;导入org.springframework.util.CollectionUtils;@抑制警告
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.springframework.util.CollectionUtils;
@SuppressWarnings("unchecked")
public class ListUtils {
public static List getFiledList(List list, String filed) {
if (CollectionUtils.isEmpty(list))
return null;
List filedList = new ArrayList();
try {
for (Object obj : list) {
Class clazz = obj.getClass();// 获取集合中的对象类型
Field[] fds = clazz.getDeclaredFields();// 获取他的字段数组
for (Field field : fds) {// 遍历该数组
String fdname = field.getName();// 得到字段名,
Method method = clazz.getMethod("get" + change(fdname),
null);// 根据字段名找到对应的get方法,null表示无参数
if (null != method && filed.equals(fdname)) {
Object val = method.invoke(obj, null);
filedList.add(val);
}
}
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return filedList;
}
/**
* @param src
* 源字符串
* @return 字符串,将src的第一个字母转换为大写,src为空时返回null
*/
public static String change(String src) {
if (src != null) {
StringBuffer sb = new StringBuffer(src);
sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
return sb.toString();
} else {
return null;
}
}
public static void main(String[] args) {
List
本文共计398个文字,预计阅读时间需要2分钟。
javaListUtils导入java.lang.reflect.Field;导入java.lang.reflect.InvocationTargetException;导入java.lang.reflect.Method;导入java.util.ArrayList;导入java.util.List;导入org.springframework.util.CollectionUtils;@抑制警告
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.springframework.util.CollectionUtils;
@SuppressWarnings("unchecked")
public class ListUtils {
public static List getFiledList(List list, String filed) {
if (CollectionUtils.isEmpty(list))
return null;
List filedList = new ArrayList();
try {
for (Object obj : list) {
Class clazz = obj.getClass();// 获取集合中的对象类型
Field[] fds = clazz.getDeclaredFields();// 获取他的字段数组
for (Field field : fds) {// 遍历该数组
String fdname = field.getName();// 得到字段名,
Method method = clazz.getMethod("get" + change(fdname),
null);// 根据字段名找到对应的get方法,null表示无参数
if (null != method && filed.equals(fdname)) {
Object val = method.invoke(obj, null);
filedList.add(val);
}
}
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return filedList;
}
/**
* @param src
* 源字符串
* @return 字符串,将src的第一个字母转换为大写,src为空时返回null
*/
public static String change(String src) {
if (src != null) {
StringBuffer sb = new StringBuffer(src);
sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
return sb.toString();
} else {
return null;
}
}
public static void main(String[] args) {
List

