1、分享一个实现六种常用数据类型(boolean、char、long、float、double及Object)的equas等值判断,完整的工具类代码如下所示
public final class EqualsUtil@b@{@b@ public static boolean areEqual(boolean aThis, boolean aThat)@b@ {@b@ return (aThis == aThat);@b@ }@b@@b@ public static boolean areEqual(char aThis, char aThat)@b@ {@b@ return (aThis == aThat);@b@ }@b@@b@ public static boolean areEqual(long aThis, long aThat)@b@ {@b@ return (aThis == aThat);@b@ }@b@@b@ public static boolean areEqual(float aThis, float aThat)@b@ {@b@ return (Float.floatToIntBits(aThis) == Float.floatToIntBits(aThat));@b@ }@b@@b@ public static boolean areEqual(double aThis, double aThat)@b@ {@b@ return (Double.doubleToLongBits(aThis) == Double.doubleToLongBits(aThat));@b@ }@b@@b@ public static boolean areEqual(Object aThis, Object aThat)@b@ {@b@ return ((aThis == null) ? false : (aThat == null) ? true : aThis.equals(aThat));@b@ }@b@}
2.基于if-util-3.2.8.jar的工具类EqualsUtil
package com.bill99.seashell.common.util;@b@@b@public final class EqualsUtil@b@{@b@ public static boolean areEqual(boolean aThis, boolean aThat)@b@ {@b@ return (aThis == aThat);@b@ }@b@@b@ public static boolean areEqual(char aThis, char aThat)@b@ {@b@ return (aThis == aThat);@b@ }@b@@b@ public static boolean areEqual(long aThis, long aThat)@b@ {@b@ return (aThis == aThat);@b@ }@b@@b@ public static boolean areEqual(float aThis, float aThat)@b@ {@b@ return (Float.floatToIntBits(aThis) == Float.floatToIntBits(aThat));@b@ }@b@@b@ public static boolean areEqual(double aThis, double aThat)@b@ {@b@ return (Double.doubleToLongBits(aThis) == Double.doubleToLongBits(aThat));@b@ }@b@@b@ public static boolean areEqual(Object aThis, Object aThat)@b@ {@b@ return ((aThis == null) ? false : (aThat == null) ? true : aThis.equals(aThat));@b@ }@b@@b@ public static boolean areEqual(String aThis, String aThat)@b@ {@b@ aThis = trim(aThis);@b@ aThat = trim(aThat);@b@ return ((aThis == null) ? false : (aThat == null) ? true : aThis.equals(aThat));@b@ }@b@@b@ private static String trim(String s)@b@ {@b@ if (s == null) {@b@ return null;@b@ }@b@@b@ return s.trim();@b@ }@b@}