add methods

This commit is contained in:
Looly
2020-03-13 17:07:30 +08:00
parent a508f2d5aa
commit c38e6f0c1a
7 changed files with 111 additions and 15 deletions

View File

@@ -53,7 +53,7 @@ public abstract class AbstractConverter<T> implements Converter<T>, Serializable
if (null == defaultValue || targetType.isInstance(defaultValue)) {
if (targetType.isInstance(value) && false == Map.class.isAssignableFrom(targetType)) {
// 除Map外已经是目标类型不需要转换Map类型涉及参数类型需要单独转换
return (T) targetType.cast(value);
return targetType.cast(value);
}
T result = convertInternal(value);
return ((null == result) ? defaultValue : result);

View File

@@ -34,6 +34,7 @@ public class FastByteArrayOutputStream extends OutputStream {
buffer = new FastByteBuffer(size);
}
@SuppressWarnings("NullableProblems")
@Override
public void write(byte[] b, int off, int len) {
buffer.append(b, off, len);
@@ -52,7 +53,7 @@ public class FastByteArrayOutputStream extends OutputStream {
* 此方法无任何效果当流被关闭后不会抛出IOException
*/
@Override
public void close() throws IOException{
public void close() {
// nop
}

View File

@@ -244,6 +244,7 @@ public class CharUtil {
* @return true表示为字符类
*/
public static boolean isChar(Object value) {
//noinspection ConstantConditions
return value instanceof Character || value.getClass() == char.class;
}
@@ -283,13 +284,14 @@ public class CharUtil {
* @since 4.0.8
*/
public static boolean isEmoji(char c) {
//noinspection ConstantConditions
return false == ((c == 0x0) || //
(c == 0x9) || //
(c == 0xA) || //
(c == 0xD) || //
((c >= 0x20) && (c <= 0xD7FF)) || //
((c >= 0xE000) && (c <= 0xFFFD)) || //
((c >= 0x10000) && (c <= 0x10FFFF)));
((c >= 0x100000) && (c <= 0x10FFFF)));
}
/**
@@ -319,4 +321,14 @@ public class CharUtil {
}
return c1 == c2;
}
/**
* 获取字符类型
* @param c 字符
* @return 字符类型
* @since 5.2.3
*/
public static int getType(int c){
return Character.getType(c);
}
}

View File

@@ -20,4 +20,10 @@ public class CharUtilTest {
Assert.assertTrue(CharUtil.isEmoji(a.charAt(1)));
}
@Test
public void isCharTest(){
char[] a = new char[]{'a'};
Assert.assertTrue(CharUtil.isChar(a));
}
}