常用工具类

Date工具类

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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package com.imaxun.demo.framework.common.util;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;

public class DateTimeUtils {
public static final DateTimeFormatter dateTimeDefaultFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
public static final DateTimeFormatter dateDefaultFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
public static final DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
public static final DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
public static final ZoneOffset defaultZoneOffset = ZoneOffset.systemDefault()
.getRules().getOffset(Instant.now());

/**
* 获取本地时间(LocalDate)
*/
public static LocalDate now() {
return LocalDate.now();
}

public static LocalDateTime nowTime() {
return LocalDateTime.now();
}

public static long nowEpochSecond() {
return Instant.now().getEpochSecond();
}

public static long nowEpochMillisecond() {
return Instant.now().toEpochMilli();
}

/**
* 本地时间对象转换为unix时间戳(毫秒/秒)
*/
public static long toEpochSecond(LocalDateTime time, ZoneOffset zoneOffset) {
return time.toEpochSecond(zoneOffset);
}

public static long toEpochSecond(LocalDateTime time) {
return toEpochSecond(time, defaultZoneOffset);
}

public static long toEpochSecondByDay(LocalDate time, ZoneOffset zoneOffset) {
return toEpochSecond(LocalDateTime.of(time, LocalTime.parse("00:00:00")), zoneOffset);
}

public static long toEpochSecondByDay(LocalDate time) {
return toEpochSecondByDay(time, defaultZoneOffset);
}

public static long toEpochMillisecondByDay(LocalDate time, ZoneOffset zoneOffset) {
return toEpochMillisecond(LocalDateTime.of(time, LocalTime.parse("00:00:00")), zoneOffset);
}

public static long toEpochMillisecondByDay(LocalDate time) {
return toEpochMillisecond(LocalDateTime.of(time, LocalTime.parse("00:00:00")), defaultZoneOffset);
}

public static long toEpochMillisecond(LocalDateTime time, ZoneOffset zoneOffset) {
return time.toInstant(zoneOffset).toEpochMilli();
}

public static long toEpochMillisecond(LocalDateTime time) {
return toEpochMillisecond(time, defaultZoneOffset);
}

/**
* unix时间戳(毫秒/秒)转换为本地时间对象
*/
public static LocalDateTime ofEpochSecond(long second, ZoneOffset zoneOffset) {
return second <= 0 ? null : LocalDateTime.ofEpochSecond(second, 0, zoneOffset);
}

public static LocalDate ofEpochSecondToDate(long second, ZoneOffset zoneOffset) {
return second <= 0 ? null : LocalDateTime.ofEpochSecond(second, 0, zoneOffset).toLocalDate();
}


public static LocalDateTime ofEpochSecond(long second) {
return ofEpochSecond(second, defaultZoneOffset);
}


public static LocalDate ofEpochSecondToDate(long second) {
return ofEpochSecondToDate(second, defaultZoneOffset);
}

public static LocalDateTime ofEpochMillisecond(long millisecond, ZoneOffset zoneOffset) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(millisecond), zoneOffset);
}

public static LocalDateTime ofEpochMillisecond(long millisecond) {
return ofEpochMillisecond(millisecond, defaultZoneOffset);
}

public static LocalDate ofEpochMillisecondToDate(long millisecond, ZoneOffset zoneOffset) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(millisecond), zoneOffset).toLocalDate();
}

public static LocalDate ofEpochMillisecondToDate(long millisecond) {
return ofEpochMillisecondToDate(millisecond, defaultZoneOffset);
}

/**
* 将字符串转换为本地时间对象
*/
public static LocalDateTime parse(CharSequence text, String pattern) {
return LocalDateTime.parse(text, DateTimeFormatter.ofPattern(pattern));
}

public static LocalDateTime parse(CharSequence text) {
return LocalDateTime.parse(text, dateTimeDefaultFormatter);
}

public static LocalDateTime parsePeriod(CharSequence text) {
return parsePeriodDate(text).atStartOfDay();
}

public static LocalDate parseDate(CharSequence text, String pattern) {
return LocalDate.parse(text, DateTimeFormatter.ofPattern(pattern));
}

public static LocalDate parseDate(CharSequence text) {
return LocalDate.parse(text, dateDefaultFormatter);
}

