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 com.tc.util.EqualityComparator;
06: import com.tc.util.Stringifier;
07:
08: import java.util.ArrayList;
09: import java.util.List;
10:
11: /**
12: * A {@link CollectionComparer}that requires the collections to be in the same order.
13: */
14: public class OrderedCollectionComparer extends CollectionComparer {
15:
16: public OrderedCollectionComparer(EqualityComparator comparator,
17: Stringifier describer) {
18: super (comparator, describer);
19: }
20:
21: protected CollectionMismatch[] doComparison(Object[] collectionOne,
22: Object[] collectionTwo) {
23: List mismatches = new ArrayList();
24:
25: for (int i = 0; i < collectionOne.length; ++i) {
26: Object objectOne = collectionOne[i];
27:
28: if (i >= collectionTwo.length) {
29: mismatches.add(new MissingObjectCollectionMismatch(
30: objectOne, true, i, describer()));
31: } else {
32: Object objectTwo = collectionTwo[i];
33: boolean isEqual = isEqual(objectOne, true, objectTwo,
34: true, i, i);
35:
36: if (!isEqual) {
37: mismatches.add(new UnequalObjectCollectionMismatch(
38: objectOne, objectTwo, true, i, i,
39: describer()));
40: }
41: }
42: }
43:
44: for (int i = collectionOne.length; i < collectionTwo.length; ++i) {
45: mismatches.add(new MissingObjectCollectionMismatch(
46: collectionTwo[i], false, i, describer()));
47: }
48:
49: return (CollectionMismatch[]) mismatches
50: .toArray(new CollectionMismatch[mismatches.size()]);
51: }
52:
53: }
|