You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.7 KiB
Java
52 lines
1.7 KiB
Java
3 years ago
|
package com.engine.organization.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;
|
||
|
|
||
|
/**
|
||
|
* @Author weaver_cl
|
||
|
* @description:
|
||
|
* @Date 2022/6/14
|
||
|
* @Version V1.0
|
||
|
**/
|
||
|
public class OrganizationEnumUtil {
|
||
|
/**
|
||
|
* 根据枚举的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()]);
|
||
|
}
|
||
|
}
|