1 package net.jaekl.cfb.util;
3 // Copyright (C) 2015 Christian Jaekl
5 import java.io.PrintWriter;
6 import java.io.StringWriter;
7 import java.util.Iterator;
11 // Returns true iff. a and b contain equal items in the same order
12 public static boolean listsAreEqual(List<?> a, List<?> b)
14 if ((null == a) || (null == b)) {
19 return (0 == b.size());
22 if (a.size() != b.size()) {
26 Iterator<?> iterA = a.iterator();
27 Iterator<?> iterB = b.iterator();
29 while (iterA.hasNext()) {
30 Object elemA = iterA.next();
31 Object elemB = iterB.next();
33 if (! objsAreEqual(elemA, elemB)) {
41 // Test for equality, while taking care to avoid
42 // dereferencing a null pointer.
43 // Note that two null pointers are considered equal.
44 public static boolean objsAreEqual(Object a, Object b)
46 if ((null == a) || (null == b)) {
53 // Return 1 if obj is null, or obj.hashCode() otherwise
54 public static int objHashCode(Object obj)
59 return obj.hashCode();
62 // Convert a Throwable to the string representation
63 // that is generated by printStackTrace().
64 public static String stringify(Throwable thr)
66 StringWriter sw = new StringWriter();
67 PrintWriter pw = new PrintWriter(sw);
68 thr.printStackTrace(pw);