一、前言
关于ebean的源码包中com.avaje.ebeaninternal.util.ValueUtil值工具类,实现java.math.BigDecimal、java.net.URL及字符等值areEqual、areEqualBytes、areEqualChars判断。
二、源码说明
package com.avaje.ebeaninternal.util;@b@@b@import java.math.BigDecimal;@b@import java.net.URL;@b@@b@public class ValueUtil@b@{@b@ public static boolean areEqual(Object obj1, Object obj2)@b@ {@b@ if (obj1 == null)@b@ return (obj2 == null);@b@@b@ if (obj2 == null)@b@ return false;@b@@b@ if (obj1 == obj2)@b@ return true;@b@@b@ if (obj1 instanceof BigDecimal)@b@ {@b@ if (obj2 instanceof BigDecimal) {@b@ Comparable com1 = (Comparable)obj1;@b@ return (com1.compareTo(obj2) == 0);@b@ }@b@@b@ return false;@b@ }@b@@b@ if (obj1 instanceof URL)@b@ {@b@ return obj1.toString().equals(obj2.toString());@b@ }@b@ if ((obj1 instanceof byte[]) && (obj2 instanceof byte[]))@b@ return areEqualBytes((byte[])(byte[])obj1, (byte[])(byte[])obj2);@b@@b@ if ((obj1 instanceof char[]) && (obj2 instanceof char[]))@b@ return areEqualChars((char[])(char[])obj1, (char[])(char[])obj2);@b@@b@ return obj1.equals(obj2);@b@ }@b@@b@ private static boolean areEqualBytes(byte[] b1, byte[] b2) {@b@ if (b1.length != b2.length)@b@ return false;@b@@b@ for (int i = 0; i < b1.length; ++i)@b@ if (b1[i] != b2[i])@b@ return false;@b@@b@@b@ return true;@b@ }@b@@b@ private static boolean areEqualChars(char[] b1, char[] b2) {@b@ if (b1.length != b2.length)@b@ return false;@b@@b@ for (int i = 0; i < b1.length; ++i)@b@ if (b1[i] != b2[i])@b@ return false;@b@@b@@b@ return true;@b@ }@b@}