public static LocalDate parsePeriodDate(CharSequence text) {
return LocalDate.parse(text, new DateTimeFormatterBuilder()
.appendPattern("yyyy-MM")
.parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
.toFormatter());
}

/**
* 将本地时间对象转换为字符串
*/
public static String toString(LocalDateTime time, String pattern) {
if (time == null) return null;
return DateTimeFormatter.ofPattern(pattern).format(time);
}

public static String toString(LocalDateTime time) {
if (time == null) return null;
return toString(time, dateTimeDefaultFormatter.format(time));
}

public static String toString(LocalDate time, String pattern) {
if (time == null) return null;
return DateTimeFormatter.ofPattern(pattern).format(time);
}

public static String toString(LocalDate time) {
if (time == null) return null;
return toString(time, dateDefaultFormatter.format(time));
}

/**
* date转成对应的月份,格式:2020-01
*/
public static String toMonth(LocalDateTime localDateTime) {
String str = localDateTime.format(monthFormatter);
return str;
}

public static String toMonth(LocalDate localDate) {
String str = localDate.format(monthFormatter);
return str;
}

public static String toTime(LocalDateTime localDateTime) {
String str = localDateTime.format(timeFormatter);
return str;
}

/**
* 时间比较
*/
public static LocalDateTime max(LocalDateTime src, LocalDateTime des) {
return src.isAfter(des) ? src : des;
}

public static LocalDateTime min(LocalDateTime src, LocalDateTime des) {
return src.isBefore(des) ? src : des;
}

public static LocalDate max(LocalDate src, LocalDate des) {
return src.isAfter(des) ? src : des;
}

public static LocalDate min(LocalDate src, LocalDate des) {
return src.isBefore(des) ? src : des;
}

/**
* 获取特殊日期
*/
public static LocalDate firstDateInMonth(LocalDate date) {
return date.with(TemporalAdjusters.firstDayOfMonth());
}

public static LocalDate lastDateInMonth(LocalDate date) {
return date.with(TemporalAdjusters.lastDayOfMonth());
}

public static LocalDateTime firstDateTimeInMonth(LocalDateTime date) {
return date.with(TemporalAdjusters.firstDayOfMonth());
}

public static LocalDateTime lastDateTimeInMonth(LocalDateTime date) {
return date.with(TemporalAdjusters.lastDayOfMonth());
}

public static Date localDateTime2Date(LocalDateTime localDateTime) {
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime zdt = localDateTime.atZone(zoneId);
return Date.from(zdt.toInstant());
}

public static Date localDate2Date(LocalDate localDate) {
return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}

public static LocalDateTime date2LocalDateTime(Date date) {
ZoneId zoneId = ZoneId.systemDefault();
return LocalDateTime.ofInstant(date.toInstant(), zoneId);
}

public static LocalDate date2LocalDate(Date date) {
ZoneId zoneId = ZoneId.systemDefault();
return LocalDateTime.ofInstant(date.toInstant(), zoneId).toLocalDate();
}
}

LocalDate工具类

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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package com.imaxun.demo.framework.common.util;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;

