new folders for Collections
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/8060e261 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/8060e261 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/8060e261 Branch: refs/heads/mavenfolders Commit: 8060e261ae0b437dea8cba1b4681963cf22a7bfb Parents: cd52541 Author: Alex Harui <[email protected]> Authored: Tue Feb 2 16:30:40 2016 -0800 Committer: Alex Harui <[email protected]> Committed: Tue Feb 2 16:30:40 2016 -0800 ---------------------------------------------------------------------- .../Collections/as/src/CollectionsClasses.as | 35 -- .../org/apache/flex/collections/ArrayList.as | 396 ------------------- .../org/apache/flex/collections/ICollection.as | 43 -- .../flex/collections/IStringCollection.as | 43 -- .../apache/flex/collections/LazyCollection.as | 267 ------------- .../collections/converters/IItemConverter.as | 49 --- .../collections/converters/JSONItemConverter.as | 74 ---- .../flex/collections/parsers/IInputParser.as | 50 --- .../flex/collections/parsers/JSONInputParser.as | 54 --- .../projects/Collections/basic-manifest.xml | 29 -- .../Collections/compile-asjs-config.xml | 69 ---- .../projects/Collections/compile-config.xml | 78 ---- .../src/main/flex/CollectionsClasses.as | 35 ++ .../org/apache/flex/collections/ArrayList.as | 396 +++++++++++++++++++ .../org/apache/flex/collections/ICollection.as | 43 ++ .../flex/collections/IStringCollection.as | 43 ++ .../apache/flex/collections/LazyCollection.as | 267 +++++++++++++ .../collections/converters/IItemConverter.as | 49 +++ .../collections/converters/JSONItemConverter.as | 74 ++++ .../flex/collections/parsers/IInputParser.as | 50 +++ .../flex/collections/parsers/JSONInputParser.as | 54 +++ .../src/main/resources/basic-manifest.xml | 29 ++ .../src/main/resources/compile-asjs-config.xml | 69 ++++ .../src/main/resources/compile-config.xml | 78 ++++ 24 files changed, 1187 insertions(+), 1187 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/as/src/CollectionsClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/as/src/CollectionsClasses.as b/frameworks/projects/Collections/as/src/CollectionsClasses.as deleted file mode 100644 index 5112c5c..0000000 --- a/frameworks/projects/Collections/as/src/CollectionsClasses.as +++ /dev/null @@ -1,35 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// -package -{ - -/** - * @private - * This class is used to link additional classes into rpc.swc - * beyond those that are found by dependecy analysis starting - * from the classes specified in manifest.xml. - */ -internal class CollectionsClasses -{ - import org.apache.flex.collections.ArrayList; ArrayList; - import org.apache.flex.collections.LazyCollection; LazyCollection; -} - -} - http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/as/src/org/apache/flex/collections/ArrayList.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/as/src/org/apache/flex/collections/ArrayList.as b/frameworks/projects/Collections/as/src/org/apache/flex/collections/ArrayList.as deleted file mode 100644 index 58d44e8..0000000 --- a/frameworks/projects/Collections/as/src/org/apache/flex/collections/ArrayList.as +++ /dev/null @@ -1,396 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// -package org.apache.flex.collections -{ - import org.apache.flex.core.IBead; - import org.apache.flex.core.IStrand; - import org.apache.flex.events.Event; - import org.apache.flex.events.EventDispatcher; - import org.apache.flex.events.IEventDispatcher; - import org.apache.flex.collections.parsers.IInputParser; - import org.apache.flex.collections.converters.IItemConverter; - - //-------------------------------------- - // Events - //-------------------------------------- - - /** - * Dispatched when the collection's underlying source array - * is changed. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - [Event(name="collectionChanged", type="org.apache.flex.events.Event")] - - /** - * Dispatched when the collection has added an item. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - [Event(name="itemAdded", type="org.apache.flex.events.Event")] - - /** - * Dispatched when the collection has removed an item. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - [Event(name="itemRemoved", type="org.apache.flex.events.Event")] - - /** - * Dispatched when the collection has updated an item. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - [Event(name="itemUpdated", type="org.apache.flex.events.Event")] - - /** - * The ArrayList class provides an event-driven wrapper for the - * standard Array. Events are dispatched when items are added, removed, - * or changed. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public class ArrayList extends EventDispatcher implements IBead, ICollection - { - /** - * Constructor. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function ArrayList(initialSource:Array=null) - { - super(); - if (initialSource) _source = initialSource; - else _source = []; - } - - private var _id:String; - - /** - * @copy org.apache.flex.core.UIBase#id - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get id():String - { - return _id; - } - - /** - * @private - */ - public function set id(value:String):void - { - if (_id != value) - { - _id = value; - dispatchEvent(new Event("idChanged")); - } - } - - private var _strand:IStrand; - - /** - * @copy org.apache.flex.core.UIBase#strand - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function set strand(value:IStrand):void - { - _strand = value; - _source = new Array(); - } - - private var _source:Array; - - /** - * The array of raw data needing conversion. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get source():Array - { - return _source; - } - - public function set source(value:Array):void - { - if (_source != value) { - if (value == null) _source = []; - else _source = value; - dispatchEvent(new Event("collectionChanged")); - } - } - - /** - * Returns a copy of the source array. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function toArray():Array - { - return _source.concat(); - } - - /** - * Fetches an item from the collection - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function getItemAt(index:int):Object - { - return _source[index]; - } - - /** - * Fetches an item from the collection given an index. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function getItemIndex(item:Object):int - { - for (var index:int=0; index < _source.length; index++) { - if (item == _source[index]) { - return index; - } - } - return -1; - } - - /** - * Adds an item to the end of the array. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function addItem(item:Object):void - { - addItemAt(item, length); - } - - /** - * Inserts an item to a specific location within the array. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function addItemAt(item:Object, index:int):void - { - const spliceUpperBound:int = length; - - if (index < spliceUpperBound && index > 0) - { - source.splice(index, 0, item); - } - else if (index == spliceUpperBound) - { - source.push(item); - } - else if (index == 0) - { - source.unshift(item); - } - else - { - // error - return; - } - - dispatchEvent(new Event("itemAdded")); - } - - /** - * Replaces the item at the given index with a new item and - * returns the old item. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function setItemAt(item:Object, index:int):Object - { - const spliceUpperBound:int = length; - var oldItem:Object; - - if (index >= 0 && index < spliceUpperBound) { - oldItem = source[index]; - source[index] = item; - dispatchEvent(new Event("itemUpdated")); - } - else { - // error - } - - return oldItem; - } - - /** - * Removed an item from the array and returns it. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function removeItem(item:Object):Boolean - { - var index:int = getItemIndex(item); - var result:Boolean = index >= 0; - if (result) { - removeItemAt(index); - } - return result; - } - - /** - * Removes an item from a specific location within the array and - * returns it. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function removeItemAt(index:int):Object - { - const spliceUpperBound:int = length - 1; - var removed:Object; - - if (index > 0 && index < spliceUpperBound) - { - removed = source.splice(index, 1)[0]; - } - else if (index == spliceUpperBound) - { - removed = source.pop(); - } - else if (index == 0) - { - removed = source.shift(); - } - else { - // error - return null; - } - - dispatchEvent(new Event("itemRemoved")); - return removed; - } - - /** - * Removes all of the items from the array. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function removeAll():void - { - if (length > 0) { - source.splice(0, length); - dispatchEvent(new Event("itemRemoved")); - } - } - - /** - * Signals that an item in the array has been updated. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function itemUpdated(item:Object):void - { - var index:int = getItemIndex(item); - if (index >= 0) { - dispatchEvent(new Event("itemUpdated")); - } - } - - /** - * Signals that an item in the array has been updated. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function itemUpdatedAt(index:int):void - { - dispatchEvent(new Event("itemUpdated")); - } - - /** - * The number of items. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get length():int - { - return _source ? _source.length : 0; - } - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/as/src/org/apache/flex/collections/ICollection.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/as/src/org/apache/flex/collections/ICollection.as b/frameworks/projects/Collections/as/src/org/apache/flex/collections/ICollection.as deleted file mode 100644 index e9ae8fd..0000000 --- a/frameworks/projects/Collections/as/src/org/apache/flex/collections/ICollection.as +++ /dev/null @@ -1,43 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// -package org.apache.flex.collections -{ - /** - * The ICollection interface is the basic interface for an iterable collection - * of data items. Other extension may offer the ability to modify the collection - * and dispatch change events. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public interface ICollection - { - /** - * Get the item at a particular index. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - function getItemAt(index:int):Object - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/as/src/org/apache/flex/collections/IStringCollection.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/as/src/org/apache/flex/collections/IStringCollection.as b/frameworks/projects/Collections/as/src/org/apache/flex/collections/IStringCollection.as deleted file mode 100644 index daf47bc..0000000 --- a/frameworks/projects/Collections/as/src/org/apache/flex/collections/IStringCollection.as +++ /dev/null @@ -1,43 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// -package org.apache.flex.collections -{ - /** - * The IStringCollection interface is the basic interface for an iterable collection - * of strings. Other extension may offer the ability to modify the collection - * and dispatch change events. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public interface IStringCollection - { - /** - * Get the string at a particular index. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - function getItemAt(index:int):String - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/as/src/org/apache/flex/collections/LazyCollection.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/as/src/org/apache/flex/collections/LazyCollection.as b/frameworks/projects/Collections/as/src/org/apache/flex/collections/LazyCollection.as deleted file mode 100644 index edf965c..0000000 --- a/frameworks/projects/Collections/as/src/org/apache/flex/collections/LazyCollection.as +++ /dev/null @@ -1,267 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// -package org.apache.flex.collections -{ - COMPILE::AS3 - { - import flash.events.Event; - } - - import org.apache.flex.core.IBead; - import org.apache.flex.core.IStrand; - import org.apache.flex.events.Event; - import org.apache.flex.events.EventDispatcher; - import org.apache.flex.events.IEventDispatcher; - import org.apache.flex.collections.parsers.IInputParser; - import org.apache.flex.collections.converters.IItemConverter; - - //-------------------------------------- - // Events - //-------------------------------------- - - /** - * Dispatched when the collection has processed a complete event. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - [Event(name="complete", type="org.apache.flex.events.Event")] - - /** - * The LazyCollection class implements a collection - * whose items require conversion from a source data format - * to some other data type. For example, converting - * SOAP or JSON to ActionScript data classes. - * The Flex SDK used to convert all of the data items - * when the source data arrived, which, for very large data sets - * or complex data classes, could lock up the user interface. - * The lazy collection converts items as they are fetched from - * the collection, resulting in significant performance savings - * in many cases. Note that, if you need to compute a summary of - * data in the collection when the source data arrives, the - * computation can still lock up the user interface as you will - * have to visit and convert every data item. Of course, it is - * possible to compute that summary in a worker or pseudo-thread. - * The LazyCollection class is designed to be a bead that attaches - * to a data retrieval strand that dispatches an Event.COMPLETE and - * has a "data" property that gets passed to the input parser. - * - * This LazyCollection does not support adding/removing items from - * the collection or sending data back to the source. Subclasses - * have that additional functionality. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public class LazyCollection extends EventDispatcher implements IBead, ICollection - { - /** - * Constructor. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function LazyCollection() - { - super(); - } - - private var _inputParser:IInputParser; - - /** - * A lazy collection uses an IInputParser to convert the source data items - * into an array of data items. This is required in order to determine - * the length of the collection. This conversion happens as the source - * data arrives so it needs to be fast to avoid locking up the UI. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get inputParser():IInputParser - { - return _inputParser; - } - - /** - * @private - */ - public function set inputParser(value:IInputParser):void - { - if (_inputParser != value) - { - _inputParser = value; - dispatchEvent(new org.apache.flex.events.Event("inputParserChanged")); - } - } - - private var _itemConverter:IItemConverter; - - /** - * A lazy collection uses an IItemConverter to convert the source data items - * into the desired data type. The converter is only called as items - * are fetched from the collection. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get itemConverter():IItemConverter - { - return _itemConverter; - } - - /** - * @private - */ - public function set itemConverter(value:IItemConverter):void - { - if (_itemConverter != value) - { - _itemConverter = value; - dispatchEvent(new org.apache.flex.events.Event("itemConverterChanged")); - } - } - - private var _id:String; - - /** - * @copy org.apache.flex.core.UIBase#id - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get id():String - { - return _id; - } - - /** - * @private - */ - public function set id(value:String):void - { - if (_id != value) - { - _id = value; - dispatchEvent(new org.apache.flex.events.Event("idChanged")); - } - } - - private var _strand:IStrand; - - /** - * @copy org.apache.flex.core.UIBase#strand - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function set strand(value:IStrand):void - { - _strand = value; - COMPILE::AS3 - { - IEventDispatcher(_strand).addEventListener(flash.events.Event.COMPLETE, completeHandler); - } - COMPILE::JS - { - IEventDispatcher(_strand).addEventListener("complete", completeHandler); - } - } - - /** - * The array of raw data needing conversion. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - protected var rawData:Array; - - /** - * The array of desired data types. This array is sparse and - * unconverted items are therefore undefined in the array. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - protected var data:Array; - - COMPILE::AS3 - private function completeHandler(event:flash.events.Event):void - { - rawData = inputParser.parseItems(_strand["data"]); - data = new Array(rawData.length); - dispatchEvent(event); - } - COMPILE::JS - private function completeHandler(event:org.apache.flex.events.Event):void - { - rawData = inputParser.parseItems(_strand["data"]); - data = new Array(rawData.length); - dispatchEvent(event); - } - - /** - * Fetches an item from the collection, converting it first if necessary. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function getItemAt(index:int):Object - { - if (data[index] == undefined) - { - data[index] = itemConverter.convertItem(rawData[index]); - } - return data[index]; - } - - /** - * The number of items. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get length():int - { - return rawData ? rawData.length : 0; - } - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/as/src/org/apache/flex/collections/converters/IItemConverter.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/as/src/org/apache/flex/collections/converters/IItemConverter.as b/frameworks/projects/Collections/as/src/org/apache/flex/collections/converters/IItemConverter.as deleted file mode 100644 index 11492ac..0000000 --- a/frameworks/projects/Collections/as/src/org/apache/flex/collections/converters/IItemConverter.as +++ /dev/null @@ -1,49 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// -package org.apache.flex.collections.converters -{ - /** - * The IItemConverter interface is the basic interface for - * converting a serialized data item to a data class instance. - * - * This interface is generally used in a LazyCollection. - * @see org.apache.flex.net.dataConverters.LazyCollection. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public interface IItemConverter - { - /** - * Take the input string (could be serialized data set, - * XML, or JSON) and return a data class instance. - * - * @param s Serialized data item, XML or JSON. - * @return An instance of a data class. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - function convertItem(data:String):Object - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/as/src/org/apache/flex/collections/converters/JSONItemConverter.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/as/src/org/apache/flex/collections/converters/JSONItemConverter.as b/frameworks/projects/Collections/as/src/org/apache/flex/collections/converters/JSONItemConverter.as deleted file mode 100644 index 6fc5888..0000000 --- a/frameworks/projects/Collections/as/src/org/apache/flex/collections/converters/JSONItemConverter.as +++ /dev/null @@ -1,74 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// -package org.apache.flex.collections.converters -{ - import org.apache.flex.collections.converters.IItemConverter; - - /** - * The JSONItemConverter class parses a JSON structure - * into an ActionScript object. Other variants - * would return a specific data class instance. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public class JSONItemConverter implements IItemConverter - { - public function convertItem(data:String):Object - { - var c:int = data.indexOf("{"); - if (c > 0) - data = data.substring(c); - if (data.indexOf("}") == -1) - data += "}"; - return JSON.parse(data); - } - - /** - * Get a property from an object. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - protected function getProperty(obj:Object, propName:String):* - { - if (propName === 'this') - return obj; - - return obj[propName]; - } - - /** - * Set a property on an object. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - protected function setProperty(obj:Object, propName:String, value:*):void - { - obj[propName] = value; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/as/src/org/apache/flex/collections/parsers/IInputParser.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/as/src/org/apache/flex/collections/parsers/IInputParser.as b/frameworks/projects/Collections/as/src/org/apache/flex/collections/parsers/IInputParser.as deleted file mode 100644 index 1cbe76a..0000000 --- a/frameworks/projects/Collections/as/src/org/apache/flex/collections/parsers/IInputParser.as +++ /dev/null @@ -1,50 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// -package org.apache.flex.collections.parsers -{ - /** - * The IInputParser interface is the basic interface for parsing - * data from a server or database into an array of items. - * - * This interface is generally used in a LazyCollection. - * @see org.apache.flex.net.dataConverters.LazyCollection. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public interface IInputParser - { - /** - * Take the input string (could be serialized data set, - * XML, or JSON) and return an array of serialized data - * items. - * - * @param s Serialized data set, XML or JSON. - * @return An Array of serialized data items. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - function parseItems(s:String):Array; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/as/src/org/apache/flex/collections/parsers/JSONInputParser.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/as/src/org/apache/flex/collections/parsers/JSONInputParser.as b/frameworks/projects/Collections/as/src/org/apache/flex/collections/parsers/JSONInputParser.as deleted file mode 100644 index c15c359..0000000 --- a/frameworks/projects/Collections/as/src/org/apache/flex/collections/parsers/JSONInputParser.as +++ /dev/null @@ -1,54 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// -package org.apache.flex.collections.parsers -{ - /** - * The JSONInputParser class parses a JSON structure - * into an array of JSON sub-structures. It assumes - * the input JSON format is an array without sub-arrays. - * A more complex parser might be needed for more complex - * JSON structures. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public class JSONInputParser implements IInputParser - { - /** - * @copy org.apache.flex.net.IInputParser#parseItems - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function parseItems(s:String):Array - { - var c:int = s.indexOf("["); - if (c != -1) - { - var c2:int = s.lastIndexOf("]"); - s = s.substring(c + 1, c2); - } - return s.split("},"); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/basic-manifest.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/basic-manifest.xml b/frameworks/projects/Collections/basic-manifest.xml deleted file mode 100644 index 5ea77b7..0000000 --- a/frameworks/projects/Collections/basic-manifest.xml +++ /dev/null @@ -1,29 +0,0 @@ -<?xml version="1.0"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> - - -<componentPackage> - - <component id="ArrayList" class="org.apache.flex.collections.ArrayList"/> - <component id="LazyCollection" class="org.apache.flex.collections.LazyCollection"/> - <component id="JSONInputParser" class="org.apache.flex.collections.parsers.JSONInputParser"/> - <component id="JSONItemConverter" class="org.apache.flex.collections.converters.JSONItemConverter"/> - -</componentPackage> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/compile-asjs-config.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/compile-asjs-config.xml b/frameworks/projects/Collections/compile-asjs-config.xml deleted file mode 100644 index f5e728e..0000000 --- a/frameworks/projects/Collections/compile-asjs-config.xml +++ /dev/null @@ -1,69 +0,0 @@ -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<flex-config> - - <compiler> - <accessible>false</accessible> - - <external-library-path> - </external-library-path> - - <mxml> - <children-as-data>true</children-as-data> - </mxml> - <binding-value-change-event>org.apache.flex.events.ValueChangeEvent</binding-value-change-event> - <binding-value-change-event-kind>org.apache.flex.events.ValueChangeEvent</binding-value-change-event-kind> - <binding-value-change-event-type>valueChange</binding-value-change-event-type> - - <keep-as3-metadata> - <name>Bindable</name> - <name>Managed</name> - <name>ChangeEvent</name> - <name>NonCommittingChangeEvent</name> - <name>Transient</name> - </keep-as3-metadata> - - <locale/> - - <library-path> - <!-- asjscompc won't 'link' these classes in, but will list their requires - if these swcs are on the external-library-path then their requires - will not be listed --> - <path-element>../../externs/Core.swc</path-element> - </library-path> - - <source-path> - <path-element>as/src</path-element> - </source-path> - - <warn-no-constructor>false</warn-no-constructor> - </compiler> - - <include-sources> - <path-element>as/src</path-element> - </include-sources> - - <include-namespaces> - <uri>library://ns.apache.org/flexjs/basic</uri> - </include-namespaces> - - <target-player>${playerglobal.version}</target-player> - - -</flex-config> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/compile-config.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/compile-config.xml b/frameworks/projects/Collections/compile-config.xml deleted file mode 100644 index 22daebd..0000000 --- a/frameworks/projects/Collections/compile-config.xml +++ /dev/null @@ -1,78 +0,0 @@ -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<flex-config> - - <compiler> - <accessible>false</accessible> - - <external-library-path> - <path-element>${env.AIR_HOME}/frameworks/libs/air/airglobal.swc</path-element> - <path-element>../../libs/Core.swc</path-element> - </external-library-path> - - <mxml> - <children-as-data>true</children-as-data> - </mxml> - <binding-value-change-event>org.apache.flex.events.ValueChangeEvent</binding-value-change-event> - <binding-value-change-event-kind>org.apache.flex.events.ValueChangeEvent</binding-value-change-event-kind> - <binding-value-change-event-type>valueChange</binding-value-change-event-type> - - <keep-as3-metadata> - <name>Bindable</name> - <name>Managed</name> - <name>ChangeEvent</name> - <name>NonCommittingChangeEvent</name> - <name>Transient</name> - </keep-as3-metadata> - - <locale/> - - <library-path/> - - <namespaces> - <namespace> - <uri>library://ns.apache.org/flexjs/basic</uri> - <manifest>basic-manifest.xml</manifest> - </namespace> - </namespaces> - - <source-path> - <path-element>as/src</path-element> - </source-path> - - <warn-no-constructor>false</warn-no-constructor> - </compiler> - - <include-file> - <name>js/out/*</name> - <path>js/out/*</path> - </include-file> - - <include-classes> - <class>CollectionsClasses</class> - </include-classes> - - <include-namespaces> - <uri>library://ns.apache.org/flexjs/basic</uri> - </include-namespaces> - - <target-player>${playerglobal.version}</target-player> - - -</flex-config> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/src/main/flex/CollectionsClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/CollectionsClasses.as b/frameworks/projects/Collections/src/main/flex/CollectionsClasses.as new file mode 100644 index 0000000..5112c5c --- /dev/null +++ b/frameworks/projects/Collections/src/main/flex/CollectionsClasses.as @@ -0,0 +1,35 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package +{ + +/** + * @private + * This class is used to link additional classes into rpc.swc + * beyond those that are found by dependecy analysis starting + * from the classes specified in manifest.xml. + */ +internal class CollectionsClasses +{ + import org.apache.flex.collections.ArrayList; ArrayList; + import org.apache.flex.collections.LazyCollection; LazyCollection; +} + +} + http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ArrayList.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ArrayList.as b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ArrayList.as new file mode 100644 index 0000000..58d44e8 --- /dev/null +++ b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ArrayList.as @@ -0,0 +1,396 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.collections +{ + import org.apache.flex.core.IBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.collections.parsers.IInputParser; + import org.apache.flex.collections.converters.IItemConverter; + + //-------------------------------------- + // Events + //-------------------------------------- + + /** + * Dispatched when the collection's underlying source array + * is changed. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="collectionChanged", type="org.apache.flex.events.Event")] + + /** + * Dispatched when the collection has added an item. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="itemAdded", type="org.apache.flex.events.Event")] + + /** + * Dispatched when the collection has removed an item. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="itemRemoved", type="org.apache.flex.events.Event")] + + /** + * Dispatched when the collection has updated an item. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="itemUpdated", type="org.apache.flex.events.Event")] + + /** + * The ArrayList class provides an event-driven wrapper for the + * standard Array. Events are dispatched when items are added, removed, + * or changed. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class ArrayList extends EventDispatcher implements IBead, ICollection + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function ArrayList(initialSource:Array=null) + { + super(); + if (initialSource) _source = initialSource; + else _source = []; + } + + private var _id:String; + + /** + * @copy org.apache.flex.core.UIBase#id + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get id():String + { + return _id; + } + + /** + * @private + */ + public function set id(value:String):void + { + if (_id != value) + { + _id = value; + dispatchEvent(new Event("idChanged")); + } + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.UIBase#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + _source = new Array(); + } + + private var _source:Array; + + /** + * The array of raw data needing conversion. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get source():Array + { + return _source; + } + + public function set source(value:Array):void + { + if (_source != value) { + if (value == null) _source = []; + else _source = value; + dispatchEvent(new Event("collectionChanged")); + } + } + + /** + * Returns a copy of the source array. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function toArray():Array + { + return _source.concat(); + } + + /** + * Fetches an item from the collection + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function getItemAt(index:int):Object + { + return _source[index]; + } + + /** + * Fetches an item from the collection given an index. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function getItemIndex(item:Object):int + { + for (var index:int=0; index < _source.length; index++) { + if (item == _source[index]) { + return index; + } + } + return -1; + } + + /** + * Adds an item to the end of the array. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function addItem(item:Object):void + { + addItemAt(item, length); + } + + /** + * Inserts an item to a specific location within the array. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function addItemAt(item:Object, index:int):void + { + const spliceUpperBound:int = length; + + if (index < spliceUpperBound && index > 0) + { + source.splice(index, 0, item); + } + else if (index == spliceUpperBound) + { + source.push(item); + } + else if (index == 0) + { + source.unshift(item); + } + else + { + // error + return; + } + + dispatchEvent(new Event("itemAdded")); + } + + /** + * Replaces the item at the given index with a new item and + * returns the old item. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function setItemAt(item:Object, index:int):Object + { + const spliceUpperBound:int = length; + var oldItem:Object; + + if (index >= 0 && index < spliceUpperBound) { + oldItem = source[index]; + source[index] = item; + dispatchEvent(new Event("itemUpdated")); + } + else { + // error + } + + return oldItem; + } + + /** + * Removed an item from the array and returns it. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function removeItem(item:Object):Boolean + { + var index:int = getItemIndex(item); + var result:Boolean = index >= 0; + if (result) { + removeItemAt(index); + } + return result; + } + + /** + * Removes an item from a specific location within the array and + * returns it. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function removeItemAt(index:int):Object + { + const spliceUpperBound:int = length - 1; + var removed:Object; + + if (index > 0 && index < spliceUpperBound) + { + removed = source.splice(index, 1)[0]; + } + else if (index == spliceUpperBound) + { + removed = source.pop(); + } + else if (index == 0) + { + removed = source.shift(); + } + else { + // error + return null; + } + + dispatchEvent(new Event("itemRemoved")); + return removed; + } + + /** + * Removes all of the items from the array. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function removeAll():void + { + if (length > 0) { + source.splice(0, length); + dispatchEvent(new Event("itemRemoved")); + } + } + + /** + * Signals that an item in the array has been updated. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function itemUpdated(item:Object):void + { + var index:int = getItemIndex(item); + if (index >= 0) { + dispatchEvent(new Event("itemUpdated")); + } + } + + /** + * Signals that an item in the array has been updated. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function itemUpdatedAt(index:int):void + { + dispatchEvent(new Event("itemUpdated")); + } + + /** + * The number of items. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get length():int + { + return _source ? _source.length : 0; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ICollection.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ICollection.as b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ICollection.as new file mode 100644 index 0000000..e9ae8fd --- /dev/null +++ b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/ICollection.as @@ -0,0 +1,43 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.collections +{ + /** + * The ICollection interface is the basic interface for an iterable collection + * of data items. Other extension may offer the ability to modify the collection + * and dispatch change events. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public interface ICollection + { + /** + * Get the item at a particular index. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function getItemAt(index:int):Object + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/IStringCollection.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/IStringCollection.as b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/IStringCollection.as new file mode 100644 index 0000000..daf47bc --- /dev/null +++ b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/IStringCollection.as @@ -0,0 +1,43 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.collections +{ + /** + * The IStringCollection interface is the basic interface for an iterable collection + * of strings. Other extension may offer the ability to modify the collection + * and dispatch change events. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public interface IStringCollection + { + /** + * Get the string at a particular index. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function getItemAt(index:int):String + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/LazyCollection.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/LazyCollection.as b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/LazyCollection.as new file mode 100644 index 0000000..edf965c --- /dev/null +++ b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/LazyCollection.as @@ -0,0 +1,267 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.collections +{ + COMPILE::AS3 + { + import flash.events.Event; + } + + import org.apache.flex.core.IBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.collections.parsers.IInputParser; + import org.apache.flex.collections.converters.IItemConverter; + + //-------------------------------------- + // Events + //-------------------------------------- + + /** + * Dispatched when the collection has processed a complete event. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="complete", type="org.apache.flex.events.Event")] + + /** + * The LazyCollection class implements a collection + * whose items require conversion from a source data format + * to some other data type. For example, converting + * SOAP or JSON to ActionScript data classes. + * The Flex SDK used to convert all of the data items + * when the source data arrived, which, for very large data sets + * or complex data classes, could lock up the user interface. + * The lazy collection converts items as they are fetched from + * the collection, resulting in significant performance savings + * in many cases. Note that, if you need to compute a summary of + * data in the collection when the source data arrives, the + * computation can still lock up the user interface as you will + * have to visit and convert every data item. Of course, it is + * possible to compute that summary in a worker or pseudo-thread. + * The LazyCollection class is designed to be a bead that attaches + * to a data retrieval strand that dispatches an Event.COMPLETE and + * has a "data" property that gets passed to the input parser. + * + * This LazyCollection does not support adding/removing items from + * the collection or sending data back to the source. Subclasses + * have that additional functionality. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class LazyCollection extends EventDispatcher implements IBead, ICollection + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function LazyCollection() + { + super(); + } + + private var _inputParser:IInputParser; + + /** + * A lazy collection uses an IInputParser to convert the source data items + * into an array of data items. This is required in order to determine + * the length of the collection. This conversion happens as the source + * data arrives so it needs to be fast to avoid locking up the UI. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get inputParser():IInputParser + { + return _inputParser; + } + + /** + * @private + */ + public function set inputParser(value:IInputParser):void + { + if (_inputParser != value) + { + _inputParser = value; + dispatchEvent(new org.apache.flex.events.Event("inputParserChanged")); + } + } + + private var _itemConverter:IItemConverter; + + /** + * A lazy collection uses an IItemConverter to convert the source data items + * into the desired data type. The converter is only called as items + * are fetched from the collection. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get itemConverter():IItemConverter + { + return _itemConverter; + } + + /** + * @private + */ + public function set itemConverter(value:IItemConverter):void + { + if (_itemConverter != value) + { + _itemConverter = value; + dispatchEvent(new org.apache.flex.events.Event("itemConverterChanged")); + } + } + + private var _id:String; + + /** + * @copy org.apache.flex.core.UIBase#id + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get id():String + { + return _id; + } + + /** + * @private + */ + public function set id(value:String):void + { + if (_id != value) + { + _id = value; + dispatchEvent(new org.apache.flex.events.Event("idChanged")); + } + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.UIBase#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + COMPILE::AS3 + { + IEventDispatcher(_strand).addEventListener(flash.events.Event.COMPLETE, completeHandler); + } + COMPILE::JS + { + IEventDispatcher(_strand).addEventListener("complete", completeHandler); + } + } + + /** + * The array of raw data needing conversion. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected var rawData:Array; + + /** + * The array of desired data types. This array is sparse and + * unconverted items are therefore undefined in the array. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected var data:Array; + + COMPILE::AS3 + private function completeHandler(event:flash.events.Event):void + { + rawData = inputParser.parseItems(_strand["data"]); + data = new Array(rawData.length); + dispatchEvent(event); + } + COMPILE::JS + private function completeHandler(event:org.apache.flex.events.Event):void + { + rawData = inputParser.parseItems(_strand["data"]); + data = new Array(rawData.length); + dispatchEvent(event); + } + + /** + * Fetches an item from the collection, converting it first if necessary. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function getItemAt(index:int):Object + { + if (data[index] == undefined) + { + data[index] = itemConverter.convertItem(rawData[index]); + } + return data[index]; + } + + /** + * The number of items. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get length():int + { + return rawData ? rawData.length : 0; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/converters/IItemConverter.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/converters/IItemConverter.as b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/converters/IItemConverter.as new file mode 100644 index 0000000..11492ac --- /dev/null +++ b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/converters/IItemConverter.as @@ -0,0 +1,49 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.collections.converters +{ + /** + * The IItemConverter interface is the basic interface for + * converting a serialized data item to a data class instance. + * + * This interface is generally used in a LazyCollection. + * @see org.apache.flex.net.dataConverters.LazyCollection. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public interface IItemConverter + { + /** + * Take the input string (could be serialized data set, + * XML, or JSON) and return a data class instance. + * + * @param s Serialized data item, XML or JSON. + * @return An instance of a data class. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function convertItem(data:String):Object + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/converters/JSONItemConverter.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/converters/JSONItemConverter.as b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/converters/JSONItemConverter.as new file mode 100644 index 0000000..6fc5888 --- /dev/null +++ b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/converters/JSONItemConverter.as @@ -0,0 +1,74 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.collections.converters +{ + import org.apache.flex.collections.converters.IItemConverter; + + /** + * The JSONItemConverter class parses a JSON structure + * into an ActionScript object. Other variants + * would return a specific data class instance. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class JSONItemConverter implements IItemConverter + { + public function convertItem(data:String):Object + { + var c:int = data.indexOf("{"); + if (c > 0) + data = data.substring(c); + if (data.indexOf("}") == -1) + data += "}"; + return JSON.parse(data); + } + + /** + * Get a property from an object. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected function getProperty(obj:Object, propName:String):* + { + if (propName === 'this') + return obj; + + return obj[propName]; + } + + /** + * Set a property on an object. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected function setProperty(obj:Object, propName:String, value:*):void + { + obj[propName] = value; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/parsers/IInputParser.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/parsers/IInputParser.as b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/parsers/IInputParser.as new file mode 100644 index 0000000..1cbe76a --- /dev/null +++ b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/parsers/IInputParser.as @@ -0,0 +1,50 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.collections.parsers +{ + /** + * The IInputParser interface is the basic interface for parsing + * data from a server or database into an array of items. + * + * This interface is generally used in a LazyCollection. + * @see org.apache.flex.net.dataConverters.LazyCollection. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public interface IInputParser + { + /** + * Take the input string (could be serialized data set, + * XML, or JSON) and return an array of serialized data + * items. + * + * @param s Serialized data set, XML or JSON. + * @return An Array of serialized data items. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function parseItems(s:String):Array; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/parsers/JSONInputParser.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/parsers/JSONInputParser.as b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/parsers/JSONInputParser.as new file mode 100644 index 0000000..c15c359 --- /dev/null +++ b/frameworks/projects/Collections/src/main/flex/org/apache/flex/collections/parsers/JSONInputParser.as @@ -0,0 +1,54 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.collections.parsers +{ + /** + * The JSONInputParser class parses a JSON structure + * into an array of JSON sub-structures. It assumes + * the input JSON format is an array without sub-arrays. + * A more complex parser might be needed for more complex + * JSON structures. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class JSONInputParser implements IInputParser + { + /** + * @copy org.apache.flex.net.IInputParser#parseItems + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function parseItems(s:String):Array + { + var c:int = s.indexOf("["); + if (c != -1) + { + var c2:int = s.lastIndexOf("]"); + s = s.substring(c + 1, c2); + } + return s.split("},"); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8060e261/frameworks/projects/Collections/src/main/resources/basic-manifest.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/src/main/resources/basic-manifest.xml b/frameworks/projects/Collections/src/main/resources/basic-manifest.xml new file mode 100644 index 0000000..5ea77b7 --- /dev/null +++ b/frameworks/projects/Collections/src/main/resources/basic-manifest.xml @@ -0,0 +1,29 @@ +<?xml version="1.0"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> + + +<componentPackage> + + <component id="ArrayList" class="org.apache.flex.collections.ArrayList"/> + <component id="LazyCollection" class="org.apache.flex.collections.LazyCollection"/> + <component id="JSONInputParser" class="org.apache.flex.collections.parsers.JSONInputParser"/> + <component id="JSONItemConverter" class="org.apache.flex.collections.converters.JSONItemConverter"/> + +</componentPackage>
