]> jaekl.net Git - cfb.git/blob - prod/net/jaekl/cfb/util/Util.java
309e20dde6e74fd672074cde15ad87aa041a6803
[cfb.git] / prod / net / jaekl / cfb / util / Util.java
1 package net.jaekl.cfb.util;
2
3 // Copyright (C) 2015 Christian Jaekl
4
5 import java.io.PrintWriter;
6 import java.io.StringWriter;
7
8 public class Util {
9         public static String stringify(Throwable thr) 
10         {
11                 StringWriter sw = new StringWriter();
12                 PrintWriter pw = new PrintWriter(sw);
13                 thr.printStackTrace(pw);
14                 return sw.toString();
15         }
16         
17         // Test for equality, while taking care to avoid 
18         // dereferencing a null pointer.
19         // Note that two null pointers are considered equal.
20         public static boolean objsAreEqual(Object a, Object b) 
21         {
22                 if ((null == a) || (null == b)) {
23                         return (a == b);
24                 }
25                 
26                 return a.equals(b);
27         }
28         
29         // Return 1 if obj is null, or obj.hashCode() otherwise
30         public static int objHashCode(Object obj)
31         {
32                 if (null == obj) {
33                         return 1;
34                 }
35                 return obj.hashCode();
36         }
37 }