¶Ô±ÈÐÂÎļþ |
| | |
| | | /* |
| | | * Copyright (c) 2018-2028, DreamLu All rights reserved. |
| | | * |
| | | * Redistribution and use in source and binary forms, with or without |
| | | * modification, are permitted provided that the following conditions are met: |
| | | * |
| | | * Redistributions of source code must retain the above copyright notice, |
| | | * this list of conditions and the following disclaimer. |
| | | * Redistributions in binary form must reproduce the above copyright |
| | | * notice, this list of conditions and the following disclaimer in the |
| | | * documentation and/or other materials provided with the distribution. |
| | | * Neither the name of the dreamlu.net developer nor the names of its |
| | | * contributors may be used to endorse or promote products derived from |
| | | * this software without specific prior written permission. |
| | | * Author: DreamLu 墿¥æ¢¦ (596392912@qq.com) |
| | | */ |
| | | package org.springblade.core.tool.utils; |
| | | |
| | | import com.fasterxml.jackson.core.JsonParser; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import org.springblade.core.tool.jackson.JsonUtil; |
| | | import org.springframework.beans.BeansException; |
| | | import org.springframework.core.MethodParameter; |
| | | import org.springframework.core.annotation.AnnotatedElementUtils; |
| | | import org.springframework.core.convert.TypeDescriptor; |
| | | import org.springframework.lang.Nullable; |
| | | import org.springframework.util.PatternMatchUtils; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.method.HandlerMethod; |
| | | |
| | | import java.io.Closeable; |
| | | import java.io.File; |
| | | import java.io.InputStream; |
| | | import java.lang.annotation.Annotation; |
| | | import java.lang.reflect.AnnotatedElement; |
| | | import java.lang.reflect.Constructor; |
| | | import java.lang.reflect.Method; |
| | | import java.nio.charset.Charset; |
| | | import java.text.DecimalFormat; |
| | | import java.time.Duration; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.Temporal; |
| | | import java.time.temporal.TemporalAccessor; |
| | | import java.util.*; |
| | | import java.util.function.Supplier; |
| | | |
| | | /** |
| | | * å·¥å
·å
éåï¼å·¥å
·ç±»å¿«æ·æ¹å¼ |
| | | * |
| | | * @author L.cm |
| | | */ |
| | | public class Func { |
| | | |
| | | /** |
| | | * æè¨ï¼å¿
é¡»ä¸è½ä¸º null |
| | | * <blockquote><pre> |
| | | * public Foo(Bar bar) { |
| | | * this.bar = $.requireNotNull(bar); |
| | | * } |
| | | * </pre></blockquote> |
| | | * |
| | | * @param obj the object reference to check for nullity |
| | | * @param <T> the type of the reference |
| | | * @return {@code obj} if not {@code null} |
| | | * @throws NullPointerException if {@code obj} is {@code null} |
| | | */ |
| | | public static <T> T requireNotNull(T obj) { |
| | | return Objects.requireNonNull(obj); |
| | | } |
| | | |
| | | /** |
| | | * æè¨ï¼å¿
é¡»ä¸è½ä¸º null |
| | | * <blockquote><pre> |
| | | * public Foo(Bar bar, Baz baz) { |
| | | * this.bar = $.requireNotNull(bar, "bar must not be null"); |
| | | * this.baz = $.requireNotNull(baz, "baz must not be null"); |
| | | * } |
| | | * </pre></blockquote> |
| | | * |
| | | * @param obj the object reference to check for nullity |
| | | * @param message detail message to be used in the event that a {@code |
| | | * NullPointerException} is thrown |
| | | * @param <T> the type of the reference |
| | | * @return {@code obj} if not {@code null} |
| | | * @throws NullPointerException if {@code obj} is {@code null} |
| | | */ |
| | | public static <T> T requireNotNull(T obj, String message) { |
| | | return Objects.requireNonNull(obj, message); |
| | | } |
| | | |
| | | /** |
| | | * æè¨ï¼å¿
é¡»ä¸è½ä¸º null |
| | | * <blockquote><pre> |
| | | * public Foo(Bar bar, Baz baz) { |
| | | * this.bar = $.requireNotNull(bar, () -> "bar must not be null"); |
| | | * } |
| | | * </pre></blockquote> |
| | | * |
| | | * @param obj the object reference to check for nullity |
| | | * @param messageSupplier supplier of the detail message to be |
| | | * used in the event that a {@code NullPointerException} is thrown |
| | | * @param <T> the type of the reference |
| | | * @return {@code obj} if not {@code null} |
| | | * @throws NullPointerException if {@code obj} is {@code null} |
| | | */ |
| | | public static <T> T requireNotNull(T obj, Supplier<String> messageSupplier) { |
| | | return Objects.requireNonNull(obj, messageSupplier); |
| | | } |
| | | |
| | | /** |
| | | * å¤æå¯¹è±¡æ¯å¦ä¸ºnull |
| | | * <p> |
| | | * This method exists to be used as a |
| | | * {@link java.util.function.Predicate}, {@code filter($::isNull)} |
| | | * </p> |
| | | * |
| | | * @param obj a reference to be checked against {@code null} |
| | | * @return {@code true} if the provided reference is {@code null} otherwise |
| | | * {@code false} |
| | | * @see java.util.function.Predicate |
| | | */ |
| | | public static boolean isNull(@Nullable Object obj) { |
| | | return Objects.isNull(obj); |
| | | } |
| | | |
| | | /** |
| | | * å¤æå¯¹è±¡æ¯å¦ not null |
| | | * <p> |
| | | * This method exists to be used as a |
| | | * {@link java.util.function.Predicate}, {@code filter($::notNull)} |
| | | * </p> |
| | | * |
| | | * @param obj a reference to be checked against {@code null} |
| | | * @return {@code true} if the provided reference is non-{@code null} |
| | | * otherwise {@code false} |
| | | * @see java.util.function.Predicate |
| | | */ |
| | | public static boolean notNull(@Nullable Object obj) { |
| | | return Objects.nonNull(obj); |
| | | } |
| | | |
| | | /** |
| | | * é¦åæ¯åå°å |
| | | * |
| | | * @param str å符串 |
| | | * @return {String} |
| | | */ |
| | | public static String firstCharToLower(String str) { |
| | | return StringUtil.firstCharToLower(str); |
| | | } |
| | | |
| | | /** |
| | | * é¦åæ¯å大å |
| | | * |
| | | * @param str å符串 |
| | | * @return {String} |
| | | */ |
| | | public static String firstCharToUpper(String str) { |
| | | return StringUtil.firstCharToUpper(str); |
| | | } |
| | | |
| | | /** |
| | | * 夿æ¯å¦ä¸ºç©ºå符串 |
| | | * <pre class="code"> |
| | | * $.isBlank(null) = true |
| | | * $.isBlank("") = true |
| | | * $.isBlank(" ") = true |
| | | * $.isBlank("12345") = false |
| | | * $.isBlank(" 12345 ") = false |
| | | * </pre> |
| | | * |
| | | * @param cs the {@code CharSequence} to check (may be {@code null}) |
| | | * @return {@code true} if the {@code CharSequence} is not {@code null}, |
| | | * its length is greater than 0, and it does not contain whitespace only |
| | | * @see Character#isWhitespace |
| | | */ |
| | | public static boolean isBlank(@Nullable final CharSequence cs) { |
| | | return StringUtil.isBlank(cs); |
| | | } |
| | | |
| | | /** |
| | | * 夿ä¸ä¸ºç©ºå符串 |
| | | * <pre> |
| | | * $.isNotBlank(null) = false |
| | | * $.isNotBlank("") = false |
| | | * $.isNotBlank(" ") = false |
| | | * $.isNotBlank("bob") = true |
| | | * $.isNotBlank(" bob ") = true |
| | | * </pre> |
| | | * |
| | | * @param cs the CharSequence to check, may be null |
| | | * @return {@code true} if the CharSequence is |
| | | * not empty and not null and not whitespace |
| | | * @see Character#isWhitespace |
| | | */ |
| | | public static boolean isNotBlank(@Nullable final CharSequence cs) { |
| | | return StringUtil.isNotBlank(cs); |
| | | } |
| | | |
| | | /** |
| | | * 夿æ¯å¦æä»»æä¸ä¸ª 空å符串 |
| | | * |
| | | * @param css CharSequence |
| | | * @return boolean |
| | | */ |
| | | public static boolean isAnyBlank(final CharSequence... css) { |
| | | return StringUtil.isAnyBlank(css); |
| | | } |
| | | |
| | | /** |
| | | * 夿æ¯å¦å
¨ä¸ºé空å符串 |
| | | * |
| | | * @param css CharSequence |
| | | * @return boolean |
| | | */ |
| | | public static boolean isNoneBlank(final CharSequence... css) { |
| | | return StringUtil.isNoneBlank(css); |
| | | } |
| | | |
| | | /** |
| | | * å¤æå¯¹è±¡æ¯æ°ç» |
| | | * |
| | | * @param obj the object to check |
| | | * @return æ¯å¦æ°ç» |
| | | */ |
| | | public static boolean isArray(@Nullable Object obj) { |
| | | return ObjectUtil.isArray(obj); |
| | | } |
| | | |
| | | /** |
| | | * å¤æç©ºå¯¹è±¡ objectãmapãlistãsetãåç¬¦ä¸²ãæ°ç» |
| | | * |
| | | * @param obj the object to check |
| | | * @return æ°ç»æ¯å¦ä¸ºç©º |
| | | */ |
| | | public static boolean isEmpty(@Nullable Object obj) { |
| | | return ObjectUtil.isEmpty(obj); |
| | | } |
| | | |
| | | /** |
| | | * 对象ä¸ä¸ºç©º objectãmapãlistãsetãåç¬¦ä¸²ãæ°ç» |
| | | * |
| | | * @param obj the object to check |
| | | * @return æ¯å¦ä¸ä¸ºç©º |
| | | */ |
| | | public static boolean isNotEmpty(@Nullable Object obj) { |
| | | return !ObjectUtil.isEmpty(obj); |
| | | } |
| | | |
| | | /** |
| | | * 夿æ°ç»ä¸ºç©º |
| | | * |
| | | * @param array the array to check |
| | | * @return æ°ç»æ¯å¦ä¸ºç©º |
| | | */ |
| | | public static boolean isEmpty(@Nullable Object[] array) { |
| | | return ObjectUtil.isEmpty(array); |
| | | } |
| | | |
| | | /** |
| | | * 夿æ°ç»ä¸ä¸ºç©º |
| | | * |
| | | * @param array æ°ç» |
| | | * @return æ°ç»æ¯å¦ä¸ä¸ºç©º |
| | | */ |
| | | public static boolean isNotEmpty(@Nullable Object[] array) { |
| | | return ObjectUtil.isNotEmpty(array); |
| | | } |
| | | |
| | | /** |
| | | * 对象ç»ä¸æ¯å¦åå¨ Empty Object |
| | | * |
| | | * @param os å¯¹è±¡ç» |
| | | * @return boolean |
| | | */ |
| | | public static boolean hasEmpty(Object... os) { |
| | | for (Object o : os) { |
| | | if (isEmpty(o)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 对象ç»ä¸æ¯å¦å
¨é¨ä¸º Empty Object |
| | | * |
| | | * @param os å¯¹è±¡ç» |
| | | * @return boolean |
| | | */ |
| | | public static boolean isAllEmpty(Object... os) { |
| | | for (Object o : os) { |
| | | if (isNotEmpty(o)) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * å°å符串ä¸ç¹å®æ¨¡å¼çåç¬¦è½¬æ¢æmapä¸å¯¹åºçå¼ |
| | | * <p> |
| | | * use: format("my name is ${name}, and i like ${like}!", {"name":"L.cm", "like": "Java"}) |
| | | * |
| | | * @param message éè¦è½¬æ¢çå符串 |
| | | * @param params è½¬æ¢æéçé®å¼å¯¹éå |
| | | * @return 转æ¢åçå符串 |
| | | */ |
| | | public static String format(@Nullable String message, @Nullable Map<String, ?> params) { |
| | | return StringUtil.format(message, params); |
| | | } |
| | | |
| | | /** |
| | | * å log æ ¼å¼ç format è§å |
| | | * <p> |
| | | * use: format("my name is {}, and i like {}!", "L.cm", "Java") |
| | | * |
| | | * @param message éè¦è½¬æ¢çå符串 |
| | | * @param arguments éè¦æ¿æ¢çåé |
| | | * @return 转æ¢åçå符串 |
| | | */ |
| | | public static String format(@Nullable String message, @Nullable Object... arguments) { |
| | | return StringUtil.format(message, arguments); |
| | | } |
| | | |
| | | /** |
| | | * æ ¼å¼åæ§è¡æ¶é´ï¼åä½ä¸º ms å sï¼ä¿çä¸ä½å°æ° |
| | | * |
| | | * @param nanos çº³ç§ |
| | | * @return æ ¼å¼ååçæ¶é´ |
| | | */ |
| | | public static String format(long nanos) { |
| | | return StringUtil.format(nanos); |
| | | } |
| | | |
| | | /** |
| | | * æ¯è¾ä¸¤ä¸ªå¯¹è±¡æ¯å¦ç¸çã<br> |
| | | * ç¸åçæ¡ä»¶æä¸¤ä¸ªï¼æ»¡è¶³å
¶ä¸å³å¯ï¼<br> |
| | | * |
| | | * @param obj1 对象1 |
| | | * @param obj2 对象2 |
| | | * @return æ¯å¦ç¸ç |
| | | */ |
| | | public static boolean equals(Object obj1, Object obj2) { |
| | | return Objects.equals(obj1, obj2); |
| | | } |
| | | |
| | | /** |
| | | * å®å
¨ç equals |
| | | * |
| | | * @param o1 first Object to compare |
| | | * @param o2 second Object to compare |
| | | * @return whether the given objects are equal |
| | | * @see Object#equals(Object) |
| | | * @see java.util.Arrays#equals |
| | | */ |
| | | public static boolean equalsSafe(@Nullable Object o1, @Nullable Object o2) { |
| | | return ObjectUtil.nullSafeEquals(o1, o2); |
| | | } |
| | | |
| | | /** |
| | | * 夿æ°ç»ä¸æ¯å¦å
å«å
ç´ |
| | | * |
| | | * @param array the Array to check |
| | | * @param element the element to look for |
| | | * @param <T> The generic tag |
| | | * @return {@code true} if found, {@code false} else |
| | | */ |
| | | public static <T> boolean contains(@Nullable T[] array, final T element) { |
| | | return CollectionUtil.contains(array, element); |
| | | } |
| | | |
| | | /** |
| | | * 夿è¿ä»£å¨ä¸æ¯å¦å
å«å
ç´ |
| | | * |
| | | * @param iterator the Iterator to check |
| | | * @param element the element to look for |
| | | * @return {@code true} if found, {@code false} otherwise |
| | | */ |
| | | public static boolean contains(@Nullable Iterator<?> iterator, Object element) { |
| | | return CollectionUtil.contains(iterator, element); |
| | | } |
| | | |
| | | /** |
| | | * 夿æä¸¾æ¯å¦å
å«è¯¥å
ç´ |
| | | * |
| | | * @param enumeration the Enumeration to check |
| | | * @param element the element to look for |
| | | * @return {@code true} if found, {@code false} otherwise |
| | | */ |
| | | public static boolean contains(@Nullable Enumeration<?> enumeration, Object element) { |
| | | return CollectionUtil.contains(enumeration, element); |
| | | } |
| | | |
| | | /** |
| | | * ä¸å¯å Set |
| | | * |
| | | * @param es 对象 |
| | | * @param <E> æ³å |
| | | * @return éå |
| | | */ |
| | | @SafeVarargs |
| | | public static <E> Set<E> ofImmutableSet(E... es) { |
| | | return CollectionUtil.ofImmutableSet(es); |
| | | } |
| | | |
| | | /** |
| | | * ä¸å¯å List |
| | | * |
| | | * @param es 对象 |
| | | * @param <E> æ³å |
| | | * @return éå |
| | | */ |
| | | @SafeVarargs |
| | | public static <E> List<E> ofImmutableList(E... es) { |
| | | return CollectionUtil.ofImmutableList(es); |
| | | } |
| | | |
| | | /** |
| | | * 强转string,并廿å¤ä½ç©ºæ ¼ |
| | | * |
| | | * @param str å符串 |
| | | * @return {String} |
| | | */ |
| | | public static String toStr(Object str) { |
| | | return toStr(str, ""); |
| | | } |
| | | |
| | | /** |
| | | * 强转string,并廿å¤ä½ç©ºæ ¼ |
| | | * |
| | | * @param str å符串 |
| | | * @param defaultValue é»è®¤å¼ |
| | | * @return {String} |
| | | */ |
| | | public static String toStr(Object str, String defaultValue) { |
| | | if (null == str || str.equals(StringPool.NULL)) { |
| | | return defaultValue; |
| | | } |
| | | return String.valueOf(str); |
| | | } |
| | | |
| | | /** |
| | | * 强转string(å
å«ç©ºå符串),并廿å¤ä½ç©ºæ ¼ |
| | | * |
| | | * @param str å符串 |
| | | * @param defaultValue é»è®¤å¼ |
| | | * @return {String} |
| | | */ |
| | | public static String toStrWithEmpty(Object str, String defaultValue) { |
| | | if (null == str || str.equals(StringPool.NULL) || str.equals(StringPool.EMPTY)) { |
| | | return defaultValue; |
| | | } |
| | | return String.valueOf(str); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 夿ä¸ä¸ªå符串æ¯å¦æ¯æ°å |
| | | * |
| | | * @param cs the CharSequence to check, may be null |
| | | * @return {boolean} |
| | | */ |
| | | public static boolean isNumeric(final CharSequence cs) { |
| | | return StringUtil.isNumeric(cs); |
| | | } |
| | | |
| | | /** |
| | | * å符串转 intï¼ä¸ºç©ºåè¿å0 |
| | | * |
| | | * <pre> |
| | | * $.toInt(null) = 0 |
| | | * $.toInt("") = 0 |
| | | * $.toInt("1") = 1 |
| | | * </pre> |
| | | * |
| | | * @param str the string to convert, may be null |
| | | * @return the int represented by the string, or <code>zero</code> if |
| | | * conversion fails |
| | | */ |
| | | public static int toInt(final Object str) { |
| | | return NumberUtil.toInt(String.valueOf(str)); |
| | | } |
| | | |
| | | /** |
| | | * å符串转 intï¼ä¸ºç©ºåè¿åé»è®¤å¼ |
| | | * |
| | | * <pre> |
| | | * $.toInt(null, 1) = 1 |
| | | * $.toInt("", 1) = 1 |
| | | * $.toInt("1", 0) = 1 |
| | | * </pre> |
| | | * |
| | | * @param str the string to convert, may be null |
| | | * @param defaultValue the default value |
| | | * @return the int represented by the string, or the default if conversion fails |
| | | */ |
| | | public static int toInt(@Nullable final Object str, final int defaultValue) { |
| | | return NumberUtil.toInt(String.valueOf(str), defaultValue); |
| | | } |
| | | |
| | | /** |
| | | * å符串转 longï¼ä¸ºç©ºåè¿å0 |
| | | * |
| | | * <pre> |
| | | * $.toLong(null) = 0L |
| | | * $.toLong("") = 0L |
| | | * $.toLong("1") = 1L |
| | | * </pre> |
| | | * |
| | | * @param str the string to convert, may be null |
| | | * @return the long represented by the string, or <code>0</code> if |
| | | * conversion fails |
| | | */ |
| | | public static long toLong(final Object str) { |
| | | return NumberUtil.toLong(String.valueOf(str)); |
| | | } |
| | | |
| | | /** |
| | | * å符串转 longï¼ä¸ºç©ºåè¿åé»è®¤å¼ |
| | | * |
| | | * <pre> |
| | | * $.toLong(null, 1L) = 1L |
| | | * $.toLong("", 1L) = 1L |
| | | * $.toLong("1", 0L) = 1L |
| | | * </pre> |
| | | * |
| | | * @param str the string to convert, may be null |
| | | * @param defaultValue the default value |
| | | * @return the long represented by the string, or the default if conversion fails |
| | | */ |
| | | public static long toLong(@Nullable final Object str, final long defaultValue) { |
| | | return NumberUtil.toLong(String.valueOf(str), defaultValue); |
| | | } |
| | | |
| | | /** |
| | | * <p>Convert a <code>String</code> to an <code>Double</code>, returning a |
| | | * default value if the conversion fails.</p> |
| | | * |
| | | * <p>If the string is <code>null</code>, the default value is returned.</p> |
| | | * |
| | | * <pre> |
| | | * $.toDouble(null, 1) = 1.0 |
| | | * $.toDouble("", 1) = 1.0 |
| | | * $.toDouble("1", 0) = 1.0 |
| | | * </pre> |
| | | * |
| | | * @param value the string to convert, may be null |
| | | * @return the int represented by the string, or the default if conversion fails |
| | | */ |
| | | public static Double toDouble(Object value) { |
| | | return toDouble(String.valueOf(value), -1.00); |
| | | } |
| | | |
| | | /** |
| | | * <p>Convert a <code>String</code> to an <code>Double</code>, returning a |
| | | * default value if the conversion fails.</p> |
| | | * |
| | | * <p>If the string is <code>null</code>, the default value is returned.</p> |
| | | * |
| | | * <pre> |
| | | * $.toDouble(null, 1) = 1.0 |
| | | * $.toDouble("", 1) = 1.0 |
| | | * $.toDouble("1", 0) = 1.0 |
| | | * </pre> |
| | | * |
| | | * @param value the string to convert, may be null |
| | | * @param defaultValue the default value |
| | | * @return the int represented by the string, or the default if conversion fails |
| | | */ |
| | | public static Double toDouble(Object value, Double defaultValue) { |
| | | return NumberUtil.toDouble(String.valueOf(value), defaultValue); |
| | | } |
| | | |
| | | /** |
| | | * <p>Convert a <code>String</code> to an <code>Float</code>, returning a |
| | | * default value if the conversion fails.</p> |
| | | * |
| | | * <p>If the string is <code>null</code>, the default value is returned.</p> |
| | | * |
| | | * <pre> |
| | | * $.toFloat(null, 1) = 1.00f |
| | | * $.toFloat("", 1) = 1.00f |
| | | * $.toFloat("1", 0) = 1.00f |
| | | * </pre> |
| | | * |
| | | * @param value the string to convert, may be null |
| | | * @return the int represented by the string, or the default if conversion fails |
| | | */ |
| | | public static Float toFloat(Object value) { |
| | | return toFloat(String.valueOf(value), -1.0f); |
| | | } |
| | | |
| | | /** |
| | | * <p>Convert a <code>String</code> to an <code>Float</code>, returning a |
| | | * default value if the conversion fails.</p> |
| | | * |
| | | * <p>If the string is <code>null</code>, the default value is returned.</p> |
| | | * |
| | | * <pre> |
| | | * $.toFloat(null, 1) = 1.00f |
| | | * $.toFloat("", 1) = 1.00f |
| | | * $.toFloat("1", 0) = 1.00f |
| | | * </pre> |
| | | * |
| | | * @param value the string to convert, may be null |
| | | * @param defaultValue the default value |
| | | * @return the int represented by the string, or the default if conversion fails |
| | | */ |
| | | public static Float toFloat(Object value, Float defaultValue) { |
| | | return NumberUtil.toFloat(String.valueOf(value), defaultValue); |
| | | } |
| | | |
| | | /** |
| | | * <p>Convert a <code>String</code> to an <code>Boolean</code>, returning a |
| | | * default value if the conversion fails.</p> |
| | | * |
| | | * <p>If the string is <code>null</code>, the default value is returned.</p> |
| | | * |
| | | * <pre> |
| | | * $.toBoolean("true", true) = true |
| | | * $.toBoolean("false") = false |
| | | * $.toBoolean("", false) = false |
| | | * </pre> |
| | | * |
| | | * @param value the string to convert, may be null |
| | | * @return the int represented by the string, or the default if conversion fails |
| | | */ |
| | | public static Boolean toBoolean(Object value) { |
| | | return toBoolean(value, null); |
| | | } |
| | | |
| | | /** |
| | | * <p>Convert a <code>String</code> to an <code>Boolean</code>, returning a |
| | | * default value if the conversion fails.</p> |
| | | * |
| | | * <p>If the string is <code>null</code>, the default value is returned.</p> |
| | | * |
| | | * <pre> |
| | | * $.toBoolean("true", true) = true |
| | | * $.toBoolean("false") = false |
| | | * $.toBoolean("", false) = false |
| | | * </pre> |
| | | * |
| | | * @param value the string to convert, may be null |
| | | * @param defaultValue the default value |
| | | * @return the int represented by the string, or the default if conversion fails |
| | | */ |
| | | public static Boolean toBoolean(Object value, Boolean defaultValue) { |
| | | if (value != null) { |
| | | String val = String.valueOf(value); |
| | | val = val.toLowerCase().trim(); |
| | | return Boolean.parseBoolean(val); |
| | | } |
| | | return defaultValue; |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºIntegeræ°ç»<br> |
| | | * |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Integer[] toIntArray(String str) { |
| | | return toIntArray(",", str); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºIntegeræ°ç»<br> |
| | | * |
| | | * @param split åé符 |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Integer[] toIntArray(String split, String str) { |
| | | if (StringUtil.isEmpty(str)) { |
| | | return new Integer[]{}; |
| | | } |
| | | String[] arr = str.split(split); |
| | | final Integer[] ints = new Integer[arr.length]; |
| | | for (int i = 0; i < arr.length; i++) { |
| | | final Integer v = toInt(arr[i], 0); |
| | | ints[i] = v; |
| | | } |
| | | return ints; |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºIntegeréå<br> |
| | | * |
| | | * @param str ç»æè¢«è½¬æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static List<Integer> toIntList(String str) { |
| | | return Arrays.asList(toIntArray(str)); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºIntegeréå<br> |
| | | * |
| | | * @param split åé符 |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static List<Integer> toIntList(String split, String str) { |
| | | return Arrays.asList(toIntArray(split, str)); |
| | | } |
| | | |
| | | /** |
| | | * è·å第ä¸ä½Integeræ°å¼ |
| | | * |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Integer firstInt(String str) { |
| | | return firstInt(",", str); |
| | | } |
| | | |
| | | /** |
| | | * è·å第ä¸ä½Integeræ°å¼ |
| | | * |
| | | * @param split åé符 |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Integer firstInt(String split, String str) { |
| | | List<Integer> ints = toIntList(split, str); |
| | | if (isEmpty(ints)) { |
| | | return null; |
| | | } else { |
| | | return ints.get(0); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºLongæ°ç»<br> |
| | | * |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Long[] toLongArray(String str) { |
| | | return toLongArray(",", str); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºLongæ°ç»<br> |
| | | * |
| | | * @param split åé符 |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Long[] toLongArray(String split, String str) { |
| | | if (StringUtil.isEmpty(str)) { |
| | | return new Long[]{}; |
| | | } |
| | | String[] arr = str.split(split); |
| | | final Long[] longs = new Long[arr.length]; |
| | | for (int i = 0; i < arr.length; i++) { |
| | | final Long v = toLong(arr[i], 0); |
| | | longs[i] = v; |
| | | } |
| | | return longs; |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºLongéå<br> |
| | | * |
| | | * @param str ç»æè¢«è½¬æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static List<Long> toLongList(String str) { |
| | | return Arrays.asList(toLongArray(str)); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºLongéå<br> |
| | | * |
| | | * @param split åé符 |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static List<Long> toLongList(String split, String str) { |
| | | return Arrays.asList(toLongArray(split, str)); |
| | | } |
| | | |
| | | /** |
| | | * è·å第ä¸ä½Longæ°å¼ |
| | | * |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Long firstLong(String str) { |
| | | return firstLong(",", str); |
| | | } |
| | | |
| | | /** |
| | | * è·å第ä¸ä½Longæ°å¼ |
| | | * |
| | | * @param split åé符 |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static Long firstLong(String split, String str) { |
| | | List<Long> longs = toLongList(split, str); |
| | | if (isEmpty(longs)) { |
| | | return null; |
| | | } else { |
| | | return longs.get(0); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºStringæ°ç»<br> |
| | | * |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static String[] toStrArray(String str) { |
| | | return toStrArray(",", str); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºStringæ°ç»<br> |
| | | * |
| | | * @param split åé符 |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static String[] toStrArray(String split, String str) { |
| | | if (isBlank(str)) { |
| | | return new String[]{}; |
| | | } |
| | | return str.split(split); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºStringéå<br> |
| | | * |
| | | * @param str ç»æè¢«è½¬æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static List<String> toStrList(String str) { |
| | | return Arrays.asList(toStrArray(str)); |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºStringéå<br> |
| | | * |
| | | * @param split åé符 |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static List<String> toStrList(String split, String str) { |
| | | return Arrays.asList(toStrArray(split, str)); |
| | | } |
| | | |
| | | /** |
| | | * è·å第ä¸ä½Stringæ°å¼ |
| | | * |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static String firstStr(String str) { |
| | | return firstStr(",", str); |
| | | } |
| | | |
| | | /** |
| | | * è·å第ä¸ä½Stringæ°å¼ |
| | | * |
| | | * @param split åé符 |
| | | * @param str 被转æ¢çå¼ |
| | | * @return ç»æ |
| | | */ |
| | | public static String firstStr(String split, String str) { |
| | | List<String> strs = toStrList(split, str); |
| | | if (isEmpty(strs)) { |
| | | return null; |
| | | } else { |
| | | return strs.get(0); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å° long 转çå符串 为 62 è¿å¶ |
| | | * |
| | | * @param num æ°å |
| | | * @return çå符串 |
| | | */ |
| | | public static String to62String(long num) { |
| | | return NumberUtil.to62String(num); |
| | | } |
| | | |
| | | /** |
| | | * å°éåæ¼æ¥æå符串ï¼é»è®¤ä½¿ç¨`,`æ¼æ¥ |
| | | * |
| | | * @param coll the {@code Collection} to convert |
| | | * @return the delimited {@code String} |
| | | */ |
| | | public static String join(Collection<?> coll) { |
| | | return StringUtil.join(coll); |
| | | } |
| | | |
| | | /** |
| | | * å°éåæ¼æ¥æå符串ï¼é»è®¤æå®åé符 |
| | | * |
| | | * @param coll the {@code Collection} to convert |
| | | * @param delim the delimiter to use (typically a ",") |
| | | * @return the delimited {@code String} |
| | | */ |
| | | public static String join(Collection<?> coll, String delim) { |
| | | return StringUtil.join(coll, delim); |
| | | } |
| | | |
| | | /** |
| | | * å°æ°ç»æ¼æ¥æå符串ï¼é»è®¤ä½¿ç¨`,`æ¼æ¥ |
| | | * |
| | | * @param arr the array to display |
| | | * @return the delimited {@code String} |
| | | */ |
| | | public static String join(Object[] arr) { |
| | | return StringUtil.join(arr); |
| | | } |
| | | |
| | | /** |
| | | * å°æ°ç»æ¼æ¥æå符串ï¼é»è®¤æå®åé符 |
| | | * |
| | | * @param arr the array to display |
| | | * @param delim the delimiter to use (typically a ",") |
| | | * @return the delimited {@code String} |
| | | */ |
| | | public static String join(Object[] arr, String delim) { |
| | | return StringUtil.join(arr, delim); |
| | | } |
| | | |
| | | /** |
| | | * ååå符串ï¼ä¸å»é¤åååæ¯ä¸ªå
ç´ ä¸¤è¾¹ç空ç½ç¬¦ï¼ä¸å»é¤ç©ºç½é¡¹ |
| | | * |
| | | * @param str 被ååçå符串 |
| | | * @param separator åé符å符 |
| | | * @return åååçéå |
| | | */ |
| | | public static List<String> split(CharSequence str, char separator) { |
| | | return StringUtil.split(str, separator, -1); |
| | | } |
| | | |
| | | /** |
| | | * ååå符串ï¼å»é¤åååæ¯ä¸ªå
ç´ ä¸¤è¾¹ç空ç½ç¬¦ï¼å»é¤ç©ºç½é¡¹ |
| | | * |
| | | * @param str 被ååçå符串 |
| | | * @param separator åé符å符 |
| | | * @return åååçéå |
| | | */ |
| | | public static List<String> splitTrim(CharSequence str, char separator) { |
| | | return StringUtil.splitTrim(str, separator); |
| | | } |
| | | |
| | | /** |
| | | * ååå符串ï¼å»é¤åååæ¯ä¸ªå
ç´ ä¸¤è¾¹ç空ç½ç¬¦ï¼å»é¤ç©ºç½é¡¹ |
| | | * |
| | | * @param str 被ååçå符串 |
| | | * @param separator åé符å符 |
| | | * @return åååçéå |
| | | */ |
| | | public static List<String> splitTrim(CharSequence str, CharSequence separator) { |
| | | return StringUtil.splitTrim(str, separator); |
| | | } |
| | | |
| | | /** |
| | | * åå² å符串 |
| | | * |
| | | * @param str å符串 |
| | | * @param delimiter åå²ç¬¦ |
| | | * @return å符串æ°ç» |
| | | */ |
| | | public static String[] split(@Nullable String str, @Nullable String delimiter) { |
| | | return StringUtil.delimitedListToStringArray(str, delimiter); |
| | | } |
| | | |
| | | /** |
| | | * åå² å符串 å é¤å¸¸è§ 空ç½ç¬¦ |
| | | * |
| | | * @param str å符串 |
| | | * @param delimiter åå²ç¬¦ |
| | | * @return å符串æ°ç» |
| | | */ |
| | | public static String[] splitTrim(@Nullable String str, @Nullable String delimiter) { |
| | | return StringUtil.delimitedListToStringArray(str, delimiter, " \t\n\n\f"); |
| | | } |
| | | |
| | | /** |
| | | * å符串æ¯å¦ç¬¦åæå®ç è¡¨è¾¾å¼ |
| | | * |
| | | * <p> |
| | | * pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy" |
| | | * </p> |
| | | * |
| | | * @param pattern è¡¨è¾¾å¼ |
| | | * @param str å符串 |
| | | * @return æ¯å¦å¹é
|
| | | */ |
| | | public static boolean simpleMatch(@Nullable String pattern, @Nullable String str) { |
| | | return PatternMatchUtils.simpleMatch(pattern, str); |
| | | } |
| | | |
| | | /** |
| | | * å符串æ¯å¦ç¬¦åæå®ç è¡¨è¾¾å¼ |
| | | * |
| | | * <p> |
| | | * pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy" |
| | | * </p> |
| | | * |
| | | * @param patterns è¡¨è¾¾å¼ æ°ç» |
| | | * @param str å符串 |
| | | * @return æ¯å¦å¹é
|
| | | */ |
| | | public static boolean simpleMatch(@Nullable String[] patterns, String str) { |
| | | return PatternMatchUtils.simpleMatch(patterns, str); |
| | | } |
| | | |
| | | /** |
| | | * çæuuid |
| | | * |
| | | * @return UUID |
| | | */ |
| | | public static String randomUUID() { |
| | | return StringUtil.randomUUID(); |
| | | } |
| | | |
| | | /** |
| | | * 转ä¹HTMLç¨äºå®å
¨è¿æ»¤ |
| | | * |
| | | * @param html html |
| | | * @return {String} |
| | | */ |
| | | public static String escapeHtml(String html) { |
| | | return StringUtil.escapeHtml(html); |
| | | } |
| | | |
| | | /** |
| | | * éæºæ°çæ |
| | | * |
| | | * @param count å符é¿åº¦ |
| | | * @return éæºæ° |
| | | */ |
| | | public static String random(int count) { |
| | | return StringUtil.random(count); |
| | | } |
| | | |
| | | /** |
| | | * éæºæ°çæ |
| | | * |
| | | * @param count å符é¿åº¦ |
| | | * @param randomType éæºæ°ç±»å« |
| | | * @return éæºæ° |
| | | */ |
| | | public static String random(int count, RandomType randomType) { |
| | | return StringUtil.random(count, randomType); |
| | | } |
| | | |
| | | /** |
| | | * å符串åºååæ md5 |
| | | * |
| | | * @param data Data to digest |
| | | * @return MD5 digest as a hex string |
| | | */ |
| | | public static String md5Hex(final String data) { |
| | | return DigestUtil.md5Hex(data); |
| | | } |
| | | |
| | | /** |
| | | * æ°ç»åºååæ md5 |
| | | * |
| | | * @param bytes the bytes to calculate the digest over |
| | | * @return md5 digest string |
| | | */ |
| | | public static String md5Hex(final byte[] bytes) { |
| | | return DigestUtil.md5Hex(bytes); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * sha1Hex |
| | | * |
| | | * @param data Data to digest |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String sha1Hex(String data) { |
| | | return DigestUtil.sha1Hex(data); |
| | | } |
| | | |
| | | /** |
| | | * sha1Hex |
| | | * |
| | | * @param bytes Data to digest |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String sha1Hex(final byte[] bytes) { |
| | | return DigestUtil.sha1Hex(bytes); |
| | | } |
| | | |
| | | /** |
| | | * SHA224Hex |
| | | * |
| | | * @param data Data to digest |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String sha224Hex(String data) { |
| | | return DigestUtil.sha224Hex(data); |
| | | } |
| | | |
| | | /** |
| | | * SHA224Hex |
| | | * |
| | | * @param bytes Data to digest |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String sha224Hex(final byte[] bytes) { |
| | | return DigestUtil.sha224Hex(bytes); |
| | | } |
| | | |
| | | /** |
| | | * sha256Hex |
| | | * |
| | | * @param data Data to digest |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String sha256Hex(String data) { |
| | | return DigestUtil.sha256Hex(data); |
| | | } |
| | | |
| | | /** |
| | | * sha256Hex |
| | | * |
| | | * @param bytes Data to digest |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String sha256Hex(final byte[] bytes) { |
| | | return DigestUtil.sha256Hex(bytes); |
| | | } |
| | | |
| | | /** |
| | | * sha384Hex |
| | | * |
| | | * @param data Data to digest |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String sha384Hex(String data) { |
| | | return DigestUtil.sha384Hex(data); |
| | | } |
| | | |
| | | /** |
| | | * sha384Hex |
| | | * |
| | | * @param bytes Data to digest |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String sha384Hex(final byte[] bytes) { |
| | | return DigestUtil.sha384Hex(bytes); |
| | | } |
| | | |
| | | /** |
| | | * sha512Hex |
| | | * |
| | | * @param data Data to digest |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String sha512Hex(String data) { |
| | | return DigestUtil.sha512Hex(data); |
| | | } |
| | | |
| | | /** |
| | | * sha512Hex |
| | | * |
| | | * @param bytes Data to digest |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String sha512Hex(final byte[] bytes) { |
| | | return DigestUtil.sha512Hex(bytes); |
| | | } |
| | | |
| | | /** |
| | | * hmacMd5 Hex |
| | | * |
| | | * @param data Data to digest |
| | | * @param key key |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String hmacMd5Hex(String data, String key) { |
| | | return DigestUtil.hmacMd5Hex(data, key); |
| | | } |
| | | |
| | | /** |
| | | * hmacMd5 Hex |
| | | * |
| | | * @param bytes Data to digest |
| | | * @param key key |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String hmacMd5Hex(final byte[] bytes, String key) { |
| | | return DigestUtil.hmacMd5Hex(bytes, key); |
| | | } |
| | | |
| | | /** |
| | | * hmacSha1 Hex |
| | | * |
| | | * @param data Data to digest |
| | | * @param key key |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String hmacSha1Hex(String data, String key) { |
| | | return DigestUtil.hmacSha1Hex(data, key); |
| | | } |
| | | |
| | | /** |
| | | * hmacSha1 Hex |
| | | * |
| | | * @param bytes Data to digest |
| | | * @param key key |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String hmacSha1Hex(final byte[] bytes, String key) { |
| | | return DigestUtil.hmacSha1Hex(bytes, key); |
| | | } |
| | | |
| | | /** |
| | | * hmacSha224 Hex |
| | | * |
| | | * @param data Data to digest |
| | | * @param key key |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String hmacSha224Hex(String data, String key) { |
| | | return DigestUtil.hmacSha224Hex(data, key); |
| | | } |
| | | |
| | | /** |
| | | * hmacSha224 Hex |
| | | * |
| | | * @param bytes Data to digest |
| | | * @param key key |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String hmacSha224Hex(final byte[] bytes, String key) { |
| | | return DigestUtil.hmacSha224Hex(bytes, key); |
| | | } |
| | | |
| | | /** |
| | | * hmacSha256 Hex |
| | | * |
| | | * @param data Data to digest |
| | | * @param key key |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String hmacSha256Hex(String data, String key) { |
| | | return DigestUtil.hmacSha256Hex(data, key); |
| | | } |
| | | |
| | | /** |
| | | * hmacSha256 Hex |
| | | * |
| | | * @param bytes Data to digest |
| | | * @param key key |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String hmacSha256Hex(final byte[] bytes, String key) { |
| | | return DigestUtil.hmacSha256Hex(bytes, key); |
| | | } |
| | | |
| | | /** |
| | | * hmacSha384 Hex |
| | | * |
| | | * @param data Data to digest |
| | | * @param key key |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String hmacSha384Hex(String data, String key) { |
| | | return DigestUtil.hmacSha384Hex(data, key); |
| | | } |
| | | |
| | | /** |
| | | * hmacSha384 Hex |
| | | * |
| | | * @param bytes Data to digest |
| | | * @param key key |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String hmacSha384Hex(final byte[] bytes, String key) { |
| | | return DigestUtil.hmacSha384Hex(bytes, key); |
| | | } |
| | | |
| | | /** |
| | | * hmacSha512 Hex |
| | | * |
| | | * @param data Data to digest |
| | | * @param key key |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String hmacSha512Hex(String data, String key) { |
| | | return DigestUtil.hmacSha512Hex(data, key); |
| | | } |
| | | |
| | | /** |
| | | * hmacSha512 Hex |
| | | * |
| | | * @param bytes Data to digest |
| | | * @param key key |
| | | * @return digest as a hex string |
| | | */ |
| | | public static String hmacSha512Hex(final byte[] bytes, String key) { |
| | | return DigestUtil.hmacSha512Hex(bytes, key); |
| | | } |
| | | |
| | | /** |
| | | * byte æ°ç»åºååæ hex |
| | | * |
| | | * @param bytes bytes to encode |
| | | * @return MD5 digest as a hex string |
| | | */ |
| | | public static String encodeHex(byte[] bytes) { |
| | | return DigestUtil.encodeHex(bytes); |
| | | } |
| | | |
| | | /** |
| | | * å符串ååºååæ hex |
| | | * |
| | | * @param hexString String to decode |
| | | * @return MD5 digest as a hex string |
| | | */ |
| | | public static byte[] decodeHex(final String hexString) { |
| | | return DigestUtil.decodeHex(hexString); |
| | | } |
| | | |
| | | /** |
| | | * Base64ç¼ç |
| | | * |
| | | * @param value å符串 |
| | | * @return {String} |
| | | */ |
| | | public static String encodeBase64(String value) { |
| | | return Base64Util.encode(value); |
| | | } |
| | | |
| | | /** |
| | | * Base64ç¼ç |
| | | * |
| | | * @param value å符串 |
| | | * @param charset å符é |
| | | * @return {String} |
| | | */ |
| | | public static String encodeBase64(String value, Charset charset) { |
| | | return Base64Util.encode(value, charset); |
| | | } |
| | | |
| | | /** |
| | | * Base64ç¼ç 为URLå®å
¨ |
| | | * |
| | | * @param value å符串 |
| | | * @return {String} |
| | | */ |
| | | public static String encodeBase64UrlSafe(String value) { |
| | | return Base64Util.encodeUrlSafe(value); |
| | | } |
| | | |
| | | /** |
| | | * Base64ç¼ç 为URLå®å
¨ |
| | | * |
| | | * @param value å符串 |
| | | * @param charset å符é |
| | | * @return {String} |
| | | */ |
| | | public static String encodeBase64UrlSafe(String value, Charset charset) { |
| | | return Base64Util.encodeUrlSafe(value, charset); |
| | | } |
| | | |
| | | /** |
| | | * Base64è§£ç |
| | | * |
| | | * @param value å符串 |
| | | * @return {String} |
| | | */ |
| | | public static String decodeBase64(String value) { |
| | | return Base64Util.decode(value); |
| | | } |
| | | |
| | | /** |
| | | * Base64è§£ç |
| | | * |
| | | * @param value å符串 |
| | | * @param charset å符é |
| | | * @return {String} |
| | | */ |
| | | public static String decodeBase64(String value, Charset charset) { |
| | | return Base64Util.decode(value, charset); |
| | | } |
| | | |
| | | /** |
| | | * Base64URLå®å
¨è§£ç |
| | | * |
| | | * @param value å符串 |
| | | * @return {String} |
| | | */ |
| | | public static String decodeBase64UrlSafe(String value) { |
| | | return Base64Util.decodeUrlSafe(value); |
| | | } |
| | | |
| | | /** |
| | | * Base64URLå®å
¨è§£ç |
| | | * |
| | | * @param value å符串 |
| | | * @param charset å符é |
| | | * @return {String} |
| | | */ |
| | | public static String decodeBase64UrlSafe(String value, Charset charset) { |
| | | return Base64Util.decodeUrlSafe(value, charset); |
| | | } |
| | | |
| | | /** |
| | | * å
³é Closeable |
| | | * |
| | | * @param closeable èªå¨å
³é |
| | | */ |
| | | public static void closeQuietly(@Nullable Closeable closeable) { |
| | | IoUtil.closeQuietly(closeable); |
| | | } |
| | | |
| | | /** |
| | | * InputStream to String utf-8 |
| | | * |
| | | * @param input the <code>InputStream</code> to read from |
| | | * @return the requested String |
| | | * @throws NullPointerException if the input is null |
| | | */ |
| | | public static String readToString(InputStream input) { |
| | | return IoUtil.readToString(input); |
| | | } |
| | | |
| | | /** |
| | | * InputStream to String |
| | | * |
| | | * @param input the <code>InputStream</code> to read from |
| | | * @param charset the <code>Charset</code> |
| | | * @return the requested String |
| | | * @throws NullPointerException if the input is null |
| | | */ |
| | | public static String readToString(@Nullable InputStream input, Charset charset) { |
| | | return IoUtil.readToString(input, charset); |
| | | } |
| | | |
| | | /** |
| | | * InputStream to bytes æ°ç» |
| | | * |
| | | * @param input InputStream |
| | | * @return the requested byte array |
| | | */ |
| | | public static byte[] readToByteArray(@Nullable InputStream input) { |
| | | return IoUtil.readToByteArray(input); |
| | | } |
| | | |
| | | /** |
| | | * 读åæä»¶ä¸ºå符串 |
| | | * |
| | | * @param file the file to read, must not be {@code null} |
| | | * @return the file contents, never {@code null} |
| | | */ |
| | | public static String readToString(final File file) { |
| | | return FileUtil.readToString(file); |
| | | } |
| | | |
| | | /** |
| | | * 读åæä»¶ä¸ºå符串 |
| | | * |
| | | * @param file the file to read, must not be {@code null} |
| | | * @param encoding the encoding to use, {@code null} means platform default |
| | | * @return the file contents, never {@code null} |
| | | */ |
| | | public static String readToString(File file, Charset encoding) { |
| | | return FileUtil.readToString(file, encoding); |
| | | } |
| | | |
| | | /** |
| | | * 读åæä»¶ä¸º byte æ°ç» |
| | | * |
| | | * @param file the file to read, must not be {@code null} |
| | | * @return the file contents, never {@code null} |
| | | */ |
| | | public static byte[] readToByteArray(File file) { |
| | | return FileUtil.readToByteArray(file); |
| | | } |
| | | |
| | | /** |
| | | * å°å¯¹è±¡åºååæjsonå符串 |
| | | * |
| | | * @param object javaBean |
| | | * @return jsonString jsonå符串 |
| | | */ |
| | | public static String toJson(Object object) { |
| | | return JsonUtil.toJson(object); |
| | | } |
| | | |
| | | /** |
| | | * å°å¯¹è±¡åºååæ json byte æ°ç» |
| | | * |
| | | * @param object javaBean |
| | | * @return jsonString jsonå符串 |
| | | */ |
| | | public static byte[] toJsonAsBytes(Object object) { |
| | | return JsonUtil.toJsonAsBytes(object); |
| | | } |
| | | |
| | | /** |
| | | * å°jsonå符串转æ JsonNode |
| | | * |
| | | * @param jsonString jsonString |
| | | * @return jsonString jsonå符串 |
| | | */ |
| | | public static JsonNode readTree(String jsonString) { |
| | | return JsonUtil.readTree(jsonString); |
| | | } |
| | | |
| | | /** |
| | | * å°jsonå符串转æ JsonNode |
| | | * |
| | | * @param in InputStream |
| | | * @return jsonString jsonå符串 |
| | | */ |
| | | public static JsonNode readTree(InputStream in) { |
| | | return JsonUtil.readTree(in); |
| | | } |
| | | |
| | | /** |
| | | * å°jsonå符串转æ JsonNode |
| | | * |
| | | * @param content content |
| | | * @return jsonString jsonå符串 |
| | | */ |
| | | public static JsonNode readTree(byte[] content) { |
| | | return JsonUtil.readTree(content); |
| | | } |
| | | |
| | | /** |
| | | * å°jsonå符串转æ JsonNode |
| | | * |
| | | * @param jsonParser JsonParser |
| | | * @return jsonString jsonå符串 |
| | | */ |
| | | public static JsonNode readTree(JsonParser jsonParser) { |
| | | return JsonUtil.readTree(jsonParser); |
| | | } |
| | | |
| | | /** |
| | | * å°json byte æ°ç»ååºååæå¯¹è±¡ |
| | | * |
| | | * @param bytes json bytes |
| | | * @param valueType class |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | public static <T> T readJson(byte[] bytes, Class<T> valueType) { |
| | | return JsonUtil.parse(bytes, valueType); |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param jsonString jsonString |
| | | * @param valueType class |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | public static <T> T readJson(String jsonString, Class<T> valueType) { |
| | | return JsonUtil.parse(jsonString, valueType); |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param in InputStream |
| | | * @param valueType class |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | public static <T> T readJson(InputStream in, Class<T> valueType) { |
| | | return JsonUtil.parse(in, valueType); |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param bytes bytes |
| | | * @param typeReference æ³åç±»å |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | public static <T> T readJson(byte[] bytes, TypeReference<T> typeReference) { |
| | | return JsonUtil.parse(bytes, typeReference); |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param jsonString jsonString |
| | | * @param typeReference æ³åç±»å |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | public static <T> T readJson(String jsonString, TypeReference<T> typeReference) { |
| | | return JsonUtil.parse(jsonString, typeReference); |
| | | } |
| | | |
| | | /** |
| | | * å°jsonååºååæå¯¹è±¡ |
| | | * |
| | | * @param in InputStream |
| | | * @param typeReference æ³åç±»å |
| | | * @param <T> T æ³åæ è®° |
| | | * @return Bean |
| | | */ |
| | | public static <T> T readJson(InputStream in, TypeReference<T> typeReference) { |
| | | return JsonUtil.parse(in, typeReference); |
| | | } |
| | | |
| | | /** |
| | | * url ç¼ç |
| | | * |
| | | * @param source the String to be encoded |
| | | * @return the encoded String |
| | | */ |
| | | public static String urlEncode(String source) { |
| | | return UrlUtil.encode(source, Charsets.UTF_8); |
| | | } |
| | | |
| | | /** |
| | | * url ç¼ç |
| | | * |
| | | * @param source the String to be encoded |
| | | * @param charset the character encoding to encode to |
| | | * @return the encoded String |
| | | */ |
| | | public static String urlEncode(String source, Charset charset) { |
| | | return UrlUtil.encode(source, charset); |
| | | } |
| | | |
| | | /** |
| | | * url è§£ç |
| | | * |
| | | * @param source the encoded String |
| | | * @return the decoded value |
| | | * @throws IllegalArgumentException when the given source contains invalid encoded sequences |
| | | * @see StringUtils#uriDecode(String, Charset) |
| | | * @see java.net.URLDecoder#decode(String, String) |
| | | */ |
| | | public static String urlDecode(String source) { |
| | | return StringUtils.uriDecode(source, Charsets.UTF_8); |
| | | } |
| | | |
| | | /** |
| | | * url è§£ç |
| | | * |
| | | * @param source the encoded String |
| | | * @param charset the character encoding to use |
| | | * @return the decoded value |
| | | * @throws IllegalArgumentException when the given source contains invalid encoded sequences |
| | | * @see StringUtils#uriDecode(String, Charset) |
| | | * @see java.net.URLDecoder#decode(String, String) |
| | | */ |
| | | public static String urlDecode(String source, Charset charset) { |
| | | return StringUtils.uriDecode(source, charset); |
| | | } |
| | | |
| | | /** |
| | | * æ¥ææ¶é´æ ¼å¼å |
| | | * |
| | | * @param date æ¶é´ |
| | | * @return æ ¼å¼ååçæ¶é´ |
| | | */ |
| | | public static String formatDateTime(Date date) { |
| | | return DateUtil.formatDateTime(date); |
| | | } |
| | | |
| | | /** |
| | | * æ¥ææ ¼å¼å |
| | | * |
| | | * @param date æ¶é´ |
| | | * @return æ ¼å¼ååçæ¶é´ |
| | | */ |
| | | public static String formatDate(Date date) { |
| | | return DateUtil.formatDate(date); |
| | | } |
| | | |
| | | /** |
| | | * æ¶é´æ ¼å¼å |
| | | * |
| | | * @param date æ¶é´ |
| | | * @return æ ¼å¼ååçæ¶é´ |
| | | */ |
| | | public static String formatTime(Date date) { |
| | | return DateUtil.formatTime(date); |
| | | } |
| | | |
| | | /** |
| | | * å¯¹è±¡æ ¼å¼å æ¯ææ°åï¼dateï¼java8æ¶é´ |
| | | * |
| | | * @param object æ ¼å¼å对象 |
| | | * @param pattern è¡¨è¾¾å¼ |
| | | * @return æ ¼å¼ååçå符串 |
| | | */ |
| | | public static String format(Object object, String pattern) { |
| | | if (object instanceof Number) { |
| | | DecimalFormat decimalFormat = new DecimalFormat(pattern); |
| | | return decimalFormat.format(object); |
| | | } else if (object instanceof Date) { |
| | | return DateUtil.format((Date) object, pattern); |
| | | } else if (object instanceof TemporalAccessor) { |
| | | return DateTimeUtil.format((TemporalAccessor) object, pattern); |
| | | } |
| | | throw new IllegalArgumentException("æªæ¯æç对象:" + object + ",æ ¼å¼:" + object); |
| | | } |
| | | |
| | | /** |
| | | * å°å符串转æ¢ä¸ºæ¶é´ |
| | | * |
| | | * @param dateStr æ¶é´å符串 |
| | | * @param pattern è¡¨è¾¾å¼ |
| | | * @return æ¶é´ |
| | | */ |
| | | public static Date parseDate(String dateStr, String pattern) { |
| | | return DateUtil.parse(dateStr, pattern); |
| | | } |
| | | |
| | | /** |
| | | * å°å符串转æ¢ä¸ºæ¶é´ |
| | | * |
| | | * @param dateStr æ¶é´å符串 |
| | | * @param format ConcurrentDateFormat |
| | | * @return æ¶é´ |
| | | */ |
| | | public static Date parse(String dateStr, ConcurrentDateFormat format) { |
| | | return DateUtil.parse(dateStr, format); |
| | | } |
| | | |
| | | /** |
| | | * æ¥ææ¶é´æ ¼å¼å |
| | | * |
| | | * @param temporal æ¶é´ |
| | | * @return æ ¼å¼ååçæ¶é´ |
| | | */ |
| | | public static String formatDateTime(TemporalAccessor temporal) { |
| | | return DateTimeUtil.formatDateTime(temporal); |
| | | } |
| | | |
| | | /** |
| | | * æ¥ææ¶é´æ ¼å¼å |
| | | * |
| | | * @param temporal æ¶é´ |
| | | * @return æ ¼å¼ååçæ¶é´ |
| | | */ |
| | | public static String formatDate(TemporalAccessor temporal) { |
| | | return DateTimeUtil.formatDate(temporal); |
| | | } |
| | | |
| | | /** |
| | | * æ¶é´æ ¼å¼å |
| | | * |
| | | * @param temporal æ¶é´ |
| | | * @return æ ¼å¼ååçæ¶é´ |
| | | */ |
| | | public static String formatTime(TemporalAccessor temporal) { |
| | | return DateTimeUtil.formatTime(temporal); |
| | | } |
| | | |
| | | /** |
| | | * å°å符串转æ¢ä¸ºæ¶é´ |
| | | * |
| | | * @param dateStr æ¶é´å符串 |
| | | * @param formatter DateTimeFormatter |
| | | * @return æ¶é´ |
| | | */ |
| | | public static LocalDateTime parseDateTime(String dateStr, DateTimeFormatter formatter) { |
| | | return DateTimeUtil.parseDateTime(dateStr, formatter); |
| | | } |
| | | |
| | | /** |
| | | * å°å符串转æ¢ä¸ºæ¶é´ |
| | | * |
| | | * @param dateStr æ¶é´å符串 |
| | | * @return æ¶é´ |
| | | */ |
| | | public static LocalDateTime parseDateTime(String dateStr) { |
| | | return DateTimeUtil.parseDateTime(dateStr); |
| | | } |
| | | |
| | | /** |
| | | * å°å符串转æ¢ä¸ºæ¶é´ |
| | | * |
| | | * @param dateStr æ¶é´å符串 |
| | | * @param formatter DateTimeFormatter |
| | | * @return æ¶é´ |
| | | */ |
| | | public static LocalDate parseDate(String dateStr, DateTimeFormatter formatter) { |
| | | return DateTimeUtil.parseDate(dateStr, formatter); |
| | | } |
| | | |
| | | /** |
| | | * å°å符串转æ¢ä¸ºæ¥æ |
| | | * |
| | | * @param dateStr æ¶é´å符串 |
| | | * @return æ¶é´ |
| | | */ |
| | | public static LocalDate parseDate(String dateStr) { |
| | | return DateTimeUtil.parseDate(dateStr, DateTimeUtil.DATE_FORMAT); |
| | | } |
| | | |
| | | /** |
| | | * å°å符串转æ¢ä¸ºæ¶é´ |
| | | * |
| | | * @param dateStr æ¶é´å符串 |
| | | * @param formatter DateTimeFormatter |
| | | * @return æ¶é´ |
| | | */ |
| | | public static LocalTime parseTime(String dateStr, DateTimeFormatter formatter) { |
| | | return DateTimeUtil.parseTime(dateStr, formatter); |
| | | } |
| | | |
| | | /** |
| | | * å°å符串转æ¢ä¸ºæ¶é´ |
| | | * |
| | | * @param dateStr æ¶é´å符串 |
| | | * @return æ¶é´ |
| | | */ |
| | | public static LocalTime parseTime(String dateStr) { |
| | | return DateTimeUtil.parseTime(dateStr); |
| | | } |
| | | |
| | | /** |
| | | * æ¶é´æ¯è¾ |
| | | * |
| | | * @param startInclusive the start instant, inclusive, not null |
| | | * @param endExclusive the end instant, exclusive, not null |
| | | * @return a {@code Duration}, not null |
| | | */ |
| | | public static Duration between(Temporal startInclusive, Temporal endExclusive) { |
| | | return Duration.between(startInclusive, endExclusive); |
| | | } |
| | | |
| | | /** |
| | | * æ¯è¾2个 æ¶é´å·® |
| | | * |
| | | * @param startDate å¼å§æ¶é´ |
| | | * @param endDate ç»ææ¶é´ |
| | | * @return æ¶é´é´é |
| | | */ |
| | | public static Duration between(Date startDate, Date endDate) { |
| | | return DateUtil.between(startDate, endDate); |
| | | } |
| | | |
| | | /** |
| | | * 对象类åè½¬æ¢ |
| | | * |
| | | * @param source the source object |
| | | * @param targetType the target type |
| | | * @param <T> æ³åæ è®° |
| | | * @return the converted value |
| | | * @throws IllegalArgumentException if targetType is {@code null}, |
| | | * or sourceType is {@code null} but source is not {@code null} |
| | | */ |
| | | @Nullable |
| | | public static <T> T convert(@Nullable Object source, Class<T> targetType) { |
| | | return ConvertUtil.convert(source, targetType); |
| | | } |
| | | |
| | | /** |
| | | * 对象类åè½¬æ¢ |
| | | * |
| | | * @param source the source object |
| | | * @param sourceType the source type |
| | | * @param targetType the target type |
| | | * @param <T> æ³åæ è®° |
| | | * @return the converted value |
| | | * @throws IllegalArgumentException if targetType is {@code null}, |
| | | * or sourceType is {@code null} but source is not {@code null} |
| | | */ |
| | | @Nullable |
| | | public static <T> T convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { |
| | | return ConvertUtil.convert(source, sourceType, targetType); |
| | | } |
| | | |
| | | /** |
| | | * 对象类åè½¬æ¢ |
| | | * |
| | | * @param source the source object |
| | | * @param targetType the target type |
| | | * @param <T> æ³åæ è®° |
| | | * @return the converted value |
| | | * @throws IllegalArgumentException if targetType is {@code null}, |
| | | * or sourceType is {@code null} but source is not {@code null} |
| | | */ |
| | | @Nullable |
| | | public static <T> T convert(@Nullable Object source, TypeDescriptor targetType) { |
| | | return ConvertUtil.convert(source, targetType); |
| | | } |
| | | |
| | | /** |
| | | * è·åæ¹æ³åæ°ä¿¡æ¯ |
| | | * |
| | | * @param constructor æé å¨ |
| | | * @param parameterIndex åæ°åºå· |
| | | * @return {MethodParameter} |
| | | */ |
| | | public static MethodParameter getMethodParameter(Constructor<?> constructor, int parameterIndex) { |
| | | return ClassUtil.getMethodParameter(constructor, parameterIndex); |
| | | } |
| | | |
| | | /** |
| | | * è·åæ¹æ³åæ°ä¿¡æ¯ |
| | | * |
| | | * @param method æ¹æ³ |
| | | * @param parameterIndex åæ°åºå· |
| | | * @return {MethodParameter} |
| | | */ |
| | | public static MethodParameter getMethodParameter(Method method, int parameterIndex) { |
| | | return ClassUtil.getMethodParameter(method, parameterIndex); |
| | | } |
| | | |
| | | /** |
| | | * è·åAnnotation注解 |
| | | * |
| | | * @param annotatedElement AnnotatedElement |
| | | * @param annotationType 注解类 |
| | | * @param <A> æ³åæ è®° |
| | | * @return {Annotation} |
| | | */ |
| | | @Nullable |
| | | public static <A extends Annotation> A getAnnotation(AnnotatedElement annotatedElement, Class<A> annotationType) { |
| | | return AnnotatedElementUtils.findMergedAnnotation(annotatedElement, annotationType); |
| | | } |
| | | |
| | | /** |
| | | * è·åAnnotationï¼å
æ¾æ¹æ³ï¼æ²¡æååæ¾æ¹æ³ä¸çç±» |
| | | * |
| | | * @param method Method |
| | | * @param annotationType 注解类 |
| | | * @param <A> æ³åæ è®° |
| | | * @return {Annotation} |
| | | */ |
| | | @Nullable |
| | | public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationType) { |
| | | return ClassUtil.getAnnotation(method, annotationType); |
| | | } |
| | | |
| | | /** |
| | | * è·åAnnotationï¼å
æ¾HandlerMethodï¼æ²¡æå忾坹åºçç±» |
| | | * |
| | | * @param handlerMethod HandlerMethod |
| | | * @param annotationType 注解类 |
| | | * @param <A> æ³åæ è®° |
| | | * @return {Annotation} |
| | | */ |
| | | @Nullable |
| | | public static <A extends Annotation> A getAnnotation(HandlerMethod handlerMethod, Class<A> annotationType) { |
| | | return ClassUtil.getAnnotation(handlerMethod, annotationType); |
| | | } |
| | | |
| | | /** |
| | | * å®ä¾å对象 |
| | | * |
| | | * @param clazz ç±» |
| | | * @param <T> æ³åæ è®° |
| | | * @return 对象 |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <T> T newInstance(Class<?> clazz) { |
| | | return (T) BeanUtil.instantiateClass(clazz); |
| | | } |
| | | |
| | | /** |
| | | * å®ä¾å对象 |
| | | * |
| | | * @param clazzStr ç±»å |
| | | * @param <T> æ³åæ è®° |
| | | * @return 对象 |
| | | */ |
| | | public static <T> T newInstance(String clazzStr) { |
| | | return BeanUtil.newInstance(clazzStr); |
| | | } |
| | | |
| | | /** |
| | | * è·åBeanç屿§ |
| | | * |
| | | * @param bean bean |
| | | * @param propertyName 屿§å |
| | | * @return 屿§å¼ |
| | | */ |
| | | @Nullable |
| | | public static Object getProperty(@Nullable Object bean, String propertyName) { |
| | | return BeanUtil.getProperty(bean, propertyName); |
| | | } |
| | | |
| | | /** |
| | | * 设置Bean屿§ |
| | | * |
| | | * @param bean bean |
| | | * @param propertyName 屿§å |
| | | * @param value 屿§å¼ |
| | | */ |
| | | public static void setProperty(Object bean, String propertyName, Object value) { |
| | | BeanUtil.setProperty(bean, propertyName, value); |
| | | } |
| | | |
| | | /** |
| | | * æµ
å¤å¶ |
| | | * |
| | | * @param source æºå¯¹è±¡ |
| | | * @param <T> æ³åæ è®° |
| | | * @return T |
| | | */ |
| | | @Nullable |
| | | public static <T> T clone(@Nullable T source) { |
| | | return BeanUtil.clone(source); |
| | | } |
| | | |
| | | /** |
| | | * æ·è´å¯¹è±¡ï¼æ¯æ Map å Bean |
| | | * |
| | | * @param source æºå¯¹è±¡ |
| | | * @param clazz ç±»å |
| | | * @param <T> æ³åæ è®° |
| | | * @return T |
| | | */ |
| | | @Nullable |
| | | public static <T> T copy(@Nullable Object source, Class<T> clazz) { |
| | | return BeanUtil.copy(source, clazz); |
| | | } |
| | | |
| | | /** |
| | | * æ·è´å¯¹è±¡ï¼æ¯æ Map å Bean |
| | | * |
| | | * @param source æºå¯¹è±¡ |
| | | * @param targetBean éè¦èµå¼ç对象 |
| | | */ |
| | | public static void copy(@Nullable Object source, @Nullable Object targetBean) { |
| | | BeanUtil.copy(source, targetBean); |
| | | } |
| | | |
| | | /** |
| | | * æ·è´å¯¹è±¡ï¼source å¯¹è±¡å±æ§åé null 夿 |
| | | * |
| | | * <p> |
| | | * æ¯æ map bean copy |
| | | * </p> |
| | | * |
| | | * @param source æºå¯¹è±¡ |
| | | * @param targetBean éè¦èµå¼ç对象 |
| | | */ |
| | | public static void copyNonNull(@Nullable Object source, @Nullable Object targetBean) { |
| | | BeanUtil.copyNonNull(source, targetBean); |
| | | } |
| | | |
| | | /** |
| | | * æ·è´å¯¹è±¡ï¼å¹¶å¯¹ä¸åç±»å屿§è¿è¡è½¬æ¢ |
| | | * |
| | | * @param source æºå¯¹è±¡ |
| | | * @param clazz ç±»å |
| | | * @param <T> æ³åæ è®° |
| | | * @return T |
| | | */ |
| | | @Nullable |
| | | public static <T> T copyWithConvert(@Nullable Object source, Class<T> clazz) { |
| | | return BeanUtil.copyWithConvert(source, clazz); |
| | | } |
| | | |
| | | /** |
| | | * æ·è´å表对象 |
| | | * |
| | | * <p> |
| | | * æ¯æ map bean copy |
| | | * </p> |
| | | * |
| | | * @param sourceList æºå表 |
| | | * @param targetClazz è½¬æ¢æçç±»å |
| | | * @param <T> æ³åæ è®° |
| | | * @return T |
| | | */ |
| | | public static <T> List<T> copy(@Nullable Collection<?> sourceList, Class<T> targetClazz) { |
| | | return BeanUtil.copy(sourceList, targetClazz); |
| | | } |
| | | |
| | | /** |
| | | * æ·è´å表对象ï¼å¹¶å¯¹ä¸åç±»å屿§è¿è¡è½¬æ¢ |
| | | * |
| | | * <p> |
| | | * æ¯æ map bean copy |
| | | * </p> |
| | | * |
| | | * @param sourceList æºå¯¹è±¡å表 |
| | | * @param targetClazz è½¬æ¢æçç±» |
| | | * @param <T> æ³åæ è®° |
| | | * @return List |
| | | */ |
| | | public static <T> List<T> copyWithConvert(@Nullable Collection<?> sourceList, Class<T> targetClazz) { |
| | | return BeanUtil.copyWithConvert(sourceList, targetClazz); |
| | | } |
| | | |
| | | /** |
| | | * æ·è´å¯¹è±¡ï¼æ©å± Spring çæ·è´æ¹æ³ |
| | | * |
| | | * @param source the source bean |
| | | * @param clazz the target bean class |
| | | * @param <T> æ³åæ è®° |
| | | * @return T |
| | | * @throws BeansException if the copying failed |
| | | */ |
| | | @Nullable |
| | | public static <T> T copyProperties(@Nullable Object source, Class<T> clazz) throws BeansException { |
| | | return BeanUtil.copyProperties(source, clazz); |
| | | } |
| | | |
| | | /** |
| | | * æ·è´åè¡¨å¯¹è±¡ï¼æ©å± Spring çæ·è´æ¹æ³ |
| | | * |
| | | * @param sourceList the source list bean |
| | | * @param targetClazz the target bean class |
| | | * @param <T> æ³åæ è®° |
| | | * @return List |
| | | * @throws BeansException if the copying failed |
| | | */ |
| | | public static <T> List<T> copyProperties(@Nullable Collection<?> sourceList, Class<T> targetClazz) throws BeansException { |
| | | return BeanUtil.copyProperties(sourceList, targetClazz); |
| | | } |
| | | |
| | | /** |
| | | * å°å¯¹è±¡è£
æmapå½¢å¼ |
| | | * |
| | | * @param bean æºå¯¹è±¡ |
| | | * @return {Map} |
| | | */ |
| | | public static Map<String, Object> toMap(@Nullable Object bean) { |
| | | return BeanUtil.toMap(bean); |
| | | } |
| | | |
| | | /** |
| | | * å°map 转为 bean |
| | | * |
| | | * @param beanMap map |
| | | * @param valueType 对象类å |
| | | * @param <T> æ³åæ è®° |
| | | * @return {T} |
| | | */ |
| | | public static <T> T toBean(Map<String, Object> beanMap, Class<T> valueType) { |
| | | return BeanUtil.toBean(beanMap, valueType); |
| | | } |
| | | |
| | | } |