From 4513d48372de566db3e8ad55cbd09cb0fc61f41d Mon Sep 17 00:00:00 2001 From: richie Date: Tue, 27 Aug 2019 13:56:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8D=E7=AC=A6=E5=90=88?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 +++++ .../java/com/fanruan/api/util/ReflectKit.java | 16 +++++++++++ .../java/com/fanruan/api/util/RenderKit.java | 22 +++++++++++++++ .../java/com/fanruan/api/util/StableKit.java | 16 ----------- .../com/fanruan/api/util/TemplateKit.java | 19 ------------- .../com/fanruan/api/util/ReflectKitTest.java | 14 ++++++++++ .../com/fanruan/api/util/RenderKitTest.java | 28 +++++++++++++++++++ .../com/fanruan/api/util/StableKitTest.java | 14 ---------- 8 files changed, 87 insertions(+), 49 deletions(-) create mode 100644 src/main/java/com/fanruan/api/util/ReflectKit.java create mode 100644 src/main/java/com/fanruan/api/util/RenderKit.java delete mode 100644 src/main/java/com/fanruan/api/util/StableKit.java delete mode 100644 src/main/java/com/fanruan/api/util/TemplateKit.java create mode 100644 src/test/java/com/fanruan/api/util/ReflectKitTest.java create mode 100644 src/test/java/com/fanruan/api/util/RenderKitTest.java delete mode 100644 src/test/java/com/fanruan/api/util/StableKitTest.java diff --git a/pom.xml b/pom.xml index d90e077..4737dfd 100644 --- a/pom.xml +++ b/pom.xml @@ -90,6 +90,13 @@ ${common-version} compile + + + com.fr.report + fine-report-designer + ${common-version} + compile + junit junit diff --git a/src/main/java/com/fanruan/api/util/ReflectKit.java b/src/main/java/com/fanruan/api/util/ReflectKit.java new file mode 100644 index 0000000..ef9d4b9 --- /dev/null +++ b/src/main/java/com/fanruan/api/util/ReflectKit.java @@ -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); + } +} diff --git a/src/main/java/com/fanruan/api/util/RenderKit.java b/src/main/java/com/fanruan/api/util/RenderKit.java new file mode 100644 index 0000000..3858679 --- /dev/null +++ b/src/main/java/com/fanruan/api/util/RenderKit.java @@ -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 map) throws Exception { + return TemplateUtils.renderParameter4Tpl(text, map); + } +} diff --git a/src/main/java/com/fanruan/api/util/StableKit.java b/src/main/java/com/fanruan/api/util/StableKit.java deleted file mode 100644 index 112339e..0000000 --- a/src/main/java/com/fanruan/api/util/StableKit.java +++ /dev/null @@ -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); - } -} diff --git a/src/main/java/com/fanruan/api/util/TemplateKit.java b/src/main/java/com/fanruan/api/util/TemplateKit.java deleted file mode 100644 index e8704fe..0000000 --- a/src/main/java/com/fanruan/api/util/TemplateKit.java +++ /dev/null @@ -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); - } -} diff --git a/src/test/java/com/fanruan/api/util/ReflectKitTest.java b/src/test/java/com/fanruan/api/util/ReflectKitTest.java new file mode 100644 index 0000000..1c88dfb --- /dev/null +++ b/src/test/java/com/fanruan/api/util/ReflectKitTest.java @@ -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); + } +} \ No newline at end of file diff --git a/src/test/java/com/fanruan/api/util/RenderKitTest.java b/src/test/java/com/fanruan/api/util/RenderKitTest.java new file mode 100644 index 0000000..4c53c41 --- /dev/null +++ b/src/test/java/com/fanruan/api/util/RenderKitTest.java @@ -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 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)); + } +} \ No newline at end of file diff --git a/src/test/java/com/fanruan/api/util/StableKitTest.java b/src/test/java/com/fanruan/api/util/StableKitTest.java deleted file mode 100644 index cb470b7..0000000 --- a/src/test/java/com/fanruan/api/util/StableKitTest.java +++ /dev/null @@ -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); - } -} \ No newline at end of file