public class DateTimeUtils {
public static final DateTimeFormatter dateTimeDefaultFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
public static final DateTimeFormatter dateDefaultFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
public static final DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
public static final DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
public static final ZoneOffset defaultZoneOffset = ZoneOffset.systemDefault()
.getRules().getOffset(Instant.now());

/**
* 获取本地时间(LocalDate)
*/
public static LocalDate now() {
return LocalDate.now();
}

public static LocalDateTime nowTime() {
return LocalDateTime.now();
}

public static long nowEpochSecond() {
return Instant.now().getEpochSecond();
}

public static long nowEpochMillisecond() {
return Instant.now().toEpochMilli();
}

/**
* 本地时间对象转换为unix时间戳(毫秒/秒)
*/
public static long toEpochSecond(LocalDateTime time, ZoneOffset zoneOffset) {
return time.toEpochSecond(zoneOffset);
}

public static long toEpochSecond(LocalDateTime time) {
return toEpochSecond(time, defaultZoneOffset);
}

public static long toEpochSecondByDay(LocalDate time, ZoneOffset zoneOffset) {
return toEpochSecond(LocalDateTime.of(time, LocalTime.parse("00:00:00")), zoneOffset);
}

public static long toEpochSecondByDay(LocalDate time) {
return toEpochSecondByDay(time, defaultZoneOffset);
}

public static long toEpochMillisecondByDay(LocalDate time, ZoneOffset zoneOffset) {
return toEpochMillisecond(LocalDateTime.of(time, LocalTime.parse("00:00:00")), zoneOffset);
}

public static long toEpochMillisecondByDay(LocalDate time) {
return toEpochMillisecond(LocalDateTime.of(time, LocalTime.parse("00:00:00")), defaultZoneOffset);
}

public static long toEpochMillisecond(LocalDateTime time, ZoneOffset zoneOffset) {
return time.toInstant(zoneOffset).toEpochMilli();
}

public static long toEpochMillisecond(LocalDateTime time) {
return toEpochMillisecond(time, defaultZoneOffset);
}

/**
* unix时间戳(毫秒/秒)转换为本地时间对象
*/
public static LocalDateTime ofEpochSecond(long second, ZoneOffset zoneOffset) {
return second <= 0 ? null : LocalDateTime.ofEpochSecond(second, 0, zoneOffset);
}

public static LocalDate ofEpochSecondToDate(long second, ZoneOffset zoneOffset) {
return second <= 0 ? null : LocalDateTime.ofEpochSecond(second, 0, zoneOffset).toLocalDate();
}


public static LocalDateTime ofEpochSecond(long second) {
return ofEpochSecond(second, defaultZoneOffset);
}


public static LocalDate ofEpochSecondToDate(long second) {
return ofEpochSecondToDate(second, defaultZoneOffset);
}

public static LocalDateTime ofEpochMillisecond(long millisecond, ZoneOffset zoneOffset) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(millisecond), zoneOffset);
}

public static LocalDateTime ofEpochMillisecond(long millisecond) {
return ofEpochMillisecond(millisecond, defaultZoneOffset);
}

public static LocalDate ofEpochMillisecondToDate(long millisecond, ZoneOffset zoneOffset) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(millisecond), zoneOffset).toLocalDate();
}

public static LocalDate ofEpochMillisecondToDate(long millisecond) {
return ofEpochMillisecondToDate(millisecond, defaultZoneOffset);
}

/**
* 将字符串转换为本地时间对象
*/
public static LocalDateTime parse(CharSequence text, String pattern) {
return LocalDateTime.parse(text, DateTimeFormatter.ofPattern(pattern));
}

public static LocalDateTime parse(CharSequence text) {
return LocalDateTime.parse(text, dateTimeDefaultFormatter);
}

public static LocalDateTime parsePeriod(CharSequence text) {
return parsePeriodDate(text).atStartOfDay();
}

public static LocalDate parseDate(CharSequence text, String pattern) {
return LocalDate.parse(text, DateTimeFormatter.ofPattern(pattern));
}

public static LocalDate parseDate(CharSequence text) {
return LocalDate.parse(text, dateDefaultFormatter);
}

public static LocalDate parsePeriodDate(CharSequence text) {
return LocalDate.parse(text, new DateTimeFormatterBuilder()
.appendPattern("yyyy-MM")
.parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
.toFormatter());
}

/**
* 将本地时间对象转换为字符串
*/
public static String toString(LocalDateTime time, String pattern) {
if (time == null) return null;
return DateTimeFormatter.ofPattern(pattern).format(time);
}

public static String toString(LocalDateTime time) {
if (time == null) return null;
return toString(time, dateTimeDefaultFormatter.format(time));
}

public static String toString(LocalDate time, String pattern) {
if (time == null) return null;
return DateTimeFormatter.ofPattern(pattern).format(time);
}

public static String toString(LocalDate time) {
if (time == null) return null;
return toString(time, dateDefaultFormatter.format(time));
}

/**
* date转成对应的月份,格式:2020-01
*/
public static String toMonth(LocalDateTime localDateTime) {
String str = localDateTime.format(monthFormatter);
return str;
}

public static String toMonth(LocalDate localDate) {
String str = localDate.format(monthFormatter);
return str;
}

public static String toTime(LocalDateTime localDateTime) {
String str = localDateTime.format(timeFormatter);
return str;
}

/**
* 时间比较
*/
public static LocalDateTime max(LocalDateTime src, LocalDateTime des) {
return src.isAfter(des) ? src : des;
}

