0) { switch (objectToUseDropDownList.selectedIndex) { case NON_BINDABLE_OBJECT: collectionTests.fillArrayNonBindable(myArray, numItemsToInitializeWith, fillSeedItems); break; case PROPERTY_CHANGE_BINDABLE_OBJECT: collectionTests.fillArrayPropertyChangeBindable(myArray, numItemsToInitializeWith, fillSeedItems); break; case UNIQUE_EVENT_BINDABLE_OBJECT: collectionTests.fillArrayUniqueEventBindable(myArray, numItemsToInitializeWith, fillSeedItems); break; case SINGLE_VERSION_EVENT_BINDABLE_OBJECT: collectionTests.fillArraySingleVersionEventBindable(myArray, numItemsToInitializeWith, fillSeedItems); break; } } if (numItemsToAddPerSecond > 0) { switch (objectToUseDropDownList.selectedIndex) { case NON_BINDABLE_OBJECT: testResultsAdd = collectionTests.startRandomAdditionsNonBindableArray(myArray, numIterations, numItemsToAddPerSecond, fillObjectsInitially); break; case PROPERTY_CHANGE_BINDABLE_OBJECT: testResultsAdd = collectionTests.startRandomAdditionsPropertyChangeBindableArray(myArray, numIterations, numItemsToAddPerSecond, fillObjectsInitially); break; case UNIQUE_EVENT_BINDABLE_OBJECT: testResultsAdd = collectionTests.startRandomAdditionsUniqueEventBindableArray(myArray, numIterations, numItemsToAddPerSecond, fillObjectsInitially); break; case SINGLE_VERSION_EVENT_BINDABLE_OBJECT: testResultsAdd = collectionTests.startRandomAdditionsSingleVersionEventBindableArray(myArray, numIterations, numItemsToAddPerSecond, fillObjectsInitially); break; } } if (numItemsToUpdatePerSecond > 0) { testResultsUpdate = collectionTests.startRandomPropertyUpdatesArray(myArray, numIterations, numItemsToUpdatePerSecond, numPropertiesPerUpdate); } } private function startVectorTest():void { var myVector:Vector. = new Vector.(); if (numItemsToInitializeWith > 0) { switch (objectToUseDropDownList.selectedIndex) { case NON_BINDABLE_OBJECT: collectionTests.fillVectorNonBindable(myVector, numItemsToInitializeWith, fillSeedItems); break; case PROPERTY_CHANGE_BINDABLE_OBJECT: collectionTests.fillVectorPropertyChangeBindable(myVector, numItemsToInitializeWith, fillSeedItems); break; case UNIQUE_EVENT_BINDABLE_OBJECT: collectionTests.fillVectorUniqueEventBindable(myVector, numItemsToInitializeWith, fillSeedItems); break; case SINGLE_VERSION_EVENT_BINDABLE_OBJECT: collectionTests.fillVectorSingleVersionEventBindable(myVector, numItemsToInitializeWith, fillSeedItems); break; } } if (numItemsToAddPerSecond > 0) { switch (objectToUseDropDownList.selectedIndex) { case NON_BINDABLE_OBJECT: testResultsAdd = collectionTests.startRandomAdditionsNonBindableVector(myVector, numIterations, numItemsToAddPerSecond, fillObjectsInitially); break; case PROPERTY_CHANGE_BINDABLE_OBJECT: testResultsAdd = collectionTests.startRandomAdditionsPropertyChangeBindableVector(myVector, numIterations, numItemsToAddPerSecond, fillObjectsInitially); break; case UNIQUE_EVENT_BINDABLE_OBJECT: testResultsAdd = collectionTests.startRandomAdditionsUniqueEventBindableVector(myVector, numIterations, numItemsToAddPerSecond, fillObjectsInitially); break; case SINGLE_VERSION_EVENT_BINDABLE_OBJECT: testResultsAdd = collectionTests.startRandomAdditionsSingleVersionEventBindableVector(myVector, numIterations, numItemsToAddPerSecond, fillObjectsInitially); break; } } if (numItemsToUpdatePerSecond > 0) { testResultsUpdate = collectionTests.startRandomPropertyUpdatesVector(myVector, numIterations, numItemsToUpdatePerSecond, numPropertiesPerUpdate); } } private function startCollectionTest():void { var myList:IList = createCollectionObject(); collectionWrapper = wrapInOtherCollectionIfNeeded(myList); applySortAndFilterIfNeeded(collectionWrapper, myList); if (numItemsToInitializeWith > 0) { switch (objectToUseDropDownList.selectedIndex) { case NON_BINDABLE_OBJECT: collectionTests.fillCollectionNonBindable(myList, numItemsToInitializeWith, fillSeedItems); break; case PROPERTY_CHANGE_BINDABLE_OBJECT: collectionTests.fillCollectionPropertyChangeBindable(myList, numItemsToInitializeWith, fillSeedItems); break; case UNIQUE_EVENT_BINDABLE_OBJECT: collectionTests.fillCollectionUniqueEventBindable(myList, numItemsToInitializeWith, fillSeedItems); break; case SINGLE_VERSION_EVENT_BINDABLE_OBJECT: collectionTests.fillCollectionSingleVersionEventBindable(myList, numItemsToInitializeWith, fillSeedItems); break; } } if (numItemsToAddPerSecond > 0) { switch (objectToUseDropDownList.selectedIndex) { case NON_BINDABLE_OBJECT: testResultsAdd = collectionTests.startRandomAdditionsNonBindableCollection(myList, numIterations, numItemsToAddPerSecond, fillObjectsInitially); break; case PROPERTY_CHANGE_BINDABLE_OBJECT: testResultsAdd = collectionTests.startRandomAdditionsPropertyChangeBindableCollection(myList, numIterations, numItemsToAddPerSecond, fillObjectsInitially); break; case UNIQUE_EVENT_BINDABLE_OBJECT: testResultsAdd = collectionTests.startRandomAdditionsUniqueEventBindableCollection(myList, numIterations, numItemsToAddPerSecond, fillObjectsInitially); break; case SINGLE_VERSION_EVENT_BINDABLE_OBJECT: testResultsAdd = collectionTests.startRandomAdditionsSingleVersionEventBindableCollection(myList, numIterations, numItemsToAddPerSecond, fillObjectsInitially); break; } } if (numItemsToUpdatePerSecond > 0) { testResultsUpdate = collectionTests.startRandomPropertyUpdatesCollection(myList, numIterations, numItemsToUpdatePerSecond, numPropertiesPerUpdate); } } private function createCollectionObject():IList { if (collectionToUseDropDownList.selectedIndex == ARRAY_LIST_TYPE) return new ArrayList(); else return new ArrayCollection(); } private function applySortAndFilterIfNeeded( collectionWrapper:Object, underlyingCollection:IList):void { var collectionForFilterAndSort:ICollectionView = collectionWrapper as ICollectionView; if (!collectionForFilterAndSort) collectionForFilterAndSort = underlyingCollection as ICollectionView; if (collectionToUseDropDownList.selectedIndex == ARRAY_COLLECTION_FILTER_TYPE || collectionToUseDropDownList.selectedIndex == ARRAY_COLLECTION_FILTER_SORT_TYPE) { collectionForFilterAndSort.filterFunction = testFilterFunction; } if (collectionToUseDropDownList.selectedIndex == ARRAY_COLLECTION_SORT_TYPE || collectionToUseDropDownList.selectedIndex == ARRAY_COLLECTION_FILTER_SORT_TYPE) { collectionForFilterAndSort.sort = getTestSort(); } if (collectionToUseDropDownList.selectedIndex != ARRAY_COLLECTION_TYPE) { collectionForFilterAndSort.refresh(); } } private function wrapInOtherCollectionIfNeeded(myList:IList):Object { var gc2:GroupingCollection2; var hcv:HierarchicalCollectionView; switch (wrappingCollectionToUseDropDownList.selectedIndex) { case WRAPPING_COLLECTION_NONE: return myList; case WRAPPING_COLLECTION_HCV_NO_GROUPING: gc2 = new GroupingCollection2(); gc2.source = myList; gc2.refresh(); hcv = new HierarchicalCollectionView(gc2); return hcv; case WRAPPING_COLLECTION_HCV_WITH_GROUPING: gc2 = new GroupingCollection2(); gc2.grouping = getTestGrouping(); gc2.source = myList; gc2.refresh(); hcv = new HierarchicalCollectionView(gc2); return hcv; } return null; } // just to make sure we hold a reference to these things.. private var collectionWrapper:Object; private function getTestGrouping():Grouping { var grouping:Grouping = new Grouping(); var gf:GroupingField = new GroupingField("property3"); gf.groupingFunction = testGroupingFunction; grouping.fields = [gf]; return grouping; } [Bindable] private var numGroupsForGroupingCollection:int = 10; private function testGroupingFunction(item:Object, field:GroupingField):String { var myNumber:Number = item[field.name] as Number; var groupId:Number = Math.floor(myNumber * numGroupsForGroupingCollection); return groupId.toString(); } private function testCompleteHandler(event:Event):void { // if haven't finished both tests, wait for next event if (numItemsToAddPerSecond > 0 && numItemsToUpdatePerSecond > 0 && testResultsAdd.length != testResultsUpdate.length) { return; } var totalTime:int = 0; var len:int = testResultsAdd ? testResultsAdd.length : 0; for (var i:int = 0; i < len; i++) { totalTime += testResultsAdd[i]; } len = testResultsUpdate ? testResultsUpdate.length : 0; for (i = 0; i < len; i++) { totalTime += testResultsUpdate[i]; } testResultsAdd = testResultsUpdate = null; resultLabel.text += ": " + totalTime; collectionTests.removeEventListener(CollectionTest.TEST_COMPLETE, testCompleteHandler); } [Bindable] public var valToTestForGreaterThanInFilterFunction:Number = 0.8; public function testFilterFunction(item:Object):Boolean { return item.property0 > valToTestForGreaterThanInFilterFunction; } public function getTestSort():Sort { var sort:Sort = new Sort(); sort.fields = [new SortField("property1")]; return sort; } private function formatIntTo3Digits(value:int):String { if (value >= 100) return "" + value; else if (value >= 10) return "0" + value; else return "00" + value; } private function formatIntTo5Digits(value:int):String { if (value >= 10000) return "" + value; if (value >= 1000) return "0" + value; if (value >= 100) return "00" + value; else if (value >= 10) return "000" + value; else return "0000" + value; } ]]> NonBindableObject PropertyChangeBindableObject SingleVersionEventBindableObject UniqueEventBindableObject Array Vector ArrayList ArrayCollection ArrayCollection + Filter ArrayCollection + Sort ArrayCollection + Filter + Sort None GroupingCollection2 no grouping GroupingCollection2 group by 1 field HCV wrapping GC2 no grouping HCV wrapping GC2 group by 1 field