All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.ludii.excel.utils.ExcelUtils Maven / Gradle / Ivy
package com.ludii.excel.utils;
import java.lang.reflect.Field;
import java.text.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* @author 陆迪
* @date 2022/3/23
*/
public class ExcelUtils {
public static final String EMPTY = "";
private ExcelUtils() {
}
public final static String[] DATE_PARSE_PATTERNS = {
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM-dd HH", "yyyy-MM",
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM/dd HH", "yyyy/MM",
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM.dd HH", "yyyy.MM",
"yyyy年MM月dd日", "yyyy年MM月dd日 HH时mm分ss秒", "yyyy年MM月dd日 HH时mm分", "yyyy年MM月dd日 HH时", "yyyy年MM月",
"yyyyMMdd", "yyyyMM", "yyyy"};
/**
* 日期型字符串转化为日期 格式 see to DateUtils#parsePatterns
*/
public static Date parseDate(Object val) {
return parseDate(toString(val));
}
public static Date parseDate(String str) {
if (str == null) {
return null;
}
try {
return DateUtils.parseDate(str, DATE_PARSE_PATTERNS);
} catch (ParseException e) {
return null;
}
}
public static LocalDate convertToLocalDate(Date date) {
return DateUtils.convertToLocalDate(date);
}
public static LocalDateTime convertToLocalDateTime(Date date) {
return DateUtils.convertToLocalDateTime(date);
}
public static String toString(Object val) {
return val == null ? null : val.toString();
}
public static boolean isBlank(String str) {
return StringUtils.isBlank(str);
}
public static String xssFilter(String text) {
return EncodeUtils.xssFilter(text);
}
public static Field[] getAllDeclaredFields(Class> clazz) {
List fieldList = new ArrayList<>();
Field[] fields = clazz.getDeclaredFields();
if (fields.length > 0) {
fieldList.addAll(Arrays.asList(fields));
}
Class> superClazz = clazz.getSuperclass();
while (superClazz != Object.class) {
Field[] superFields = superClazz.getDeclaredFields();
if (superFields.length > 0) {
fieldList.addAll(0, Arrays.asList(superFields));
}
superClazz = superClazz.getSuperclass();
}
return fieldList.toArray(new Field[0]);
}
public static void invokeSetter(Object obj, String propertyName, E value) {
ReflectUtils.invokeSetter(obj, propertyName, value);
}
public static E invokeMethod(final Object obj, final String methodName, final Class>[] parameterTypes,
final Object[] args) {
return ReflectUtils.invokeMethod(obj, methodName, parameterTypes, args);
}
public static E invokeGetter(Object obj, String propertyName) {
return ReflectUtils.invokeGetter(obj, propertyName);
}
public static boolean isNotBlank(final CharSequence cs) {
return StringUtils.isNotBlank(cs);
}
public static boolean endsWith(final CharSequence str, final CharSequence suffix) {
return StringUtils.endsWith(str, suffix);
}
public static String substringBefore(final String str, final String separator) {
return StringUtils.substringBefore(str, separator);
}
public static boolean equals(final CharSequence cs1, final CharSequence cs2) {
return StringUtils.equals(cs1, cs2);
}
public static String substringAfter(final String str, final String separator) {
return StringUtils.substringAfter(str, separator);
}
public static String[] split(final String str, final String separatorChars, final int max) {
return StringUtils.split(str, separatorChars, max);
}
public static String defaultString(final String str, final String defaultStr) {
return StringUtils.defaultString(str, defaultStr);
}
}