Compares the specified object to this instance, and returns true if the specified object is a map and both maps contain the same mappings. @param object the object to compare with this object. @return boolean true if the object is the same as this object, and {@co
(Object object)
| 123 | * @see #entrySet() |
| 124 | */ |
| 125 | @Override |
| 126 | public boolean equals(Object object) { |
| 127 | if (this == object) { |
| 128 | return true; |
| 129 | } |
| 130 | if (object instanceof Map) { |
| 131 | Map<?, ?> map = (Map<?, ?>) object; |
| 132 | if (size() != map.size()) { |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | try { |
| 137 | for (Entry<K, V> entry : entrySet()) { |
| 138 | K key = entry.getKey(); |
| 139 | V mine = entry.getValue(); |
| 140 | Object theirs = map.get(key); |
| 141 | if (mine == null) { |
| 142 | if (theirs != null || !map.containsKey(key)) { |
| 143 | return false; |
| 144 | } |
| 145 | } else if (!mine.equals(theirs)) { |
| 146 | return false; |
| 147 | } |
| 148 | } |
| 149 | } catch (NullPointerException ignored) { |
| 150 | return false; |
| 151 | } catch (ClassCastException ignored) { |
| 152 | return false; |
| 153 | } |
| 154 | return true; |
| 155 | } |
| 156 | return false; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Returns the value of the mapping with the specified key. |