01: /**
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */package com.tc.test.collections;
04:
05: import org.apache.commons.lang.builder.EqualsBuilder;
06:
07: import com.tc.util.Stringifier;
08:
09: /**
10: * A {@link CollectionMismatch}that is used when two collections don't contain the same number of instances of two
11: * objects.
12: */
13: class UnequalObjectCountCollectionMismatch extends CollectionMismatch {
14:
15: private final int numInCollectionOne;
16: private final int numInCollectionTwo;
17:
18: public UnequalObjectCountCollectionMismatch(Object theObject,
19: int objectIndexInCollectionOne, int numInCollectionOne,
20: int numInCollectionTwo, Stringifier describer) {
21: super (theObject, null, true, objectIndexInCollectionOne, -1,
22: describer);
23:
24: this .numInCollectionOne = numInCollectionOne;
25: this .numInCollectionTwo = numInCollectionTwo;
26: }
27:
28: public String toString() {
29: return "Unequal number of objects: " + originatingString()
30: + " occurs " + this .numInCollectionOne + " times "
31: + "in collection one, but " + this .numInCollectionTwo
32: + " times in collection two.";
33: }
34:
35: public boolean equals(Object that) {
36: if (!(that instanceof UnequalObjectCountCollectionMismatch))
37: return false;
38:
39: UnequalObjectCountCollectionMismatch misThat = (UnequalObjectCountCollectionMismatch) that;
40:
41: return new EqualsBuilder().appendSuper(super.equals(that))
42: .append(this.numInCollectionOne,
43: misThat.numInCollectionOne).append(
44: this.numInCollectionTwo,
45: misThat.numInCollectionTwo).isEquals();
46: }
47:
48: }
|