KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > test > collections > UnequalObjectCollectionMismatch


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.test.collections;
5
6 import com.tc.util.Stringifier;
7 import com.tc.util.diff.DifferenceBuilder;
8 import com.tc.util.diff.Differenceable;
9
10 /**
11  * A {@link CollectionMismatch}that is used when two objects aren't equal to each other.
12  */

13 class UnequalObjectCollectionMismatch extends CollectionMismatch {
14
15   public UnequalObjectCollectionMismatch(Object JavaDoc originating, Object JavaDoc comparedAgainst,
16                                          boolean originatingIsInCollectionOne, int originatingIndex,
17                                          int comparedAgainstIndex, Stringifier describer) {
18     super(originating, comparedAgainst, originatingIsInCollectionOne, originatingIndex, comparedAgainstIndex, describer);
19   }
20
21   public String JavaDoc toString() {
22     if (originating() != null && comparedAgainst() != null && (originating() instanceof Differenceable)
23         && (comparedAgainst() instanceof Differenceable)) {
24       // formatting
25
return "Unequal objects: differences are: "
26              + DifferenceBuilder.describeDifferences((Differenceable) originating(),
27                                                      (Differenceable) comparedAgainst(), describer()) + "\n"
28              + originatingString() + "\nis not equal to\n" + comparedAgainstString() + "\n";
29     }
30
31     return "Unequal objects: " + originatingString() + " is not equal to " + comparedAgainstString();
32   }
33   
34 }
Popular Tags