From ccb2a9ceafb51ae19efdb7a56f4b6f31c39c61c5 Mon Sep 17 00:00:00 2001 From: mdb Date: Wed, 11 Jan 2006 19:00:26 +0000 Subject: [PATCH] Added an equality check for exceptions. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1752 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../java/com/samskivert/util/ObjectUtil.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/projects/samskivert/src/java/com/samskivert/util/ObjectUtil.java b/projects/samskivert/src/java/com/samskivert/util/ObjectUtil.java index df33df6a..a723ef2f 100644 --- a/projects/samskivert/src/java/com/samskivert/util/ObjectUtil.java +++ b/projects/samskivert/src/java/com/samskivert/util/ObjectUtil.java @@ -36,6 +36,34 @@ public class ObjectUtil return (o1 == o2) || ((o1 != null) && o1.equals(o2)); } + /** + * Returns true if the two supplied exceptions have equal messages and + * equal stack traces. + */ + public static boolean equals (Throwable t1, Throwable t2) + { + if (t1 == t2) { + return true; + } + if (t1 == null || t2 == null) { + return false; + } + if (!equals(t1.getMessage(), t2.getMessage())) { + return false; + } + StackTraceElement[] ste1 = t1.getStackTrace(); + StackTraceElement[] ste2 = t2.getStackTrace(); + if (ste1.length != ste2.length) { + return false; + } + for (int ii = 0; ii < ste1.length; ii++) { + if (!ste1[ii].equals(ste2[ii])) { + return false; + } + } + return true; + } + /** * Dumps the contents of the supplied object instance, listing the * class name, hash code and toString() data for each