KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > util > exception > StandardExceptionEqualityComparator


1 /**
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.util.exception;
5
6 import org.apache.commons.lang.builder.EqualsBuilder;
7
8 /**
9  * The standard implementation of {@link ExceptionEqualityComparator}.
10  */

11 public class StandardExceptionEqualityComparator implements ExceptionEqualityComparator {
12
13   private static final StandardExceptionEqualityComparator INSTANCE = new StandardExceptionEqualityComparator();
14
15   private StandardExceptionEqualityComparator() {
16     // Nothing here yet.
17
}
18
19   public static StandardExceptionEqualityComparator getInstance() {
20     return INSTANCE;
21   }
22
23   public boolean exceptionsEqual(Throwable JavaDoc exceptionOne, Throwable JavaDoc exceptionTwo) {
24     EqualsBuilder builder = new EqualsBuilder();
25
26     builder.append(exceptionOne == null, exceptionTwo == null);
27
28     if (exceptionOne != null && exceptionTwo != null) {
29       builder.append(exceptionOne.getClass(), exceptionTwo.getClass());
30       builder.append(exceptionOne.getMessage(), exceptionTwo.getMessage());
31       builder.append(exceptionOne.getStackTrace(), exceptionTwo.getStackTrace());
32     }
33
34     return builder.isEquals();
35   }
36
37 }
38
Popular Tags