KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.commons.lang.builder.EqualsBuilder;
7
8 import com.tc.util.Stringifier;
9
10 /**
11  * A {@link CollectionMismatch}that is used when two collections don't contain the same number of instances of two
12  * objects.
13  */

14 class UnequalObjectCountCollectionMismatch extends CollectionMismatch {
15
16   private final int numInCollectionOne;
17   private final int numInCollectionTwo;
18
19   public UnequalObjectCountCollectionMismatch(Object JavaDoc theObject, int objectIndexInCollectionOne, int numInCollectionOne,
20                                               int numInCollectionTwo, Stringifier describer) {
21     super(theObject, null, true, objectIndexInCollectionOne, -1, describer);
22
23     this.numInCollectionOne = numInCollectionOne;
24     this.numInCollectionTwo = numInCollectionTwo;
25   }
26
27   public String JavaDoc toString() {
28     return "Unequal number of objects: " + originatingString() + " occurs " + this.numInCollectionOne + " times "
29            + "in collection one, but " + this.numInCollectionTwo + " times in collection two.";
30   }
31
32   public boolean equals(Object JavaDoc that) {
33     if (!(that instanceof UnequalObjectCountCollectionMismatch)) return false;
34
35     UnequalObjectCountCollectionMismatch misThat = (UnequalObjectCountCollectionMismatch) that;
36
37     return new EqualsBuilder().appendSuper(super.equals(that)).append(this.numInCollectionOne,
38                                                                       misThat.numInCollectionOne)
39         .append(this.numInCollectionTwo, misThat.numInCollectionTwo).isEquals();
40   }
41
42 }
Popular Tags