public static LocalDateTime min(LocalDateTime src, LocalDateTime des) {
return src.isBefore(des) ? src : des;
}

public static LocalDate max(LocalDate src, LocalDate des) {
return src.isAfter(des) ? src : des;
}

public static LocalDate min(LocalDate src, LocalDate des) {
return src.isBefore(des) ? src : des;
}

/**
* 获取特殊日期
*/
public static LocalDate firstDateInMonth(LocalDate date) {
return date.with(TemporalAdjusters.firstDayOfMonth());
}

public static LocalDate lastDateInMonth(LocalDate date) {
return date.with(TemporalAdjusters.lastDayOfMonth());
}

public static LocalDateTime firstDateTimeInMonth(LocalDateTime date) {
return date.with(TemporalAdjusters.firstDayOfMonth());
}

public static LocalDateTime lastDateTimeInMonth(LocalDateTime date) {
return date.with(TemporalAdjusters.lastDayOfMonth());
}

public static Date localDateTime2Date(LocalDateTime localDateTime) {
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime zdt = localDateTime.atZone(zoneId);
return Date.from(zdt.toInstant());
}

public static Date localDate2Date(LocalDate localDate) {
return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}

public static LocalDateTime date2LocalDateTime(Date date) {
ZoneId zoneId = ZoneId.systemDefault();
return LocalDateTime.ofInstant(date.toInstant(), zoneId);
}

public static LocalDate date2LocalDate(Date date) {
ZoneId zoneId = ZoneId.systemDefault();
return LocalDateTime.ofInstant(date.toInstant(), zoneId).toLocalDate();
}
}


String工具类

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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
package com.imaxun.demo.framework.common.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import org.springframework.util.AntPathMatcher;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class StringUtils extends org.apache.commons.lang3.StringUtils {
public static String upperToUnderScore(String word) {
return word.replaceAll("(.)(\\p{Upper})", "$1_$2").toLowerCase();
}

public static String joinString(String[] list, String splitor) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.length; i++) {
sb.append(list[i]);
if (i < list.length - 1) {
sb.append(splitor);
}
}
return sb.toString();
}

public static boolean isNullOrEmpty(String str) {
return !hasLength(str);
}

public static boolean isNullOrBlank(String str) {
return !hasText(str);
}

public static boolean hasText(CharSequence str) {
if (!hasLength(str)) {
return false;
}
int strLen = str.length();
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(str.charAt(i))) {
return true;
}
}
return false;
}

public static boolean hasLength(CharSequence str) {
return (str != null && str.length() > 0);
}

/**
* 获取参数不为空值
*
* @param str defaultValue 要判断的value
* @return value 返回值
*/
public static String blankToDefault(String str, String defaultValue) {
return StrUtil.blankToDefault(str, defaultValue);
}

/**
* * 判断一个字符串是否为空串
*
* @param str String
* @return true:为空 false:非空
*/
public static boolean isEmpty(String str) {
return StrUtil.isEmpty(str);
}

/**
* * 判断一个字符串是否为非空串
*
* @param str String
* @return true:非空串 false:空串
*/
public static boolean isNotEmpty(String str) {
return !isEmpty(str);
}

/**
* 去空格
*/
public static String trim(String str) {
return StrUtil.trim(str);
}

/**
* 截取字符串
*
* @param str 字符串
* @param start 开始
* @return 结果
*/
public static String substring(final String str, int start) {
return substring(str, start, str.length());
}

/**
* 截取字符串
*
* @param str 字符串
* @param start 开始
* @param end 结束
* @return 结果
*/
public static String substring(final String str, int start, int end) {
return StrUtil.sub(str, start, end);
}

/**
* 格式化文本, {} 表示占位符<br>
* 此方法只是简单将占位符 {} 按照顺序替换为参数<br>
* 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br>
* 例:<br>
* 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br>
* 转义{}: format("this is \\{} for {}", "a", "b") -> this is {} for a<br>
* 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
*
* @param template 文本模板,被替换的部分用 {} 表示
* @param params 参数值
* @return 格式化后的文本
*/
public static String format(String template, Object... params) {
return StrUtil.format(template, params);
}

/**
* 是否为http(s)://开头
*
* @param link 链接
* @return 结果
*/
public static boolean isHttp(String link) {
return Validator.isUrl(link);
}

