X-Git-Url: http://jaekl.net/gitweb/?a=blobdiff_plain;f=prod%2Fnet%2Fjaekl%2Fcfb%2Futil%2FUtil.java;h=309e20dde6e74fd672074cde15ad87aa041a6803;hb=769f0f2e9b90516e68246b551a4c68f953018c72;hp=c0e7b1ca4b592ee9c2decc8e168fe3994ba3ec00;hpb=08a530ef53cc4756f5e632b69c78830872ebd9f4;p=cfb.git diff --git a/prod/net/jaekl/cfb/util/Util.java b/prod/net/jaekl/cfb/util/Util.java index c0e7b1c..309e20d 100644 --- a/prod/net/jaekl/cfb/util/Util.java +++ b/prod/net/jaekl/cfb/util/Util.java @@ -1,13 +1,37 @@ package net.jaekl.cfb.util; +// Copyright (C) 2015 Christian Jaekl + 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(); + } }