From f238356e5774f4c6c3b04ae877ada8c3034f4bb3 Mon Sep 17 00:00:00 2001 From: "Mars.Ma" Date: Mon, 26 Aug 2019 15:41:59 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-1118=20=20=E5=B0=86AssistUtil=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E9=9D=99=E6=80=81=E6=96=B9=E6=B3=95=E7=A7=BB=E6=A4=8D?= =?UTF-8?q?=E5=88=B0AssistKit=E4=B8=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fanruan/api/util/AssistKit.java | 85 +++++++++++++++++++ .../com/fanruan/api/util/AssistKitTest.java | 79 +++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 src/main/java/com/fanruan/api/util/AssistKit.java create mode 100644 src/test/java/com/fanruan/api/util/AssistKitTest.java diff --git a/src/main/java/com/fanruan/api/util/AssistKit.java b/src/main/java/com/fanruan/api/util/AssistKit.java new file mode 100644 index 0000000..5fd70ae --- /dev/null +++ b/src/main/java/com/fanruan/api/util/AssistKit.java @@ -0,0 +1,85 @@ +package com.fanruan.api.util; + +import com.fr.stable.AssistUtils; + +public class AssistKit { + /** + * 比较两个双精度浮点型数据是否相等 + * @param parm1 + * @param parm2 + * @return 相等返回true 错误返回false + */ + public static boolean equals(double parm1, double parm2) { + return AssistUtils.equals(parm1, parm2); + } + + /** + * 比较两个单精度浮点型数据是否相等 + * @param parm1 + * @param parm2 + * @return 相等返回true 错误返回false + */ + public static boolean equals(float parm1, float parm2) { + return AssistUtils.equals(parm1, parm2); + } + + /** + * 判断两个Object类型数据是否相等 + * @param parm1 + * @param parm2 + * @return 相等返回true 错误返回false + */ + public static boolean equals(Object parm1, Object parm2) { + return AssistUtils.equals(parm1, parm2); + } + + /** + * 判断两个int类型数据是否相等 + * @param parm1 + * @param parm2 + * @return 相等返回0,如果parm1大于parm2 返回1否则返回-1 + */ + public static int compare(int parm1, int parm2) { + return AssistUtils.compare(parm1, parm2); + } + + /** + * 判断两个long类型数据是否相等 + * @param parm1 + * @param parm2 + * @return 相等返回0,如果parm1大于parm2 返回1否则返回-1 + */ + public static int compare(long parm1, long parm2) { + return AssistUtils.compare(parm1, parm2); + } + + /** + * 生成对象的哈希码值 + * @param parm + * @return 返回对象的哈希码值 + */ + public static int hashCode(Object... parm) { + return AssistUtils.hashCode(parm); + } + + /** + * 返回反映这个对象的字符串 + * @param parm + * @return 返回反映这个对象的字符串 + */ + public static String toString(Object parm) { + return AssistUtils.toString(parm); + } + + /** + * + * @param parm1 + * @param parm2 + * @return + */ +// public static String toString(Object parm1, String... parm2) { +// return AssistUtils.toString(parm1, parm2); +// } + + +} diff --git a/src/test/java/com/fanruan/api/util/AssistKitTest.java b/src/test/java/com/fanruan/api/util/AssistKitTest.java new file mode 100644 index 0000000..f402bda --- /dev/null +++ b/src/test/java/com/fanruan/api/util/AssistKitTest.java @@ -0,0 +1,79 @@ +package com.fanruan.api.util; + +import com.fr.event.Null; +import org.junit.Assert; +import org.junit.Test; + +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.Objects; + +import static org.junit.Assert.*; + +public class AssistKitTest { + + @Test + public void equals1() { + double a = 1.1; + double b = 1.1; + double c = 1.11; + Assert.assertTrue(AssistKit.equals(a, b)); + Assert.assertFalse(AssistKit.equals(b, c)); + } + + @Test + public void equals2() { + float a = 1.1f; + float b = 1.1f; + float c = 1.111f; + Assert.assertTrue(AssistKit.equals(a, b)); + Assert.assertFalse(AssistKit.equals(b, c)); + } + + @Test + public void equals3() { + Object a = 126; + Object b = 126; + //Object c = new Integer(128); + //Object d = new Integer(128); + + Object e = 111.1f; + Assert.assertTrue(AssistKit.equals(a, b)); + Assert.assertTrue(AssistKit.equals(null, null)); + Assert.assertFalse(AssistKit.equals(null, a)); + + //c 和 d应该不是同一个对象啊?为什么返回True? + //Assert.assertTrue(AssistKit.equals(c, d)); + Assert.assertFalse(AssistKit.equals(a,e)); + + } + + @Test + public void compare() { + Assert.assertEquals(0, AssistKit.compare(1, 1)); + Assert.assertEquals(1, AssistKit.compare(2, 1)); + Assert.assertEquals(-1, AssistKit.compare(1, 2)); + } + + @Test + public void compare1() { + Assert.assertEquals(0, AssistKit.compare(1l, 1l)); + Assert.assertEquals(1, AssistKit.compare(2l, 1l)); + Assert.assertEquals(-1, AssistKit.compare(1l, 2l)); + } + + @Test + public void hashCode1() { + String s = "hello"; + Object[] a = new Object[]{s}; + Assert.assertEquals(Arrays.hashCode(a), AssistKit.hashCode(s)); + Assert.assertEquals(0, AssistKit.hashCode(null)); + + } + +// 暂时还没有用到,先不写单元测试 +// @Test +// public void toString1() { +// +// } +} \ No newline at end of file