/**
* 字符串转set
*
* @param str 字符串
* @param sep 分隔符
* @return set集合
*/
public static Set<String> str2Set(String str, String sep) {
return new HashSet<>(str2List(str, sep, true, false));
}

/**
* 字符串转list
*
* @param str 字符串
* @param sep 分隔符
* @param filterBlank 过滤纯空白
* @param trim 去掉首尾空白
* @return list集合
*/
public static List<String> str2List(String str, String sep, boolean filterBlank, boolean trim) {
List<String> list = new ArrayList<>();
if (isEmpty(str)) {
return list;
}

// 过滤空白字符串
if (filterBlank && isBlank(str)) {
return list;
}
String[] split = str.split(sep);
for (String string : split) {
if (filterBlank && isBlank(string)) {
continue;
}
if (trim) {
string = trim(string);
}
list.add(string);
}

return list;
}

/**
* 查找指定字符串是否包含指定字符串列表中的任意一个字符串同时串忽略大小写
*
* @param cs 指定字符串
* @param searchCharSequences 需要检查的字符串数组
* @return 是否包含任意一个字符串
*/
public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences) {
return StrUtil.containsAnyIgnoreCase(cs, searchCharSequences);
}

/**
* 驼峰转下划线命名
*/
public static String toUnderScoreCase(String str) {
return StrUtil.toUnderlineCase(str);
}

/**
* 是否包含字符串
*
* @param str 验证字符串
* @param strs 字符串组
* @return 包含返回true
*/
public static boolean inStringIgnoreCase(String str, String... strs) {
return StrUtil.equalsAnyIgnoreCase(str, strs);
}

/**
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld
*
* @param name 转换前的下划线大写方式命名的字符串
* @return 转换后的驼峰式命名的字符串
*/
public static String convertToCamelCase(String name) {
return StrUtil.upperFirst(StrUtil.toCamelCase(name));
}

/**
* 驼峰式命名法 例如:user_name->userName
*/
public static String toCamelCase(String s) {
return StrUtil.toCamelCase(s);
}

/**
* 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
*
* @param str 指定字符串
* @param strs 需要检查的字符串数组
* @return 是否匹配
*/
public static boolean matches(String str, List<String> strs) {
if (isEmpty(str) || CollUtil.isEmpty(strs)) {
return false;
}
for (String pattern : strs) {
if (isMatch(pattern, str)) {
return true;
}
}
return false;
}

/**
* 判断url是否与规则配置:
* ? 表示单个字符;
* * 表示一层路径内的任意字符串,不可跨层级;
* ** 表示任意层路径;
*
* @param pattern 匹配规则
* @param url 需要匹配的url
* @return
*/
public static boolean isMatch(String pattern, String url) {
AntPathMatcher matcher = new AntPathMatcher();
return matcher.match(pattern, url);
}

/**
* 数字左边补齐0,使之达到指定长度。注意,如果数字转换为字符串后,长度大于size,则只保留 最后size个字符。
*
* @param num 数字对象
* @param size 字符串指定长度
* @return 返回数字的字符串格式,该字符串为指定长度。
*/
public static final String fillUp(final Number num, final int size) {
return fillUp(num.toString(), size, '0');
}

/**
* 字符串左补齐。如果原始字符串s长度大于size,则只保留最后size个字符。
*
* @param s 原始字符串
* @param size 字符串指定长度
* @param c 用于补齐的字符
* @return 返回指定长度的字符串,由原字符串左补齐或截取得到。
*/
public static String fillUp(final String s, final int size, final char c) {
final StringBuilder sb = new StringBuilder(size);
if (s != null) {
final int len = s.length();
if (s.length() <= size) {
for (int i = size - len; i > 0; i--) {
sb.append(c);
}
sb.append(s);
}
else {
return s.substring(len - size, len);
}
}
else {
for (int i = size; i > 0; i--) {
sb.append(c);
}
}
return sb.toString();
}

public static boolean startWithAny(String str, Collection<String> prefixes) {
if (isEmpty(str) || ArrayUtil.isEmpty(prefixes)) {
return false;
}

for (CharSequence suffix : prefixes) {
if (StrUtil.startWith(str, suffix, false)) {
return true;
}
}
return false;
}
}
}