mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-04 12:47:59 +08:00
add methods
This commit is contained in:
parent
e14a1a5ad8
commit
2801373c9e
@ -8,7 +8,7 @@
|
||||
### 新特性
|
||||
* 【setting】 Setting中增加addSetting和autoLoad重载(pr#104@Gitee)
|
||||
* 【core 】 增加copyProperties,根据Class创建对象并进行属性拷贝(pr#105@Gitee)
|
||||
* 【core 】 增加copyProperties,根据Class创建对象并进行属性拷贝(pr#105@Gitee)
|
||||
* 【core 】 添加获取class当前文件夹名称方法(pr#106@Gitee)
|
||||
|
||||
### Bug修复
|
||||
|
||||
|
@ -266,10 +266,10 @@ public class CharUtil {
|
||||
* 是否空白符<br>
|
||||
* 空白符包括空格、制表符、全角空格和不间断空格<br>
|
||||
*
|
||||
* @see Character#isWhitespace(int)
|
||||
* @see Character#isSpaceChar(int)
|
||||
* @param c 字符
|
||||
* @return 是否空白符
|
||||
* @see Character#isWhitespace(int)
|
||||
* @see Character#isSpaceChar(int)
|
||||
* @since 4.0.10
|
||||
*/
|
||||
public static boolean isBlankChar(int c) {
|
||||
@ -324,6 +324,7 @@ public class CharUtil {
|
||||
|
||||
/**
|
||||
* 获取字符类型
|
||||
*
|
||||
* @param c 字符
|
||||
* @return 字符类型
|
||||
* @since 5.2.3
|
||||
|
@ -1054,4 +1054,35 @@ public class ClassUtil {
|
||||
|| objectPackageName.startsWith("javax.") //
|
||||
|| clazz.getClassLoader() == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取class类路径URL, 不管是否在jar包中都会返回文件夹的路径<br>
|
||||
* class在jar包中返回jar所在文件夹,class不在jar中返回文件夹目录<br>
|
||||
* jdk中的类不能使用此方法
|
||||
*
|
||||
* @return URL
|
||||
* @since 5.2.4
|
||||
*/
|
||||
public static URL getLocation(Class<?> clazz) {
|
||||
if (null == clazz) {
|
||||
return null;
|
||||
}
|
||||
return clazz.getProtectionDomain().getCodeSource().getLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取class类路径, 不管是否在jar包中都会返回文件夹的路径<br>
|
||||
* class在jar包中返回jar所在文件夹,class不在jar中返回文件夹目录<br>
|
||||
* jdk中的类不能使用此方法
|
||||
*
|
||||
* @return class路径
|
||||
* @since 5.2.4
|
||||
*/
|
||||
public static String getLocationPath(Class<?> clazz) {
|
||||
final URL location = getLocation(clazz);
|
||||
if (null == location) {
|
||||
return null;
|
||||
}
|
||||
return location.getPath();
|
||||
}
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* {@link ClassUtil} 单元测试
|
||||
*
|
||||
@ -35,7 +36,7 @@ public class ClassUtilTest {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@SuppressWarnings({"unused", "InnerClassMayBeStatic"})
|
||||
class TestSubClass extends TestClass {
|
||||
private String subField;
|
||||
|
||||
@ -102,4 +103,10 @@ public class ClassUtilTest {
|
||||
String result = ClassUtil.getShortClassName(className);
|
||||
Assert.assertEquals("c.h.c.u.StrUtil", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLocationPathTest(){
|
||||
final String classDir = ClassUtil.getLocationPath(ClassUtilTest.class);
|
||||
Assert.assertTrue(Objects.requireNonNull(classDir).endsWith("/hutool-core/target/test-classes/"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user