```
package com.netease.ehr.mbo.model.enums;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @
author xiang0818
* @
date 2021-07-21 16:06
*/
public enum SortEnum {
/**
* .
*/
COUNT("count", SckPriceVo::getCount),
;
private final String column;
private final Function<SckPriceVo, Integer> functionGen;
SortEnum(String column, Function<SckPriceVo, Integer> functionGen) {
this.column = column;
this.functionGen = functionGen;
}
public String getColumn() {
return column;
}
private Comparator<SckPriceVo> getComparing(String sortType) {
if (sortType.equals("1")) {
return Comparator.comparing(functionGen);
} else if (sortType.equals("2")) {
return Comparator.comparing(functionGen).reversed();
}
throw new RuntimeException("error");
}
private static SortEnum getByColumn(String column) {
for (SortEnum value : SortEnum.values()) {
if (value.column.equals(column)) {
return value;
}
}
throw new RuntimeException("error");
}
public static List<SckPriceVo> getSort(List<SckPriceVo> sckPriceVoList, String column, String sortType) {
return
sckPriceVoList.stream().sorted(SortEnum.getByColumn(column).getComparing(sortType)).collect(Collectors.toList());
}
}