com.base4j.util.SortUtil Maven / Gradle / Ivy
The newest version!
package com.base4j.util;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 排序工具类
*
* @author huangjun
* @version [版本号, 2017年11月17日]
* @Description:
* @ClassName:ListSortUtil
* @see [相关类/方法]
* @since [产品/模块]
*/
public class SortUtil {
public static final String ASC = "asc";
public static final String DESC = "desc";
private static Pattern NUMBER_PATTERN = Pattern.compile("^[+-]?[0-9]+$");
/**
* [简述]: 对List数组排序
*
* @param list 源数据 排序集合
* @param sort 升序 还是 降序,默认升序
* @return List
*/
public static List> sort(List> list, final String sort) {
Collections.sort(list, new Comparator