forked from fanruan/finekit
richie
5 years ago
8 changed files with 87 additions and 49 deletions
@ -0,0 +1,16 @@
|
||||
package com.fanruan.api.util; |
||||
|
||||
import com.fr.stable.StableUtils; |
||||
|
||||
public class ReflectKit { |
||||
|
||||
/** |
||||
* 判断一个类是否是另一个类的子类 |
||||
* @param current 当前类 |
||||
* @param target 目标类 |
||||
* @return 如果当前类是目标类的子类,则返回true,否则返回false |
||||
*/ |
||||
public static boolean classInstanceOf(Class current, Class target) { |
||||
return StableUtils.classInstanceOf(current, target); |
||||
} |
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.fanruan.api.util; |
||||
|
||||
import com.fr.base.TemplateUtils; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 文本动态渲染工具类 |
||||
*/ |
||||
public class RenderKit { |
||||
|
||||
/** |
||||
* 根据参数, 来计算文档字符串 |
||||
* @param text 待渲染的文本模板 |
||||
* @param map 参数集合 |
||||
* @return 返回渲染后的文本 |
||||
* @throws Exception 渲染过程中出现错误则抛出此异常 |
||||
*/ |
||||
public static String renderParameter4Tpl(String text, Map<String, Object> map) throws Exception { |
||||
return TemplateUtils.renderParameter4Tpl(text, map); |
||||
} |
||||
} |
@ -1,16 +0,0 @@
|
||||
package com.fanruan.api.util; |
||||
|
||||
import com.fr.stable.StableUtils; |
||||
|
||||
public class StableKit { |
||||
|
||||
/** |
||||
* 判断class1是否是class2的子类实例化 |
||||
* @param class1 |
||||
* @param class2 |
||||
* @return 返回判断结果 |
||||
*/ |
||||
public static boolean classInstanceOf(Class class1, Class class2) { |
||||
return StableUtils.classInstanceOf(class1, class2); |
||||
} |
||||
} |
@ -1,19 +0,0 @@
|
||||
package com.fanruan.api.util; |
||||
|
||||
import com.fr.base.TemplateUtils; |
||||
|
||||
import java.util.Map; |
||||
|
||||
public class TemplateKit { |
||||
|
||||
/** |
||||
* 根据参数, 来计算文档字符串 |
||||
* @param tpl |
||||
* @param map |
||||
* @return 返回计算后的值 |
||||
* @throws Exception |
||||
*/ |
||||
public static String renderParameter4Tpl(String tpl, Map map) throws Exception { |
||||
return TemplateUtils.renderParameter4Tpl(tpl, map); |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fanruan.api.util; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
public class ReflectKitTest { |
||||
|
||||
@Test |
||||
public void classInstanceOf() { |
||||
assertEquals(ReflectKit.classInstanceOf(Integer.class,Object.class),true); |
||||
assertEquals(ReflectKit.classInstanceOf(Object.class,Integer.class),false); |
||||
} |
||||
} |
@ -0,0 +1,28 @@
|
||||
package com.fanruan.api.util; |
||||
|
||||
import com.fanruan.api.Prepare; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-08-27 |
||||
*/ |
||||
public class RenderKitTest extends Prepare { |
||||
|
||||
@Test |
||||
public void renderParameter4Tpl() throws Exception { |
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("age", 20); |
||||
map.put("name", "Alex"); |
||||
map.put("salary", 100); |
||||
String text = "${name} is ${age} years old, he earned ${salary} dollars per month."; |
||||
Assert.assertEquals("Alex is 20 years old, he earned 100 dollars per month.", RenderKit.renderParameter4Tpl(text, map)); |
||||
} |
||||
} |
@ -1,14 +0,0 @@
|
||||
package com.fanruan.api.util; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
public class StableKitTest { |
||||
|
||||
@Test |
||||
public void classInstanceOf() { |
||||
assertEquals(StableKit.classInstanceOf(Integer.class,Object.class),true); |
||||
assertEquals(StableKit.classInstanceOf(Object.class,Integer.class),false); |
||||
} |
||||
} |
Loading…
Reference in new issue