1 /* 2 * Copyright the original author or authors. 3 * 4 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.mozilla.org/MPL/MPL-1.1.html 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import org.as2lib.core.BasicClass; 18 import org.as2lib.util.Stringifier; 19 import org.as2lib.data.holder.map.MapStringifier; 20 21 /** 22 * {@code AbstractMap} offers implementations of methods needed by most concrete 23 * {@link org.as2lib.data.holder.Map} implementations. 24 * 25 * @author Simon Wacker 26 */ 27 class org.as2lib.data.holder.map.AbstractMap extends BasicClass { 28 29 /** Stringifies maps. */ 30 private static var stringifier:Stringifier; 31 32 /** 33 * Returns the stringifier that stringifies maps. 34 * 35 * <p>If no stringifier has been set manually an instance of class {@link MapStringifier} 36 * will be returned. 37 * 38 * @return the stringifier that stringifies maps 39 */ 40 public static function getStringifier(Void):Stringifier { 41 if (!stringifier) stringifier = new MapStringifier(); 42 return stringifier; 43 } 44 45 /** 46 * Sets the new stringifier that stringifies maps. 47 * 48 * <p>If you set a stringifier of value {@code null} or {@code undefined} the static 49 * method {@link #getStringifier} will return the default stringifier. 50 * 51 * @param mapStringifier the new map stringifier 52 */ 53 public static function setStringifier(mapStringifier:Stringifier):Void { 54 stringifier = mapStringifier; 55 } 56 57 /** 58 * Constructs a new {@code AbstractMap} instance. 59 */ 60 private function AbstractMap(Void) { 61 } 62 63 /** 64 * Populates the map with the content of the passed-in {@code source}. 65 * 66 * <p>Iterates over the passed-in source with the for..in loop and uses the variables' 67 * names as key and their values as value. Variables that are hidden from for..in 68 * loops will not be added to this map. 69 * 70 * <p>This method uses the {@code put} method to add the key-value pairs. 71 * 72 * @param source an object that contains key-value pairs to populate this map with 73 */ 74 private function populate(source):Void { 75 if (source) { 76 for (var i:String in source) { 77 this["put"](i, source[i]); 78 } 79 } 80 } 81 82 }