1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
| import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Validator; import cn.hutool.core.util.RandomUtil; import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern;
public class ValCommonUtils {
public static final String LEFT_CURLYBRACES = "{";
public static final String RIGHT_CURLYBRACES = "}";
public static final String CURLYBRACES_AROUND = "\\{.+?}";
public static String tradeSn(int ran) { return DateUtil.format(new Date(), "yyyyMMddHHmmss") + randomNumeric(ran); }
public static String randomNumeric(int length) { if (length <= 0) { return ""; } return RandomUtil.randomNumbers(length); }
public static boolean isChineseByRange(String str) { if (null == str) { return false; } char[] ch = str.toCharArray(); for (char c : ch) { if (c < 0x4E00 || c > 0x9FBF) { return false; } } return true; }
public static <T> String merge(Collection<T> collection) { if (CollectionUtil.isEmpty(collection)) { return ""; } StringBuilder builder = new StringBuilder(); for (T element : collection) { if (element != null && Validator.isNotEmpty(element.toString())) { builder.append(LEFT_CURLYBRACES).append(element) .append(RIGHT_CURLYBRACES); } } return builder.toString(); }
public static List<String> split(String str) { if (Validator.isEmpty(str)) { return Collections.emptyList(); }
List<String> list = new ArrayList<>(); Pattern pattern = Pattern.compile(CURLYBRACES_AROUND); Matcher matcher = pattern.matcher(str); while (matcher.find()) { String element = matcher.group().substring(1, matcher.group().length() - 1); if (Validator.isNotNull(element)) { list.add(element); } } return list; }
public static String no(String prefix, Long sn) { StringBuilder suffix = new StringBuilder(sn + ""); while (suffix.length() < 6) { suffix.insert(0, "0"); } return prefix + suffix; }
public static List<String> split(String str, String separator) { if (Validator.isEmpty(str)) { return Collections.emptyList(); } List<String> list = new ArrayList<>(); if (Validator.isEmpty(separator)) { list.add(str); return list; } String[] array = str.split(separator); if (ArrayUtils.isEmpty(array)) { return Collections.emptyList(); } for (String element : array) { if (Validator.isNotEmpty(element)) { list.add(element); } } return list; }
}
|