Browse Source

KERNEL-1118 将AssistUtil中的静态方法移植到AssistKit中。

pull/11/head
Mars.Ma 5 years ago
parent
commit
f238356e57
  1. 85
      src/main/java/com/fanruan/api/util/AssistKit.java
  2. 79
      src/test/java/com/fanruan/api/util/AssistKitTest.java

85
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);
// }
}

79
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() {
//
// }
}
Loading…
Cancel
Save