1 4 package com.tc.test.collections; 5 6 import com.tc.util.EqualityComparator; 7 import com.tc.util.Stringifier; 8 9 import java.util.ArrayList ; 10 import java.util.List ; 11 12 15 public class OrderedCollectionComparer extends CollectionComparer { 16 17 public OrderedCollectionComparer(EqualityComparator comparator, Stringifier describer) { 18 super(comparator, describer); 19 } 20 21 protected CollectionMismatch[] doComparison(Object [] collectionOne, Object [] collectionTwo) { 22 List mismatches = new ArrayList (); 23 24 for (int i = 0; i < collectionOne.length; ++i) { 25 Object objectOne = collectionOne[i]; 26 27 if (i >= collectionTwo.length) { 28 mismatches.add(new MissingObjectCollectionMismatch(objectOne, true, i, describer())); 29 } else { 30 Object objectTwo = collectionTwo[i]; 31 boolean isEqual = isEqual(objectOne, true, objectTwo, true, i, i); 32 33 if (!isEqual) { 34 mismatches.add(new UnequalObjectCollectionMismatch(objectOne, objectTwo, true, i, i, describer())); 35 } 36 } 37 } 38 39 for (int i = collectionOne.length; i < collectionTwo.length; ++i) { 40 mismatches.add(new MissingObjectCollectionMismatch(collectionTwo[i], false, i, describer())); 41 } 42 43 return (CollectionMismatch[]) mismatches.toArray(new CollectionMismatch[mismatches.size()]); 44 } 45 46 } | Popular Tags |