X-Git-Url: http://jaekl.net/gitweb/?p=cfb.git;a=blobdiff_plain;f=prod%2Fnet%2Fjaekl%2Fcfb%2Futil%2FUtil.java;h=309e20dde6e74fd672074cde15ad87aa041a6803;hp=30f4c90c64bc40f63fc9afc7b5d312edd54b8c35;hb=358d80a86ac7c79cd57b81a4f1708da80db2f0ec;hpb=9635991f7480e1b82f897948cf8adf56537c1818 diff --git a/prod/net/jaekl/cfb/util/Util.java b/prod/net/jaekl/cfb/util/Util.java index 30f4c90..309e20d 100644 --- a/prod/net/jaekl/cfb/util/Util.java +++ b/prod/net/jaekl/cfb/util/Util.java @@ -6,10 +6,32 @@ import java.io.PrintWriter; import java.io.StringWriter; public class Util { - public static String stringify(Throwable thr) { + public static String stringify(Throwable thr) + { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); thr.printStackTrace(pw); return sw.toString(); } + + // Test for equality, while taking care to avoid + // dereferencing a null pointer. + // Note that two null pointers are considered equal. + public static boolean objsAreEqual(Object a, Object b) + { + if ((null == a) || (null == b)) { + return (a == b); + } + + return a.equals(b); + } + + // Return 1 if obj is null, or obj.hashCode() otherwise + public static int objHashCode(Object obj) + { + if (null == obj) { + return 1; + } + return obj.hashCode(); + } }