54 lines
1.7 KiB
Java
54 lines
1.7 KiB
Java
package com.engine.salary.util;
|
|
|
|
import com.engine.salary.enums.BaseEnum;
|
|
import com.engine.salary.enums.sicategory.PaymentScopeEnum;
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* @Description:
|
|
* @Author: zhangheng
|
|
* @CreateDate: 2021/11/19 16:39
|
|
* @Version: v1.0
|
|
*/
|
|
public class SalaryEnumUtil {
|
|
|
|
/**
|
|
* 根据枚举的value获取枚举对象
|
|
*
|
|
* @param value 枚举中的value
|
|
* @param list
|
|
* @param T
|
|
* @param <T>
|
|
* @return
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
public static <T> T enumMatchByValue(Integer value, BaseEnum<Integer>[] list, Class<? extends BaseEnum<Integer>> T) {
|
|
return (T) Arrays.stream(list).filter(item -> Objects.equals(item.getValue(), value)).findFirst().get();
|
|
}
|
|
|
|
/**
|
|
* 枚举数组转字符串
|
|
*
|
|
* @param list
|
|
* @return
|
|
*/
|
|
public static String enumArrToString(BaseEnum<Integer>[] list) {
|
|
List<String> collect = Arrays.stream(list).map(item -> String.valueOf(item.getValue())).collect(Collectors.toList());
|
|
return StringUtils.join(collect, ",");
|
|
}
|
|
|
|
public static PaymentScopeEnum[] stringToEnums(String values, String charSequence) {
|
|
String[] arr = values.split(charSequence);
|
|
PaymentScopeEnum[] enumConstants = PaymentScopeEnum.values();
|
|
List<PaymentScopeEnum> collect = Arrays.stream(arr)
|
|
.map(item -> Arrays.stream(enumConstants).filter(s -> Objects.equals(String.valueOf(s.getValue()), item)).findFirst().get()).collect(Collectors.toList());
|
|
return collect.toArray(new PaymentScopeEnum[collect.size()]);
|
|
}
|
|
|
|
}
|