| | |
| | | package com.ruoyi.common.core.utils; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import lombok.AccessLevel; |
| | | import lombok.NoArgsConstructor; |
| | | import org.springframework.util.AntPathMatcher; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 字符串工具类 |
| | |
| | | */ |
| | | @NoArgsConstructor(access = AccessLevel.PRIVATE) |
| | | public class StringUtils extends org.apache.commons.lang3.StringUtils { |
| | | |
| | | public static final String SEPARATOR = ","; |
| | | |
| | | /** |
| | | * 获取参数不为空值 |
| | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 切分字符串(分隔符默认逗号) |
| | | * |
| | | * @param str 被切分的字符串 |
| | | * @return 分割后的数据列表 |
| | | */ |
| | | public static List<String> splitList(String str) { |
| | | return splitTo(str, Convert::toStr); |
| | | } |
| | | |
| | | /** |
| | | * 切分字符串 |
| | | * |
| | | * @param str 被切分的字符串 |
| | | * @param separator 分隔符 |
| | | * @return 分割后的数据列表 |
| | | */ |
| | | public static List<String> splitList(String str, String separator) { |
| | | return splitTo(str, separator, Convert::toStr); |
| | | } |
| | | |
| | | /** |
| | | * 切分字符串自定义转换(分隔符默认逗号) |
| | | * |
| | | * @param str 被切分的字符串 |
| | | * @param mapper 自定义转换 |
| | | * @return 分割后的数据列表 |
| | | */ |
| | | public static <T> List<T> splitTo(String str, Function<? super Object, T> mapper) { |
| | | return splitTo(str, SEPARATOR, mapper); |
| | | } |
| | | |
| | | /** |
| | | * 切分字符串自定义转换 |
| | | * |
| | | * @param str 被切分的字符串 |
| | | * @param separator 分隔符 |
| | | * @param mapper 自定义转换 |
| | | * @return 分割后的数据列表 |
| | | */ |
| | | public static <T> List<T> splitTo(String str, String separator, Function<? super Object, T> mapper) { |
| | | if (isBlank(str)) { |
| | | return new ArrayList<>(0); |
| | | } |
| | | return StrUtil.split(str, separator) |
| | | .stream() |
| | | .filter(Objects::nonNull) |
| | | .map(mapper) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | } |