| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| MapEntry |
|
| 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 |
| 31 | { | |
| 32 | import org.as3coreaddendum.system.IEquatable; | |
| 33 | import org.as3utils.ReflectionUtil; | |
| 34 | ||
| 35 | /** | |
| 36 | * An entry maintaining a key and a value. | |
| 37 | * | |
| 38 | * @author Flávio Silva | |
| 39 | */ | |
| 40 | public class MapEntry implements IMapEntry | |
| 41 | { | |
| 42 | private var _key :*; | |
| 43 | private var _value :*; | |
| 44 | ||
| 45 | /** | |
| 46 | * Returns the key corresponding to this entry. | |
| 47 | */ | |
| 48 | public function get key(): * { return _key; } | |
| 49 | ||
| 50 | /** | |
| 51 | * Returns the value corresponding to this entry. | |
| 52 | */ | |
| 53 | public function get value(): * { return _value; } | |
| 54 | ||
| 55 | /** | |
| 56 | * Constructor, creates a new <code>MapEntry</code> object. | |
| 57 | * | |
| 58 | * @param key the key represented by this entry. | |
| 59 | * @param value the value represented by this entry. | |
| 60 | */ | |
| 61 | public function MapEntry(key:*, value:*) | |
| 62 | 1 | { |
| 63 | 1 | _key = key; |
| 64 | 1 | _value = value; |
| 65 | 1 | } |
| 66 | ||
| 67 | /** | |
| 68 | * Creates and return a new <code>MapEntry</code> object with the same key-value mapping. | |
| 69 | * | |
| 70 | * @return a new <code>MapEntry</code> object with the same key-value mapping. | |
| 71 | */ | |
| 72 | public function clone(): * | |
| 73 | { | |
| 74 | 1 | return new MapEntry(_key, _value); |
| 75 | } | |
| 76 | ||
| 77 | /** | |
| 78 | * Performs an arbitrary, specific evaluation of equality between this object and the <code>other</code> object. | |
| 79 | * <p>This implementation considers two differente objects equal if:</p> | |
| 80 | * <p> | |
| 81 | * <ul><li>object A and object B are instances of the same class</li> | |
| 82 | * <li>A.key == B.key</li> | |
| 83 | * <li>A.value == B.value</li> | |
| 84 | * </ul></p> | |
| 85 | * | |
| 86 | * @param other the object to be compared for equality. | |
| 87 | * @return <code>true</code> if the arbitrary evaluation considers the objects equal. | |
| 88 | */ | |
| 89 | public function equals(other:*): Boolean | |
| 90 | { | |
| 91 | 1 | if (this == other) return true; |
| 92 | ||
| 93 | 1 | if (!ReflectionUtil.classPathEquals(this, other)) return false; |
| 94 | ||
| 95 | 1 | var o:IMapEntry = other as IMapEntry; |
| 96 | ||
| 97 | 1 | if (!o) return false; |
| 98 | ||
| 99 | var k:Boolean; | |
| 100 | var v:Boolean; | |
| 101 | ||
| 102 | 1 | if (_key is IEquatable && o.key is IEquatable) |
| 103 | { | |
| 104 | 1 | k = (_key as IEquatable).equals(o.key); |
| 105 | } | |
| 106 | else | |
| 107 | { | |
| 108 | 1 | k = _key == o.key; |
| 109 | } | |
| 110 | ||
| 111 | 1 | if (_value is IEquatable && o.value is IEquatable) |
| 112 | { | |
| 113 | 1 | v = (_value as IEquatable).equals(o.value); |
| 114 | } | |
| 115 | else | |
| 116 | { | |
| 117 | 1 | v = _value == o.value; |
| 118 | } | |
| 119 | ||
| 120 | 1 | return k && v; |
| 121 | } | |
| 122 | ||
| 123 | /** | |
| 124 | * Returns the string representation of this instance. | |
| 125 | * | |
| 126 | * @return the string representation of this instance. | |
| 127 | */ | |
| 128 | public function toString():String | |
| 129 | { | |
| 130 | 1 | return _key + "=" + _value; |
| 131 | } | |
| 132 | } | |
| 133 | ||
| 134 | } |