| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ReadOnlyArrayListMap |
|
| 0.0;0 |
| 1 | /* | |
| 2 | * Licensed under the MIT License | |
| 3 | * | |
| 4 | * Copyright 2010 (c) Flávio Silva, http://flsilva.com | |
| 5 | * | |
| 6 | * Permission is hereby granted, free of charge, to any person | |
| 7 | * obtaining a copy of this software and associated documentation | |
| 8 | * files (the "Software"), to deal in the Software without | |
| 9 | * restriction, including without limitation the rights to use, | |
| 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| 11 | * copies of the Software, and to permit persons to whom the | |
| 12 | * Software is furnished to do so, subject to the following | |
| 13 | * conditions: | |
| 14 | * | |
| 15 | * The above copyright notice and this permission notice shall be | |
| 16 | * included in all copies or substantial portions of the Software. | |
| 17 | * | |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
| 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | |
| 20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
| 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
| 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
| 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
| 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
| 25 | * OTHER DEALINGS IN THE SOFTWARE. | |
| 26 | * | |
| 27 | * http://www.opensource.org/licenses/mit-license.php | |
| 28 | */ | |
| 29 | ||
| 30 | 1 | package org.as3collections.maps |
| 31 | { | |
| 32 | import org.as3collections.AbstractListMap; | |
| 33 | import org.as3collections.ICollection; | |
| 34 | import org.as3collections.IIterator; | |
| 35 | import org.as3collections.IMap; | |
| 36 | import org.as3collections.IMapEntry; | |
| 37 | import org.as3collections.iterators.ReadOnlyMapIterator; | |
| 38 | import org.as3coreaddendum.errors.UnsupportedOperationError; | |
| 39 | import org.as3utils.ReflectionUtil; | |
| 40 | ||
| 41 | /** | |
| 42 | * An <code>ArrayListMap</code> that doesn't allow modifications. | |
| 43 | * It receives all the mappings by its constructor and can no longer be changed. | |
| 44 | * All methods that change the map will throw an <code>UnsupportedOperationError</code>. | |
| 45 | * | |
| 46 | * @example | |
| 47 | * | |
| 48 | * <listing version="3.0"> | |
| 49 | * import org.as3collections.IMap; | |
| 50 | * import org.as3collections.maps.ArrayListMap; | |
| 51 | * import org.as3collections.maps.ReadOnlyArrayListMap; | |
| 52 | * | |
| 53 | * var map1:IMap = new ArrayListMap(); | |
| 54 | * | |
| 55 | * map1.put("fa", "fb"): // null | |
| 56 | * map1.put("ga", "gb"): // null | |
| 57 | * map1.put("ha", "hb"): // null | |
| 58 | * | |
| 59 | * map1 // {fa=fb,ga=gb,ha=hb} | |
| 60 | * map1.size() // 3 | |
| 61 | * | |
| 62 | * var map2:IMap = new ReadOnlyArrayListMap(map1); | |
| 63 | * | |
| 64 | * map2 // {fa=fb,ga=gb,ha=hb} | |
| 65 | * map2.size() // 3 | |
| 66 | * | |
| 67 | * map2.put(1, 2) // UnsupportedOperationError: ReadOnlyArrayListMap is a read-only map and doesn't allow modifications. | |
| 68 | * | |
| 69 | * map2.remove(1) // UnsupportedOperationError: ReadOnlyArrayListMap is a read-only map and doesn't allow modifications. | |
| 70 | * </listing> | |
| 71 | * | |
| 72 | * @author Flávio Silva | |
| 73 | */ | |
| 74 | public class ReadOnlyArrayListMap extends AbstractListMap | |
| 75 | { | |
| 76 | /** | |
| 77 | * Constructor, creates a new <code>ReadOnlyArrayListMap</code> object. | |
| 78 | * | |
| 79 | * @param source an map to fill the list. | |
| 80 | * @throws ArgumentError if the <code>source</code> argument is <code>null</code>. | |
| 81 | */ | |
| 82 | public function ReadOnlyArrayListMap(source:IMap) | |
| 83 | 1 | { |
| 84 | 1 | if (!source) throw new ArgumentError("The 'source' argument must not be 'null'."); |
| 85 | ||
| 86 | 1 | var it:IIterator = source.iterator(); |
| 87 | var value:*; | |
| 88 | ||
| 89 | 1 | while (it.hasNext()) |
| 90 | { | |
| 91 | 1 | value = it.next(); |
| 92 | ||
| 93 | 1 | keys.add(it.pointer()); |
| 94 | 1 | values.add(value); |
| 95 | ||
| 96 | 1 | keyAdded(it.pointer()); |
| 97 | 1 | valueAdded(value); |
| 98 | } | |
| 99 | 1 | } |
| 100 | ||
| 101 | /** | |
| 102 | * This implementation always throws an <code>UnsupportedOperationError</code>. | |
| 103 | * | |
| 104 | * @throws org.as3coreaddendum.errors.UnsupportedOperationError <code>ReadOnlyArrayListMap</code> is a read-only map and doesn't allow modifications. | |
| 105 | */ | |
| 106 | override public function clear(): void | |
| 107 | { | |
| 108 | 1 | throw new UnsupportedOperationError(ReflectionUtil.getClassName(this) + " is a read-only map and doesn't allow modifications."); |
| 109 | } | |
| 110 | ||
| 111 | /** | |
| 112 | * Creates and return a new <code>ReadOnlyArrayListMap</code> object containing all mappings in this map (in the same order). | |
| 113 | * | |
| 114 | * @return a new <code>ReadOnlyArrayListMap</code> object containing all mappings in this map (in the same order). | |
| 115 | */ | |
| 116 | override public function clone(): * | |
| 117 | { | |
| 118 | 1 | return new ReadOnlyArrayListMap(this); |
| 119 | } | |
| 120 | ||
| 121 | /** | |
| 122 | * Returns an iterator over a set of mappings. | |
| 123 | * <p>This implementation returns a <code>ReadOnlyMapIterator</code> object.</p> | |
| 124 | * | |
| 125 | * @return an iterator over a set of values. | |
| 126 | * @see org.as3collections.iterators.ReadOnlyMapIterator ReadOnlyMapIterator | |
| 127 | */ | |
| 128 | override public function iterator(): IIterator | |
| 129 | { | |
| 130 | 1 | return new ReadOnlyMapIterator(this); |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * This implementation always throws an <code>UnsupportedOperationError</code>. | |
| 135 | * | |
| 136 | * @param key | |
| 137 | * @param value | |
| 138 | * @throws org.as3coreaddendum.errors.UnsupportedOperationError <code>ReadOnlyArrayListMap</code> is a read-only map and doesn't allow modifications. | |
| 139 | * @return | |
| 140 | */ | |
| 141 | override public function put(key:*, value:*): * | |
| 142 | { | |
| 143 | 1 | throw new UnsupportedOperationError(ReflectionUtil.getClassName(this) + " is a read-only map and doesn't allow modifications."); |
| 144 | } | |
| 145 | ||
| 146 | /** | |
| 147 | * This implementation always throws an <code>UnsupportedOperationError</code>. | |
| 148 | * | |
| 149 | * @param map | |
| 150 | * @throws org.as3coreaddendum.errors.UnsupportedOperationError <code>ReadOnlyArrayListMap</code> is a read-only map and doesn't allow modifications. | |
| 151 | */ | |
| 152 | override public function putAll(map:IMap): void | |
| 153 | { | |
| 154 | 1 | throw new UnsupportedOperationError(ReflectionUtil.getClassName(this) + " is a read-only map and doesn't allow modifications."); |
| 155 | } | |
| 156 | ||
| 157 | /** | |
| 158 | * This implementation always throws an <code>UnsupportedOperationError</code>. | |
| 159 | * | |
| 160 | * @param o | |
| 161 | * @throws org.as3coreaddendum.errors.UnsupportedOperationError <code>ReadOnlyArrayListMap</code> is a read-only map and doesn't allow modifications. | |
| 162 | */ | |
| 163 | override public function putAllByObject(o:Object): void | |
| 164 | { | |
| 165 | 1 | throw new UnsupportedOperationError(ReflectionUtil.getClassName(this) + " is a read-only map and doesn't allow modifications."); |
| 166 | } | |
| 167 | ||
| 168 | /** | |
| 169 | * This implementation always throws an <code>UnsupportedOperationError</code>. | |
| 170 | * | |
| 171 | * @param entry | |
| 172 | * @throws org.as3coreaddendum.errors.UnsupportedOperationError <code>ReadOnlyArrayListMap</code> is a read-only map and doesn't allow modifications. | |
| 173 | * @return | |
| 174 | */ | |
| 175 | override public function putEntry(entry:IMapEntry): * | |
| 176 | { | |
| 177 | 1 | throw new UnsupportedOperationError(ReflectionUtil.getClassName(this) + " is a read-only map and doesn't allow modifications."); |
| 178 | } | |
| 179 | ||
| 180 | /** | |
| 181 | * This implementation always throws an <code>UnsupportedOperationError</code>. | |
| 182 | * | |
| 183 | * @param key | |
| 184 | * @throws org.as3coreaddendum.errors.UnsupportedOperationError <code>ReadOnlyArrayListMap</code> is a read-only map and doesn't allow modifications. | |
| 185 | * @return | |
| 186 | */ | |
| 187 | override public function remove(key:*): * | |
| 188 | { | |
| 189 | 1 | throw new UnsupportedOperationError(ReflectionUtil.getClassName(this) + " is a read-only map and doesn't allow modifications."); |
| 190 | } | |
| 191 | ||
| 192 | /** | |
| 193 | * This implementation always throws an <code>UnsupportedOperationError</code>. | |
| 194 | * | |
| 195 | * @param keys | |
| 196 | * @throws org.as3coreaddendum.errors.UnsupportedOperationError <code>ReadOnlyArrayListMap</code> is a read-only map and doesn't allow modifications. | |
| 197 | * @return | |
| 198 | */ | |
| 199 | override public function removeAll(keys:ICollection): Boolean | |
| 200 | { | |
| 201 | 1 | throw new UnsupportedOperationError(ReflectionUtil.getClassName(this) + " is a read-only map and doesn't allow modifications."); |
| 202 | } | |
| 203 | ||
| 204 | /** | |
| 205 | * This implementation always throws an <code>UnsupportedOperationError</code>. | |
| 206 | * | |
| 207 | * @param keys | |
| 208 | * @throws org.as3coreaddendum.errors.UnsupportedOperationError <code>ReadOnlyArrayListMap</code> is a read-only map and doesn't allow modifications. | |
| 209 | * @return | |
| 210 | */ | |
| 211 | override public function retainAll(keys:ICollection): Boolean | |
| 212 | { | |
| 213 | 1 | throw new UnsupportedOperationError(ReflectionUtil.getClassName(this) + " is a read-only map and doesn't allow modifications."); |
| 214 | } | |
| 215 | ||
| 216 | } | |
| 217 | ||
| 218 | } |