royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject [royale-asjs] 01/01: Added Map
Date Sun, 25 Feb 2018 11:30:19 GMT
This is an automated email from the ASF dual-hosted git repository.

harbs pushed a commit to branch feature/native-js
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git

commit fa36e70dc9dfd924db30a512f1a2f8622e218ae4
Author: Harbs <harbs@in-tools.com>
AuthorDate: Sun Feb 25 13:30:10 2018 +0200

    Added Map
---
 .../projects/Core/src/main/royale/CoreClasses.as   |   6 ++
 frameworks/projects/Core/src/main/royale/Map.as    | 101 +++++++++++++++++++++
 2 files changed, 107 insertions(+)

diff --git a/frameworks/projects/Core/src/main/royale/CoreClasses.as b/frameworks/projects/Core/src/main/royale/CoreClasses.as
index 0408118..fc9595e 100644
--- a/frameworks/projects/Core/src/main/royale/CoreClasses.as
+++ b/frameworks/projects/Core/src/main/royale/CoreClasses.as
@@ -224,6 +224,12 @@ internal class CoreClasses
 		import org.apache.royale.core.WrappedHTMLElement ;WrappedHTMLElement;
 	    import org.apache.royale.core.IRoyaleElement; IRoyaleElement;
 	}
+
+	//JS native classes
+	COMPILE::SWF
+	{
+		import Map; Map;
+	}
 	//Package Level Functions
 	import org.apache.royale.debugging.assert; assert;
 	import org.apache.royale.debugging.assertType; assertType;
diff --git a/frameworks/projects/Core/src/main/royale/Map.as b/frameworks/projects/Core/src/main/royale/Map.as
new file mode 100644
index 0000000..e2549ea
--- /dev/null
+++ b/frameworks/projects/Core/src/main/royale/Map.as
@@ -0,0 +1,101 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 "Licens"); 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
+{
+    COMPILE::SWF
+    {
+        import flash.utils.Dictionary;
+    }
+    COMPILE::SWF
+    public class Map
+    {
+        public function Map(iterable:Object=null)
+        {
+            dict = new Dictionary();
+        }
+
+        private var dict:Dictionary;
+        public static const length:int = 0;
+
+        private var _keys:Array = [];
+        public function get size():int
+        {
+            return _keys.length;
+        }
+
+        public function clear():void
+        {
+            dict = new Dictionary();
+            _keys = [];
+        }
+
+        public function delete(key:*):Boolean
+        {
+            var idx:int = _keys.indexOf(key);
+            if(idx != -1){
+                _keys.splice(idx,1);
+            }
+            return delete dict[key];
+        }
+
+        //TODO requires Iterator
+        // public function entries():Iterator
+        // {
+            
+        // }
+
+        public function forEach(callback:Function,thisArg:Object = null):void
+        {
+            thisArg = thisArg ? thisArg : this;
+            var len:int = _keys.length;
+            for(var i:int = 0; i < len; i++)
+            {
+                callback.call(thisArg,dict[_keys[i]],i,this);
+            }
+        }
+
+        public function get(key:Object):*
+        {
+            return dict[key];
+        }
+
+        public function has(key:Object):Boolean
+        {
+            return dict[key] != null;
+        }
+
+        //TODO requires Iterator
+        // public function keys():Iterator
+        // {
+            
+        // }
+
+        public function set(key:Object,value:*):Map
+        {
+            dict[key] = value;
+            return this;
+        }
+
+        //TODO requires Iterator
+        // public function values():Iterator
+        // {
+            
+        // }
+    }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
harbs@apache.org.

Mime
View raw message