home *** CD-ROM | disk | FTP | other *** search
Wrap
class mx.data.components.datasetclasses.DataSetIterator extends Object implements mx.data.to.ValueListIterator { var _id; var _dataset; var __filtered; var __filterFunc; var _options; var _startBuff; var _endBuff; var _rangeOn; var _curItemIndex; var _hasPrev; var _hasNext; var _cloned; var _bof; var _eof; var _index; var _indexById; var _keyList; static var Ascending = 32; static var CaseInsensitive = Array.CASEINSENSITIVE; static var Descending = Array.DESCENDING; static var Unique = Array.UNIQUESORT; static var Default = 0; static var FindInsertId = 0; static var FindIndexId = 1; static var FindFirstIndexId = 2; static var FindLastIndexId = 3; static var ItemId = "__ID__"; function DataSetIterator(id, aDataSet, source) { super(); this._id = id; this._dataset = aDataSet; if(source == undefined) { this.reset(); } else { this.__filtered = source.__filtered; this.__filterFunc = source.__filterFunc; this._options = source._options; this._startBuff = source._startBuff; this._endBuff = source._endBuff; this._rangeOn = source._rangeOn; this._curItemIndex = source._curItemIndex; this._hasPrev = source._hasPrev; this._hasNext = source._hasNext; this._cloned = true; this._bof = source._bof; this._eof = source._eof; this._index = source._index; this._indexById = source._indexById; this._keyList = source._keyList; } } function contains(item) { var _loc2_ = this._indexById[item[mx.data.components.datasetclasses.DataSetIterator.ItemId]]; if(this._rangeOn) { return _loc2_ != undefined && (_loc2_ <= this._eof && _loc2_ >= this._bof); } return _loc2_ != undefined; } function first() { return this.resync(this._bof - 1); } function find(propValues) { var _loc2_ = this.findObject(propValues,mx.data.components.datasetclasses.DataSetIterator.FindIndexId); if(_loc2_ < 0) { return null; } this._curItemIndex = _loc2_; return this._index[_loc2_]; } function findFirst(propValues) { var _loc2_ = this.findObject(propValues,mx.data.components.datasetclasses.DataSetIterator.FindFirstIndexId); if(_loc2_ < 0) { return null; } this._curItemIndex = _loc2_; return this._index[_loc2_]; } function findLast(propValues) { var _loc2_ = this.findObject(propValues,mx.data.components.datasetclasses.DataSetIterator.FindLastIndexId); if(_loc2_ < 0) { return null; } this._curItemIndex = _loc2_; return this._index[_loc2_]; } function getCurrentItem() { return this.resync(this._curItemIndex); } function getCurrentItemIndex() { var _loc2_ = this._curItemIndex; if(_loc2_ > this._eof) { _loc2_ = this._eof; } if(_loc2_ < this._bof) { _loc2_ = this._bof; } return _loc2_; } function getFiltered() { return this.__filtered; } function getFilterFunc() { return this.__filterFunc; } function getId() { return this._id; } function getItemAt(index) { var _loc2_ = index + this._bof; if(_loc2_ <= this._eof) { return this._index[_loc2_]; } return null; } function getItemId(index) { return this._index[this._bof + index][mx.data.components.datasetclasses.DataSetIterator.ItemId]; } function getItemIndex(item) { return this._indexById[item[mx.data.components.datasetclasses.DataSetIterator.ItemId]] - this._bof; } function getLength() { if(this.isEmpty()) { return 0; } return this._eof - this._bof + 1; } function getSortInfo() { return {options:this._options,keyList:this._keyList}; } function hasNext() { return this._hasNext; } function hasPrevious() { return this._hasPrev; } function isEmpty() { return this._eof < 0; } function last() { return this.resync(this._eof + 1); } function modelChanged(eventObj) { var _loc4_ = false; if(this._options == mx.data.components.datasetclasses.DataSetIterator.Default && !this.__filtered) { this._index = this._dataset.__items; this._indexById = this._dataset._itemIndexById; if(eventObj.eventName == "removeItems" && this._curItemIndex > this._index.length - 1) { this._curItemIndex = this._curItemIndex - 1; } _loc4_ = eventObj.eventName != "updateField"; } else if(!this._cloned) { var _loc9_ = undefined; if(eventObj.eventName == "removeItems") { var _loc7_ = undefined; var _loc6_ = eventObj.removedIDs; if(eventObj.firstItem == 0 && eventObj.lastItem == this._index.length) { this._index.splice(0,eventObj.lastItem); } else { var _loc2_ = 0; while(_loc2_ < _loc6_.length) { _loc7_ = _loc6_[_loc2_]; this._index.splice(this._indexById[_loc7_],1); _loc2_ = _loc2_ + 1; } } this.rebuildIndexById(); _loc4_ = true; } else if(eventObj.eventName == "addItems") { var _loc8_ = this._dataset.__items; _loc2_ = eventObj.firstItem; while(_loc2_ <= eventObj.lastItem) { _loc9_ = _loc8_[_loc2_]; var _loc5_ = _loc2_; if(!this.__filtered || this.__filterFunc(_loc9_)) { if(this._options != mx.data.components.datasetclasses.DataSetIterator.Default) { _loc5_ = this.findObject(_loc9_,mx.data.components.datasetclasses.DataSetIterator.FindInsertId); } this._index.splice(_loc5_,0,_loc9_); this.rebuildIndexById(); _loc4_ = true; } _loc2_ = _loc2_ + 1; } } else if(eventObj.eventName == "updateField") { _loc2_ = 0; while(_loc2_ < this._keyList.length && !_loc4_) { _loc4_ = this._keyList[_loc2_] == eventObj.fieldName; _loc2_ = _loc2_ + 1; } if(_loc4_) { _loc9_ = this._dataset.__items[eventObj.firstItem]; this._index.splice(this._indexById[_loc9_[mx.data.components.datasetclasses.DataSetIterator.ItemId]],1); var _loc10_ = this.findObject(_loc9_,mx.data.components.datasetclasses.DataSetIterator.FindInsertId); this._index.splice(_loc10_,0,_loc9_); this.rebuildIndexById(); } } } if(_loc4_) { this.recalcEndPoints(); } return _loc4_; } function setFiltered(value) { var _loc2_ = 0; if(this.__filtered != value) { _loc2_ = this.internalFilterItems(value); this.__filtered = value; } return _loc2_; } function setFilterFunc(value) { var _loc2_ = 0; this.__filterFunc = value; if(this.__filterFunc == null && this.__filtered) { return this.internalFilterItems(false); } if(this.__filtered) { this.internalFilterItems(false); _loc2_ = this.internalFilterItems(true); } return _loc2_; } function skip(offset) { return this.resync(this._curItemIndex + offset); } function next() { return this.skip(1); } function previous() { return this.skip(-1); } function removeRange() { if(this._rangeOn) { this._rangeOn = false; this.recalcEndPoints(); } } function reset() { this.__filtered = false; this.__filterFunc = null; this._options = mx.data.components.datasetclasses.DataSetIterator.Default; this._startBuff = null; this._endBuff = null; this._rangeOn = false; this._cloned = false; this._index = this._dataset.__items; this._indexById = this._dataset._itemIndexById; this.resetEndPoints(); this._curItemIndex = this._bof; this._hasPrev = false; this._hasNext = this._curItemIndex < this._eof; } function setRange(startValues, endValues) { this.checkSort(); this.resetEndPoints(); this._rangeOn = true; this._startBuff = startValues; this._endBuff = endValues; this.recalcEndPoints(); } function setSortOptions(options) { if(this._options != mx.data.components.datasetclasses.DataSetIterator.Default) { if((options & mx.data.components.datasetclasses.DataSetIterator.Ascending) == mx.data.components.datasetclasses.DataSetIterator.Ascending && (this._options & mx.data.components.datasetclasses.DataSetIterator.Descending) == mx.data.components.datasetclasses.DataSetIterator.Descending) { this._options ^= mx.data.components.datasetclasses.DataSetIterator.Descending; } this._options |= !this.hasNumericKey() ? 0 : Array.NUMERIC; this._options |= options; this.internalSort(); this.first(); this.recalcEndPoints(); } } function sortOn(propList, options) { this._options = options != undefined ? options : mx.data.components.datasetclasses.DataSetIterator.Ascending; this._keyList = propList; this._rangeOn = false; this._options |= !this.hasNumericKey() ? 0 : Array.NUMERIC; this.internalSort(); this.first(); this.recalcEndPoints(); } function checkSort() { if(this._options == mx.data.components.datasetclasses.DataSetIterator.Default) { throw new mx.data.components.datasetclasses.DataSetError("Operation not applicable when no sort has been defined. Error for iterator \'" + this._id + "\'."); } } function checkError(a) { if(typeof a == "number") { throw new mx.data.components.datasetclasses.DataSetError("Sort failed with the following error \'" + mx.utils.ErrorStrings.getPlayerError(a) + "\'"); } } function compareValues(a, b) { if(a == null && b == null) { return 0; } if(a == null) { return 1; } if(b == null) { return -1; } if(a < b) { return -1; } if(a > b) { return 1; } return 0; } function comparePropList(alist, blist, ci) { var _loc5_ = undefined; var _loc6_ = 0; var _loc4_ = 0; var _loc2_ = undefined; var _loc3_ = undefined; while(_loc6_ == 0 && _loc4_ < this._keyList.length) { _loc5_ = this._keyList[_loc4_]; _loc2_ = alist[_loc5_]; _loc3_ = blist[_loc5_]; if(ci && typeof _loc2_ == "string") { _loc2_ = _loc2_.toLowerCase(); _loc3_ = _loc3_.toLowerCase(); } _loc6_ = this.compareValues(_loc2_,_loc3_); _loc4_ = _loc4_ + 1; } return _loc6_; } function hasNumericKey() { var _loc3_ = this._index[0]; var _loc2_ = 0; while(_loc2_ < this._keyList.length) { if(typeof _loc3_[this._keyList[_loc2_]] == "number") { return true; } _loc2_ = _loc2_ + 1; } return false; } function filterIndex() { var _loc7_ = new Array(); var _loc3_ = undefined; var _loc4_ = false; var _loc6_ = 0; var _loc8_ = undefined; var _loc5_ = 0; this._indexById = new Array(); var _loc2_ = 0; while(_loc2_ < this._index.length) { _loc3_ = this._index[_loc2_]; try { _loc4_ = this.__filterFunc(_loc3_); } finally { } if(_loc4_) { _loc7_.push(_loc3_); this._indexById[_loc3_[mx.data.components.datasetclasses.DataSetIterator.ItemId]] = _loc5_; _loc5_ = _loc5_ + 1; } else { _loc6_ = _loc6_ - 1; } _loc2_ = _loc2_ + 1; } this._index = _loc7_; this._cloned = false; return _loc6_; } function findObject(propInfo, mode) { var _loc19_ = propInfo[mx.data.components.datasetclasses.DataSetIterator.ItemId]; if(_loc19_ != undefined && mode != mx.data.components.datasetclasses.DataSetIterator.FindInsertId) { var _loc18_ = this._indexById[_loc19_]; if(this._rangeOn && (_loc18_ > this._eof || _loc18_ < this._bof)) { _loc18_ = -1; } return _loc18_; } this.checkSort(); var _loc3_ = false; var _loc17_ = mode == mx.data.components.datasetclasses.DataSetIterator.FindIndexId || mode == mx.data.components.datasetclasses.DataSetIterator.FindFirstIndexId || mode == mx.data.components.datasetclasses.DataSetIterator.FindLastIndexId; var _loc15_ = (this._options & mx.data.components.datasetclasses.DataSetIterator.Unique) != mx.data.components.datasetclasses.DataSetIterator.Unique; var _loc16_ = false; var _loc2_ = 0; var _loc6_ = !_loc17_ ? 0 : this._bof; var _loc7_ = !_loc17_ ? this._index.length - 1 : this._eof; var _loc14_ = null; var _loc12_ = 1; var _loc13_ = (this._options & mx.data.components.datasetclasses.DataSetIterator.Descending) == mx.data.components.datasetclasses.DataSetIterator.Descending; var _loc9_ = (this._options & mx.data.components.datasetclasses.DataSetIterator.CaseInsensitive) == mx.data.components.datasetclasses.DataSetIterator.CaseInsensitive; while(!_loc16_ && _loc6_ <= _loc7_) { _loc2_ = Math.round((_loc6_ + _loc7_) / 2); _loc14_ = this._index[_loc2_]; _loc12_ = this.comparePropList(propInfo,_loc14_,_loc9_); switch(_loc12_) { case -1: if(_loc13_) { _loc6_ = _loc2_ + 1; } else { _loc7_ = _loc2_ - 1; } break; case 0: _loc16_ = true; if(!_loc15_ && mode == mx.data.components.datasetclasses.DataSetIterator.FindInsertId) { throw new mx.data.components.datasetclasses.DataSetError("Duplicate key specified. Error for index \'" + this._id + "\' on dataset \'" + this._dataset._name + "\'."); } if(_loc15_ && _loc17_) { switch(mode) { case mx.data.components.datasetclasses.DataSetIterator.FindIndexId: _loc3_ = true; break; case mx.data.components.datasetclasses.DataSetIterator.FindFirstIndexId: _loc3_ = _loc2_ == _loc6_; var _loc8_ = null; var _loc5_ = _loc2_ - 1; var _loc4_ = true; while(_loc4_ && !_loc3_ && _loc5_ >= _loc6_) { _loc8_ = this._index[_loc5_]; _loc4_ = this.comparePropList(propInfo,_loc8_,_loc9_) == 0; if(!_loc4_ || _loc4_ && _loc5_ == _loc6_) { _loc3_ = true; _loc2_ = _loc5_ + (!_loc4_ ? 1 : 0); } _loc5_ = _loc5_ - 1; } break; case mx.data.components.datasetclasses.DataSetIterator.FindLastIndexId: _loc3_ = _loc2_ == _loc7_; _loc8_ = null; _loc5_ = _loc2_ + 1; _loc4_ = true; while(_loc4_ && !_loc3_ && _loc5_ <= _loc7_) { _loc8_ = this._index[_loc5_]; _loc4_ = this.comparePropList(propInfo,_loc8_,_loc9_) == 0; if(!_loc4_ || _loc4_ && _loc5_ == _loc7_) { _loc3_ = true; _loc2_ = _loc5_ - (!_loc4_ ? 1 : 0); } _loc5_ = _loc5_ + 1; } } } else { _loc3_ = true; } break; case 1: if(_loc13_) { _loc7_ = _loc2_ - 1; } else { _loc6_ = _loc2_ + 1; } break; } } if(!_loc3_ && _loc17_) { return -1; } if(_loc13_) { return _loc12_ >= 0 ? _loc2_ : _loc2_ + 1; } return _loc12_ <= 0 ? _loc2_ : _loc2_ + 1; } function internalFilterItems(value) { var _loc2_ = 0; if(value && this.__filterFunc != null) { _loc2_ = this.filterIndex(); } else { this.unfilterIndex(); if(this._options != mx.data.components.datasetclasses.DataSetIterator.Default) { this.internalSort(); } _loc2_ = this._index.length; } this.recalcEndPoints(); return _loc2_; } function internalSort() { var _loc5_ = (this._options & mx.data.components.datasetclasses.DataSetIterator.Ascending) != mx.data.components.datasetclasses.DataSetIterator.Ascending ? this._options : this._options ^ mx.data.components.datasetclasses.DataSetIterator.Ascending; if(this._cloned) { this._cloned = false; var _loc3_ = this._index.sortOn(Object(this._keyList),_loc5_ | Array.RETURNINDEXEDARRAY); this.checkError(_loc3_); var _loc4_ = new Array(); var _loc2_ = 0; while(_loc2_ < _loc3_.length) { _loc4_.push(this._index[_loc3_[_loc2_]]); _loc2_ = _loc2_ + 1; } this._index = _loc4_; } else { this.checkError(this._index.sortOn(Object(this._keyList),_loc5_)); } this.rebuildIndexById(); } function recalcEndPoints() { this.resetEndPoints(); if(this._rangeOn) { var _loc3_ = (this._options & mx.data.components.datasetclasses.DataSetIterator.Descending) == mx.data.components.datasetclasses.DataSetIterator.Descending; var _loc2_ = undefined; if(_loc3_) { _loc2_ = this._startBuff; this._startBuff = this._endBuff; this._endBuff = _loc2_; } this._bof = this.findObject(this._startBuff,mx.data.components.datasetclasses.DataSetIterator.FindFirstIndexId); if(this._bof >= 0) { this._eof = this.findObject(this._endBuff,mx.data.components.datasetclasses.DataSetIterator.FindLastIndexId); if(this._eof < 0) { this._bof = 0; } } else { this._eof = this._bof - 1; } this._curItemIndex = this._bof - 1; } this.resync(this._curItemIndex); } function resetEndPoints() { this._eof = this._index.length - 1; this._bof = 0; } function rebuildIndexById() { this._indexById = new Array(); var _loc2_ = 0; while(_loc2_ < this._index.length) { this._indexById[this._index[_loc2_][mx.data.components.datasetclasses.DataSetIterator.ItemId]] = _loc2_; _loc2_ = _loc2_ + 1; } } function resync(newPos) { if(this._eof < this._bof) { this._hasNext = false; this._hasPrev = false; this._curItemIndex = this._eof; return null; } if(newPos >= this._eof) { this._hasNext = false; this._hasPrev = true; if(newPos == this._eof) { this._curItemIndex = this._eof; return this._index[this._eof]; } this._curItemIndex = this._eof + 1; return null; } if(newPos <= this._bof) { this._hasPrev = false; this._hasNext = true; if(newPos == this._bof) { this._curItemIndex = this._bof; return this._index[this._bof]; } this._curItemIndex = this._bof - 1; return null; } this._curItemIndex = newPos; this._hasNext = true; this._hasPrev = true; return this._index[this._curItemIndex]; } function unfilterIndex() { this._index = this._dataset.__items; this._indexById = this._dataset._itemIndexById; this._cloned = true; } }