X-Git-Url: http://jaekl.net/gitweb/?p=cfb.git;a=blobdiff_plain;f=prod%2Fnet%2Fjaekl%2Fcfb%2Futil%2FUtil.java;h=d1e79bdaa0742c45bb763c302d7404aaa6d44216;hp=309e20dde6e74fd672074cde15ad87aa041a6803;hb=f1c4313e9229dd2d5f7fd984169cbdb89fef4cd5;hpb=9868f50714076f9dc90e7021a45324411afd9ce1 diff --git a/prod/net/jaekl/cfb/util/Util.java b/prod/net/jaekl/cfb/util/Util.java index 309e20d..d1e79bd 100644 --- a/prod/net/jaekl/cfb/util/Util.java +++ b/prod/net/jaekl/cfb/util/Util.java @@ -4,14 +4,38 @@ package net.jaekl.cfb.util; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.Iterator; +import java.util.List; public class Util { - public static String stringify(Throwable thr) + // Returns true iff. a and b contain equal items in the same order + public static boolean listsAreEqual(List a, List b) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - thr.printStackTrace(pw); - return sw.toString(); + if ((null == a) || (null == b)) { + return (a == b); + } + + if (0 == a.size()) { + return (0 == b.size()); + } + + if (a.size() != b.size()) { + return false; + } + + Iterator iterA = a.iterator(); + Iterator iterB = b.iterator(); + + while (iterA.hasNext()) { + Object elemA = iterA.next(); + Object elemB = iterB.next(); + + if (! objsAreEqual(elemA, elemB)) { + return false; + } + } + + return true; } // Test for equality, while taking care to avoid @@ -34,4 +58,14 @@ public class Util { } return obj.hashCode(); } + + // Convert a Throwable to the string representation + // that is generated by printStackTrace(). + public static String stringify(Throwable thr) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + thr.printStackTrace(pw); + return sw.toString(); + } }