# 工具包集合,工具类快捷方式 **类名:** `Func` ## requireNotNull ```java /** * 断言,必须不能为 null *
* * @param obj the object reference to check for nullity * @param* public Foo(Bar bar) { * this.bar = $.requireNotNull(bar); * } *
* * @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* public Foo(Bar bar, Baz baz) { * this.bar = $.requireNotNull(bar, "bar must not be null"); * this.baz = $.requireNotNull(baz, "baz must not be null"); * } *
* * @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* public Foo(Bar bar, Baz baz) { * this.bar = $.requireNotNull(bar, () -> "bar must not be null"); * } *
* This method exists to be used as a * {@link java.util.function.Predicate}, {@code filter($::isNull)} *
* * @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 */ Func.isNull(Object obj); ``` ## notNull ```java /** * 判断对象是否 not null ** This method exists to be used as a * {@link java.util.function.Predicate}, {@code filter($::notNull)} *
* * @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 */ Func.notNull(Object obj); ``` ## firstCharToLower ```java /** * 首字母变小写 * * @param str 字符串 * @return {String} */ Func.firstCharToLower(String str); ``` ## firstCharToUpper ```java /** * 首字母变大写 * * @param str 字符串 * @return {String} */ Func.firstCharToUpper(String str); ``` ## isBlank ```java /** * 判断是否为空字符串 ** $.isBlank(null) = true * $.isBlank("") = true * $.isBlank(" ") = true * $.isBlank("12345") = false * $.isBlank(" 12345 ") = false ** * @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 */ Func.isBlank(CharSequence cs); ``` ## isNotBlank ```java /** * 判断不为空字符串 *
* $.isNotBlank(null) = false * $.isNotBlank("") = false * $.isNotBlank(" ") = false * $.isNotBlank("bob") = true * $.isNotBlank(" bob ") = true ** * @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 */ Func.isNotBlank(CharSequence cs); ``` ## isAnyBlank ```java /** * 判断是否有任意一个 空字符串 * * @param css CharSequence * @return boolean */ Func.isAnyBlank(CharSequence css); ``` ## isNoneBlank ```java /** * 判断是否全为非空字符串 * * @param css CharSequence * @return boolean */ Func.isNoneBlank(CharSequence css); ``` ## isArray ```java /** * 判断对象是数组 * * @param obj the object to check * @return 是否数组 */ Func.isArray(Object obj); ``` ## isEmpty ```java /** * 判断空对象 object、map、list、set、字符串、数组 * * @param obj the object to check * @return 数组是否为空 */ Func.isEmpty(Object obj); ``` ## isNotEmpty ```java /** * 对象不为空 object、map、list、set、字符串、数组 * * @param obj the object to check * @return 是否不为空 */ Func.isNotEmpty(Object obj); ``` ## isEmpty ```java /** * 判断数组为空 * * @param array the array to check * @return 数组是否为空 */ Func.isEmpty(Object[] array); ``` ## isNotEmpty ```java /** * 判断数组不为空 * * @param array 数组 * @return 数组是否不为空 */ Func.isNotEmpty(Object[] array); ``` ## hasEmpty ```java /** * 对象组中是否存在 Empty Object * * @param os 对象组 * @return boolean */ Func.hasEmpty(Object os); ``` ## isAllEmpty ```java /** * 对象组中是否全部为 Empty Object * * @param os 对象组 * @return boolean */ Func.isAllEmpty(Object os); ``` ## format ```java /** * 将字符串中特定模式的字符转换成map中对应的值 *
* use: format("my name is ${name}, and i like ${like}!", {"name":"L.cm", "like": "Java"})
*
* @param message 需要转换的字符串
* @param params 转换所需的键值对集合
* @return 转换后的字符串
*/
Func.format(String message, Map
* use: format("my name is {}, and i like {}!", "L.cm", "Java")
*
* @param message 需要转换的字符串
* @param arguments 需要替换的变量
* @return 转换后的字符串
*/
Func.format(String message, Object arguments);
```
## equals
```java
/**
* 比较两个对象是否相等。
* 相同的条件有两个,满足其一即可:
*
* @param obj1 对象1
* @param obj2 对象2
* @return 是否相等
*/
Func.equals(Object obj1, Object obj2);
```
## equalsSafe
```java
/**
* 安全的 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
*/
Func.equalsSafe(Object o1, Object o2);
```
## contains
```java
/**
* 判断数组中是否包含元素
*
* @param array the Array to check
* @param element the element to look for
* @param Convert a If the string is Convert a If the string is Convert a If the string is Convert a If the string is Convert a If the string is Convert a If the string is
* pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy"
*
* pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy"
*
* 支持 map bean copy
*
* 支持 map bean copy
*
* 支持 map bean copy
*
* $.toInt(null) = 0
* $.toInt("") = 0
* $.toInt("1") = 1
*
*
* @param str the string to convert, may be null
* @return the int represented by the string, or zero
if
* conversion fails
*/
Func.toInt(Object str);
```
## toInt
```java
/**
* 字符串转 int,为空则返回默认值
*
*
* $.toInt(null, 1) = 1
* $.toInt("", 1) = 1
* $.toInt("1", 0) = 1
*
*
* @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
*/
Func.toInt(Object str, int defaultValue);
```
## toLong
```java
/**
* 字符串转 long,为空则返回0
*
*
* $.toLong(null) = 0L
* $.toLong("") = 0L
* $.toLong("1") = 1L
*
*
* @param str the string to convert, may be null
* @return the long represented by the string, or 0
if
* conversion fails
*/
Func.toLong(Object str);
```
## toLong
```java
/**
* 字符串转 long,为空则返回默认值
*
*
* $.toLong(null, 1L) = 1L
* $.toLong("", 1L) = 1L
* $.toLong("1", 0L) = 1L
*
*
* @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
*/
Func.toLong(Object str, long defaultValue);
```
## toDouble
```java
/**
* String
to an Double
, returning a
* default value if the conversion fails.null
, the default value is returned.
* $.toDouble(null, 1) = 1.0
* $.toDouble("", 1) = 1.0
* $.toDouble("1", 0) = 1.0
*
*
* @param value the string to convert, may be null
* @return the int represented by the string, or the default if conversion fails
*/
Func.toDouble(Object value);
```
## toDouble
```java
/**
* String
to an Double
, returning a
* default value if the conversion fails.null
, the default value is returned.
* $.toDouble(null, 1) = 1.0
* $.toDouble("", 1) = 1.0
* $.toDouble("1", 0) = 1.0
*
*
* @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
*/
Func.toDouble(Object value, Double defaultValue);
```
## toFloat
```java
/**
* String
to an Float
, returning a
* default value if the conversion fails.null
, the default value is returned.
* $.toFloat(null, 1) = 1.00f
* $.toFloat("", 1) = 1.00f
* $.toFloat("1", 0) = 1.00f
*
*
* @param value the string to convert, may be null
* @return the int represented by the string, or the default if conversion fails
*/
Func.toFloat(Object value);
```
## toFloat
```java
/**
* String
to an Float
, returning a
* default value if the conversion fails.null
, the default value is returned.
* $.toFloat(null, 1) = 1.00f
* $.toFloat("", 1) = 1.00f
* $.toFloat("1", 0) = 1.00f
*
*
* @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
*/
Func.toFloat(Object value, Float defaultValue);
```
## toBoolean
```java
/**
* String
to an Boolean
, returning a
* default value if the conversion fails.null
, the default value is returned.
* $.toBoolean("true", true) = true
* $.toBoolean("false") = false
* $.toBoolean("", false) = false
*
*
* @param value the string to convert, may be null
* @return the int represented by the string, or the default if conversion fails
*/
Func.toBoolean(Object value);
```
## toBoolean
```java
/**
* String
to an Boolean
, returning a
* default value if the conversion fails.null
, the default value is returned.
* $.toBoolean("true", true) = true
* $.toBoolean("false") = false
* $.toBoolean("", false) = false
*
*
* @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
*/
Func.toBoolean(Object value, Boolean defaultValue);
```
## toIntArray
```java
/**
* 转换为Integer数组
*
* @param str 被转换的值
* @return 结果
*/
Func.toIntArray(String str);
```
## toIntArray
```java
/**
* 转换为Integer数组
*
* @param split 分隔符
* @param str 被转换的值
* @return 结果
*/
Func.toIntArray(String split, String str);
```
## toIntList
```java
/**
* 转换为Integer集合
*
* @param str 结果被转换的值
* @return 结果
*/
Func.toIntList(String str);
```
## toIntList
```java
/**
* 转换为Integer集合
*
* @param split 分隔符
* @param str 被转换的值
* @return 结果
*/
Func.toIntList(String split, String str);
```
## firstInt
```java
/**
* 获取第一位Integer数值
*
* @param str 被转换的值
* @return 结果
*/
Func.firstInt(String str);
```
## firstInt
```java
/**
* 获取第一位Integer数值
*
* @param split 分隔符
* @param str 被转换的值
* @return 结果
*/
Func.firstInt(String split, String str);
```
## toLongArray
```java
/**
* 转换为Long数组
*
* @param str 被转换的值
* @return 结果
*/
Func.toLongArray(String str);
```
## toLongArray
```java
/**
* 转换为Long数组
*
* @param split 分隔符
* @param str 被转换的值
* @return 结果
*/
Func.toLongArray(String split, String str);
```
## toLongList
```java
/**
* 转换为Long集合
*
* @param str 结果被转换的值
* @return 结果
*/
Func.toLongList(String str);
```
## toLongList
```java
/**
* 转换为Long集合
*
* @param split 分隔符
* @param str 被转换的值
* @return 结果
*/
Func.toLongList(String split, String str);
```
## firstLong
```java
/**
* 获取第一位Long数值
*
* @param str 被转换的值
* @return 结果
*/
Func.firstLong(String str);
```
## firstLong
```java
/**
* 获取第一位Long数值
*
* @param split 分隔符
* @param str 被转换的值
* @return 结果
*/
Func.firstLong(String split, String str);
```
## toStrArray
```java
/**
* 转换为String数组
*
* @param str 被转换的值
* @return 结果
*/
Func.toStrArray(String str);
```
## toStrArray
```java
/**
* 转换为String数组
*
* @param split 分隔符
* @param str 被转换的值
* @return 结果
*/
Func.toStrArray(String split, String str);
```
## toStrList
```java
/**
* 转换为String集合
*
* @param str 结果被转换的值
* @return 结果
*/
Func.toStrList(String str);
```
## toStrList
```java
/**
* 转换为String集合
*
* @param split 分隔符
* @param str 被转换的值
* @return 结果
*/
Func.toStrList(String split, String str);
```
## firstStr
```java
/**
* 获取第一位String数值
*
* @param str 被转换的值
* @return 结果
*/
Func.firstStr(String str);
```
## firstStr
```java
/**
* 获取第一位String数值
*
* @param split 分隔符
* @param str 被转换的值
* @return 结果
*/
Func.firstStr(String split, String str);
```
## to62String
```java
/**
* 将 long 转短字符串 为 62 进制
*
* @param num 数字
* @return 短字符串
*/
Func.to62String(long num);
```
## join
```java
/**
* 将集合拼接成字符串,默认使用`,`拼接
*
* @param coll the {@code Collection} to convert
* @return the delimited {@code String}
*/
Func.join(Collection> coll);
```
## join
```java
/**
* 将集合拼接成字符串,默认指定分隔符
*
* @param coll the {@code Collection} to convert
* @param delim the delimiter to use (typically a ",")
* @return the delimited {@code String}
*/
Func.join(Collection> coll, String delim);
```
## join
```java
/**
* 将数组拼接成字符串,默认使用`,`拼接
*
* @param arr the array to display
* @return the delimited {@code String}
*/
Func.join(Object[] arr);
```
## join
```java
/**
* 将数组拼接成字符串,默认指定分隔符
*
* @param arr the array to display
* @param delim the delimiter to use (typically a ",")
* @return the delimited {@code String}
*/
Func.join(Object[] arr, String delim);
```
## split
```java
/**
* 切分字符串,不去除切分后每个元素两边的空白符,不去除空白项
*
* @param str 被切分的字符串
* @param separator 分隔符字符
* @return 切分后的集合
*/
Func.split(CharSequence str, char separator);
```
## splitTrim
```java
/**
* 切分字符串,去除切分后每个元素两边的空白符,去除空白项
*
* @param str 被切分的字符串
* @param separator 分隔符字符
* @return 切分后的集合
*/
Func.splitTrim(CharSequence str, char separator);
```
## splitTrim
```java
/**
* 切分字符串,去除切分后每个元素两边的空白符,去除空白项
*
* @param str 被切分的字符串
* @param separator 分隔符字符
* @return 切分后的集合
*/
Func.splitTrim(CharSequence str, CharSequence separator);
```
## split
```java
/**
* 分割 字符串
*
* @param str 字符串
* @param delimiter 分割符
* @return 字符串数组
*/
Func.split(String str, String delimiter);
```
## splitTrim
```java
/**
* 分割 字符串 删除常见 空白符
*
* @param str 字符串
* @param delimiter 分割符
* @return 字符串数组
*/
Func.splitTrim(String str, String delimiter);
```
## simpleMatch
```java
/**
* 字符串是否符合指定的 表达式
*
* InputStream
to read from
* @return the requested String
* @throws NullPointerException if the input is null
*/
Func.readToString(InputStream input);
```
## readToString
```java
/**
* InputStream to String
*
* @param input the InputStream
to read from
* @param charset the Charset
* @return the requested String
* @throws NullPointerException if the input is null
*/
Func.readToString(InputStream input, Charset charset);
```
## readToByteArray
```java
/**
* InputStream to bytes 数组
*
* @param input InputStream
* @return the requested byte array
*/
Func.readToByteArray(InputStream input);
```
## readToString
```java
/**
* 读取文件为字符串
*
* @param file the file to read, must not be {@code null}
* @return the file contents, never {@code null}
*/
Func.readToString(File file);
```
## readToString
```java
/**
* 读取文件为字符串
*
* @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}
*/
Func.readToString(File file, Charset encoding);
```
## readToByteArray
```java
/**
* 读取文件为 byte 数组
*
* @param file the file to read, must not be {@code null}
* @return the file contents, never {@code null}
*/
Func.readToByteArray(File file);
```
## toJson
```java
/**
* 将对象序列化成json字符串
*
* @param object javaBean
* @return jsonString json字符串
*/
Func.toJson(Object object);
```
## toJsonAsBytes
```java
/**
* 将对象序列化成 json byte 数组
*
* @param object javaBean
* @return jsonString json字符串
*/
Func.toJsonAsBytes(Object object);
```
## readTree
```java
/**
* 将json字符串转成 JsonNode
*
* @param jsonString jsonString
* @return jsonString json字符串
*/
Func.readTree(String jsonString);
```
## readTree
```java
/**
* 将json字符串转成 JsonNode
*
* @param in InputStream
* @return jsonString json字符串
*/
Func.readTree(InputStream in);
```
## readTree
```java
/**
* 将json字符串转成 JsonNode
*
* @param content content
* @return jsonString json字符串
*/
Func.readTree(byte[] content);
```
## readTree
```java
/**
* 将json字符串转成 JsonNode
*
* @param jsonParser JsonParser
* @return jsonString json字符串
*/
Func.readTree(JsonParser jsonParser);
```
## readJson
```java
/**
* 将json byte 数组反序列化成对象
*
* @param bytes json bytes
* @param valueType class
* @param