/** * This function is used to re-run the analyser, and re-create the rows corresponding the its * results. */ private void refreshReviewTable() { reviewPanel.removeAll(); rows.clear(); GridBagLayout gbl = new GridBagLayout(); reviewPanel.setLayout(gbl); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridy = 0; try { Map<String, Long> sums = analyser.processLogFile(config.getLogFilename(), fromDate.getDate(), toDate.getDate()); for (Entry<String, Long> entry : sums.entrySet()) { String project = entry.getKey(); double hours = 1.0 * entry.getValue() / (1000 * 3600); addRow(gbl, gbc, project, hours); } for (String project : main.getProjectsTree().getTopLevelProjects()) if (!rows.containsKey(project)) addRow(gbl, gbc, project, 0); gbc.insets = new Insets(10, 0, 0, 0); addLeftLabel(gbl, gbc, "TOTAL"); gbc.gridx = 1; gbc.weightx = 1; totalLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 3)); gbl.setConstraints(totalLabel, gbc); reviewPanel.add(totalLabel); gbc.weightx = 0; addRightLabel(gbl, gbc); } catch (IOException e) { e.printStackTrace(); } recomputeTotal(); pack(); }
public static String buildContent( TestFile<String> file, String mediaType, List<Entry<Integer, Integer>> ranges, String boundary) { final StringBuilder content = new StringBuilder(); for (Entry<Integer, Integer> range : ranges) { content.append("\n"); content.append("--").append(boundary).append("\n"); content.append("Content-Type: ").append(mediaType).append("\n"); content .append("Content-Range: bytes ") .append(range.getKey()) .append("-") .append(range.getValue()) .append("/") .append(file.getSize()) .append("\n"); content.append("\n"); content.append(file.getContent().substring(range.getKey(), range.getValue() + 1)); } content.append("\n"); content.append("--").append(boundary).append("--").append("\n"); return content.toString(); }
/** @see java.util.AbstractMap#remove(java.lang.Object) */ @SuppressWarnings("unchecked") public V remove(Object key) { K buscado; try { buscado = (K) key; } catch (ClassCastException e1) { return null; } Iterator<Entry<K, V>> i = entrySet().iterator(); Entry<K, V> correctEntry = null; if (key == null) { while (correctEntry == null && i.hasNext()) { Entry<K, V> e = i.next(); if (discriminadorKeys.areEquals(e.getKey(), null)) correctEntry = e; } } else { while (correctEntry == null && i.hasNext()) { Entry<K, V> e = i.next(); if (discriminadorKeys.areEquals(buscado, e.getKey())) correctEntry = e; } } V oldValue = null; if (correctEntry != null) { oldValue = correctEntry.getValue(); i.remove(); } return oldValue; }
@Override public boolean equals(final Object o) { if (o == this) { return true; } if (o == null) { return false; } if (o instanceof ImmutableOffsetMap) { final ImmutableOffsetMap<?, ?> om = (ImmutableOffsetMap<?, ?>) o; if (newKeys.isEmpty() && offsets == om.offsets() && Arrays.deepEquals(objects, om.objects())) { return true; } } else if (o instanceof MutableOffsetMap) { final MutableOffsetMap<?, ?> om = (MutableOffsetMap<?, ?>) o; if (offsets == om.offsets && Arrays.deepEquals(objects, om.objects) && newKeys.equals(om.newKeys)) { return true; } } else if (o instanceof Map) { final Map<?, ?> om = (Map<?, ?>) o; // Size and key sets have to match if (size() != om.size() || !keySet().equals(om.keySet())) { return false; } try { // Ensure all newKeys are present. Note newKeys is guaranteed to // not contain null value. for (Entry<K, V> e : newKeys.entrySet()) { if (!e.getValue().equals(om.get(e.getKey()))) { return false; } } // Ensure all objects are present for (Entry<K, Integer> e : offsets.entrySet()) { final Object obj = objects[e.getValue()]; if (!NO_VALUE.equals(obj)) { final V v = objectToValue(e.getKey(), obj); if (!v.equals(om.get(e.getKey()))) { return false; } } } } catch (ClassCastException e) { // Can be thrown by om.get() and indicate we have incompatible key types return false; } return true; } return false; }
/** * Called to return the entry list index given the index, the hash, and the key. * * @param index the entry data index of the key. * @param hash the hash code of the key. * @param key the key. * @return the entry list index. */ protected int entryIndexForKey(int index, int hash, Object key) { if (useEqualsForKey() && key != null) { BasicEList<Entry<K, V>> eList = entryData[index]; if (eList != null) { Object[] entries = eList.data; int size = eList.size; for (int j = 0; j < size; ++j) { @SuppressWarnings("unchecked") Entry<K, V> entry = (Entry<K, V>) entries[j]; if (entry.getHash() == hash && key.equals(entry.getKey())) { return j; } } } } else { BasicEList<Entry<K, V>> eList = entryData[index]; if (eList != null) { Object[] entries = eList.data; int size = eList.size; for (int j = 0; j < size; ++j) { @SuppressWarnings("unchecked") Entry<K, V> entry = (Entry<K, V>) entries[j]; if (entry.getKey() == key) { return j; } } } } return -1; }
@SuppressWarnings("unchecked") Boolean visionallRemoveImpl(Object o) { if (!(o instanceof Entry<?, ?>)) { return false; } RootData<K, V> rootData = this.<RootData<K, V>>getRootData(); if (rootData.isLoaded()) { return null; } if (!rootData.isVisionallyReadable(QueuedOperationType.DETACH)) { return null; } if (rootData.isLoading()) { throw new IllegalStateException( LAZY_COMMON_RESOURCE.get().visionOperationWhenDataIsBeingLoaded()); } Entry<K, V> e = (Entry<K, V>) o; Ref<V> ref = rootData.visionallyRead(e.getKey(), null); if (ref != null) { if (ref.get() == null) { return false; } if (!rootData.valueUnifiedComparator().equals(ref.get(), e.getValue())) { return false; } rootData.visinallyRemove(e.getKey(), ref.get()); return true; } return null; }
@Override public Map<K, V> getAll(Set<K> keys) { Set<Data> keySet = new HashSet(keys.size()); Map<K, V> result = new HashMap<K, V>(); for (Object key : keys) { keySet.add(toData(key)); } if (nearCache != null) { final Iterator<Data> iterator = keySet.iterator(); while (iterator.hasNext()) { Data key = iterator.next(); Object cached = nearCache.get(key); if (cached != null && !ClientNearCache.NULL_OBJECT.equals(cached)) { result.put((K) toObject(key), (V) cached); iterator.remove(); } } } if (keys.isEmpty()) { return result; } MapGetAllRequest request = new MapGetAllRequest(name, keySet); MapEntrySet mapEntrySet = invoke(request); Set<Entry<Data, Data>> entrySet = mapEntrySet.getEntrySet(); for (Entry<Data, Data> dataEntry : entrySet) { final V value = (V) toObject(dataEntry.getValue()); final K key = (K) toObject(dataEntry.getKey()); result.put(key, value); if (nearCache != null) { nearCache.put(dataEntry.getKey(), value); } } return result; }
@Override public Map<String, String> getAllPropertiesString() { Map<String, String> ret = new HashMap<String, String>(); for (Entry<String, Object> e : this.entrySet()) { if (!Attribute.isFinalAttribute(e.getKey())) { ret.put(e.getKey(), Util.toStringAttrValue(e.getValue())); } } return ret; }
@Override public void putAll(Map<? extends K, ? extends V> m) { int m_size = m.size(); if (m_size == 0) return; int max_new_size = m_size + size(); if (array_keys == null && hashmap == null && max_new_size == 1) { Entry<? extends K, ? extends V> e = getFirstEntry(m); K key = e.getKey(); if (key == null) throw new NullPointerException(NULL_KEY); singleton_key = key; singleton_value = e.getValue(); return; } if (array_keys == null && hashmap == null && max_new_size <= ARRAY_SIZE) { if (singleton_key != null) convertSingletonToArray(); else { array_keys = new Object[ARRAY_SIZE]; array_values = new Object[ARRAY_SIZE]; number_of_used_array_entries = 0; } } if (array_keys != null && max_new_size <= ARRAY_SIZE) { int next = 0; loop: for (Entry<? extends K, ? extends V> f : m.entrySet()) { K key = f.getKey(); if (key == null) throw new NullPointerException(NULL_KEY); V value = f.getValue(); for (int i = 0; i < ARRAY_SIZE; i++) if (array_keys[i] != null && array_keys[i].equals(key)) { array_values[i] = value; continue loop; } while (array_keys[next] != null) next++; array_keys[next] = key; array_values[next++] = value; number_of_used_array_entries++; } return; } for (K k : m.keySet()) if (k == null) throw new NullPointerException(NULL_KEY); if (array_keys != null) { convertArrayToHashMap(); } if (hashmap == null) { hashmap = new HashMap<>(ARRAY_SIZE + max_new_size); } if (singleton_key != null) { hashmap.put(singleton_key, singleton_value); singleton_key = null; singleton_value = null; } hashmap.putAll(m); }
/** * Establece el orden de dos entries en funcion de sus keys * * @param first Primera key a comparar * @param second Segunda key a comparar * @return Negativo si la primera entry antecede a la segunda * @see ar.com.fdvs.dgarcia.lang.identificators.Identificator#compare(Object, Object) */ public int compare(Entry<K, V> first, Entry<K, V> second) { K firstKey = null; K secondKey = null; if (first != null) { firstKey = first.getKey(); } if (second != null) { secondKey = second.getKey(); } return this.discriminadorKeys.compare(firstKey, secondKey); }
/** * Considera iguales dos entries cuyas keys sean iguales * * @param first Primera key a comparar * @param second Segunda key a comparar * @return true si son consideradas iguales * @see ar.com.fdvs.dgarcia.lang.identificators.Identificator#areEquals(Object, Object) */ public boolean areEquals(Entry<K, V> first, Entry<K, V> second) { K firstKey = null; K secondKey = null; if (first != null) { firstKey = first.getKey(); } if (second != null) { secondKey = second.getKey(); } return this.discriminadorKeys.areEquals(firstKey, secondKey); }
@Override public boolean hasNext() { if (ahead) return true; while (targetIterator.hasNext()) { next = targetIterator.next(); if ((from != null) && (cmp.compare(next.getKey(), from) < 0)) continue; if ((to != null) && (cmp.compare(next.getKey(), to) >= 0)) break; ahead = true; return true; } return false; }
/** * Generates a JavaScript command to update the JavaScript agent's parameter names. Follows this * format: <code>agent.updateParameterNames({serial: 'XXXX', parameter: 'YYYY'});</code> * * @return A JavaScript Command. */ public String generateCommand(String type, Map<String, ?> props) { StringBuilder buff = new StringBuilder(agentName); buff.append(".update").append(type).append("({"); for (Entry<String, ?> entry : props.entrySet()) { if (entry.getValue() instanceof String) { buff.append(entry.getKey()).append(": '").append(entry.getValue()).append("',"); } else { buff.append(entry.getKey()).append(": ").append(entry.getValue()).append(","); } } buff.deleteCharAt(buff.length() - 1); buff.append("});"); return buff.toString(); }
/** * {@inheritDoc} * * <p>This implementation iterates over <tt>entrySet()</tt> searching for an entry with the * specified key. If such an entry is found, the entry's value is returned. If the iteration * terminates without finding such an entry, <tt>null</tt> is returned. Note that this * implementation requires linear time in the size of the map; many implementations will override * this method. * * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ public V get(Object key) { Iterator<Entry<K, V>> i = entrySet().iterator(); if (key == null) { while (i.hasNext()) { Entry<K, V> e = i.next(); if (e.getKey() == null) return e.getValue(); } } else { while (i.hasNext()) { Entry<K, V> e = i.next(); if (key.equals(e.getKey())) return e.getValue(); } } return null; }
@Override public Map<String, Set<String>> unmarshal(List<StringSetMapAdapter.Entry> entryList) throws Exception { Map<String, Set<String>> map = new HashMap<String, Set<String>>(); for (Entry entry : entryList) { if (map.containsKey(entry.getKey())) { map.get(entry.getKey()).add(entry.getValue()); } else { Set<String> valueSet = new HashSet<String>(); valueSet.add(entry.getValue()); map.put(entry.getKey(), valueSet); } } return map; }
/** * {@inheritDoc} * * <p>This implementation iterates over <tt>entrySet()</tt> searching for an entry with the * specified key. If such an entry is found, <tt>true</tt> is returned. If the iteration * terminates without finding such an entry, <tt>false</tt> is returned. Note that this * implementation requires linear time in the size of the map; many implementations will override * this method. * * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ public boolean containsKey(Object key) { Iterator<Map.Entry<K, V>> i = entrySet().iterator(); if (key == null) { while (i.hasNext()) { Entry<K, V> e = i.next(); if (e.getKey() == null) return true; } } else { while (i.hasNext()) { Entry<K, V> e = i.next(); if (key.equals(e.getKey())) return true; } } return false; }
/** * Compares the specified object with this map for equality. Returns <tt>true</tt> if the given * object is also a map and the two maps represent the same mappings. More formally, two maps * <tt>m1</tt> and <tt>m2</tt> represent the same mappings if * <tt>m1.entrySet().equals(m2.entrySet())</tt>. This ensures that the <tt>equals</tt> method * works properly across different implementations of the <tt>Map</tt> interface. * * <p>This implementation first checks if the specified object is this map; if so it returns * <tt>true</tt>. Then, it checks if the specified object is a map whose size is identical to the * size of this map; if not, it returns <tt>false</tt>. If so, it iterates over this map's * <tt>entrySet</tt> collection, and checks that the specified map contains each mapping that this * map contains. If the specified map fails to contain such a mapping, <tt>false</tt> is returned. * If the iteration completes, <tt>true</tt> is returned. * * @param o object to be compared for equality with this map * @return <tt>true</tt> if the specified object is equal to this map */ public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof Map)) return false; Map<K, V> m = (Map<K, V>) o; if (m.size() != size()) return false; try { Iterator<Entry<K, V>> i = entrySet().iterator(); while (i.hasNext()) { Entry<K, V> e = i.next(); K key = e.getKey(); V value = e.getValue(); if (value == null) { if (!(m.get(key) == null && m.containsKey(key))) return false; } else { if (!value.equals(m.get(key))) return false; } } } catch (ClassCastException unused) { return false; } catch (NullPointerException unused) { return false; } return true; }
/** * Copies the key/value mappings in <tt>map</tt> into this map. Note that this will be a * <b>deep</b> copy, as storage is by primitive value. * * @param map a <code>Map</code> value */ public void putAll(Map<? extends Character, ? extends Double> map) { Iterator<? extends Entry<? extends Character, ? extends Double>> it = map.entrySet().iterator(); for (int i = map.size(); i-- > 0; ) { Entry<? extends Character, ? extends Double> e = it.next(); this.put(e.getKey(), e.getValue()); } }
/** @see java.util.AbstractMap#equals(java.lang.Object) */ @SuppressWarnings("unchecked") public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof Map)) return false; Map<K, V> t = (Map<K, V>) o; if (t.size() != size()) return false; try { Iterator<Entry<K, V>> i = entrySet().iterator(); while (i.hasNext()) { Entry<K, V> e = i.next(); K key = e.getKey(); V value = e.getValue(); if (value == null) { if (!(t.get(key) == null && t.containsKey(key))) return false; } else { if (!discriminadorValues.areEquals(value, t.get(key))) return false; } } } catch (ClassCastException unused) { return false; } catch (NullPointerException unused) { return false; } return true; }
@SuppressWarnings("unchecked") @Override public boolean containsAll(Collection<?> c, ElementMatcher<? super Entry<K, V>> matcher) { this.requiredEnabled(); RootData<K, V> rootData = this.getRootData(); if (matcher == null) { UnifiedComparator<? super V> valueUnifiedComparator = rootData.valueUnifiedComparator(); for (Object o : c) { if (!(o instanceof Entry<?, ?>)) { return false; } Entry<K, V> e = (Entry<K, V>) o; Ref<V> ref = rootData.visionallyRead(e.getKey(), null); if (ref == null) { rootData.load(); return this.getBase().containsAll(c, matcher); } if (ref.get() == null) { return false; } if (!valueUnifiedComparator.equals(ref.get(), e.getValue())) { return false; } } return true; } rootData.load(); return this.getBase().containsAll(c, matcher); }
/** * Copies all of the mappings from the specified map to this map (optional operation). These * mappings will replace any mappings that this map had for any of the keys currently in the * specified map. * * <p>This implementation iterates over the specified map's <tt>entrySet()</tt> collection, and * calls this map's <tt>put</tt> operation once for each entry returned by the iteration. * * <p>Note that this implementation throws an <tt>UnsupportedOperationException</tt> if this map * does not support the <tt>put</tt> operation and the specified map is nonempty. * * @param t mappings to be stored in this map. * @throws UnsupportedOperationException if the <tt>putAll</tt> operation is not supported by this * map. * @throws ClassCastException if the class of a key or value in the specified map prevents it from * being stored in this map. * @throws IllegalArgumentException if some aspect of a key or value in the specified map prevents * it from being stored in this map. * @throws NullPointerException the specified map is <tt>null</tt>, or if this map does not permit * <tt>null</tt> keys or values, and the specified map contains <tt>null</tt> keys or values. */ public void putAll(Map t) { Iterator i = t.entrySet().iterator(); while (i.hasNext()) { Entry e = (Entry) i.next(); put(e.getKey(), e.getValue()); } }
/** * Returns an immutable map containing the same entries as {@code map}. If {@code map} somehow * contains entries with duplicate keys (for example, if it is a {@code SortedMap} whose * comparator is not <i>consistent with equals</i>), the results of this method are undefined. * * <p>Despite the method name, this method attempts to avoid actually copying the data when it is * safe to do so. The exact circumstances under which a copy will or will not be performed are * undocumented and subject to change. * * @throws NullPointerException if any key or value in {@code map} is null */ public static <K, V> ImmutableMap<K, V> copyOf(Map<? extends K, ? extends V> map) { if ((map instanceof ImmutableMap) && !(map instanceof ImmutableSortedMap)) { // TODO(user): Make ImmutableMap.copyOf(immutableBiMap) call copyOf() // on the ImmutableMap delegate(), rather than the bimap itself @SuppressWarnings("unchecked") // safe since map is not writable ImmutableMap<K, V> kvMap = (ImmutableMap<K, V>) map; if (!kvMap.isPartialView()) { return kvMap; } } else if (map instanceof EnumMap) { return copyOfEnumMapUnsafe(map); } Entry<?, ?>[] entries = map.entrySet().toArray(EMPTY_ENTRY_ARRAY); switch (entries.length) { case 0: return of(); case 1: @SuppressWarnings("unchecked") // all entries will be Entry<K, V>'s Entry<K, V> onlyEntry = (Entry<K, V>) entries[0]; return of(onlyEntry.getKey(), onlyEntry.getValue()); default: return new RegularImmutableMap<K, V>(entries); } }
@Override public void putAll(Map<? extends K, ? extends V> m) { if (m.isEmpty()) { return; } if (isMap()) { ((Map) _keys).putAll(m); } else { if (m.size() < 10) { for (Entry<? extends K, ? extends V> entry : m.entrySet()) { put(entry.getKey(), entry.getValue()); } } else { Map map = new HashMap(); if (isList()) { ArrayList keyList = (ArrayList) _keys; ArrayList valueList = (ArrayList) _values; for (int i = 0; i < keyList.size(); i++) { map.put(keyList.get(i), valueList.get(i)); } } else if (_keys != EMPTY_KEY) { map.put(_keys, _values); } map.putAll(m); _keys = map; _values = null; trimToSize(); } } }
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException { objectOutputStream.defaultWriteObject(); if (entryData == null) { objectOutputStream.writeInt(0); } else { // Write the capacity and the size. // objectOutputStream.writeInt(entryData.length); objectOutputStream.writeInt(size); // Write all the entryData; there will be size of them. // for (int i = 0; i < entryData.length; ++i) { BasicEList<Entry<K, V>> eList = entryData[i]; if (eList != null) { Object[] entries = eList.data; int size = eList.size; for (int j = 0; j < size; ++j) { @SuppressWarnings("unchecked") Entry<K, V> entry = (Entry<K, V>) entries[j]; objectOutputStream.writeObject(entry.getKey()); objectOutputStream.writeObject(entry.getValue()); } } } } }
/** * Returns the string representation of this {@code Hashtable}. * * @return the string representation of this {@code Hashtable}. */ @Override public synchronized String toString() { StringBuilder result = new StringBuilder(CHARS_PER_ENTRY * size); result.append('{'); Iterator<Entry<K, V>> i = entrySet().iterator(); boolean hasMore = i.hasNext(); while (hasMore) { Entry<K, V> entry = i.next(); K key = entry.getKey(); result.append(key == this ? "(this Map)" : key.toString()); result.append('='); V value = entry.getValue(); result.append(value == this ? "(this Map)" : value.toString()); if (hasMore = i.hasNext()) { result.append(", "); } } result.append('}'); return result.toString(); }
@Nullable public InstanceFactory findInstanceFactory(@Nonnull Type mockedType) { InstanceFactory instanceFactory = mockedTypesAndInstances.get(mockedType); if (instanceFactory != null) { return instanceFactory; } Class<?> mockedClass = getClassType(mockedType); //noinspection ReuseOfLocalVariable instanceFactory = mockedTypesAndInstances.get(mockedClass); if (instanceFactory != null) { return instanceFactory; } boolean abstractType = mockedClass.isInterface() || isAbstract(mockedClass.getModifiers()); for (Entry<Type, InstanceFactory> entry : mockedTypesAndInstances.entrySet()) { Type registeredMockedType = entry.getKey(); Class<?> registeredMockedClass = getClassType(registeredMockedType); if (abstractType) { registeredMockedClass = getMockedClassOrInterfaceType(registeredMockedClass); } if (mockedClass.isAssignableFrom(registeredMockedClass)) { instanceFactory = entry.getValue(); break; } } return instanceFactory; }
/** * {@inheritDoc} * * <p>This implementation first checks the structure of {@code object}. If it is not a map or of a * different size, this returns false. Otherwise it iterates its own entry set, looking up each * entry's key in {@code object}. If any value does not equal the other map's value for the same * key, this returns false. Otherwise it returns true. */ @Override public boolean equals(Object object) { if (this == object) { return true; } if (object instanceof Map) { Map<?, ?> map = (Map<?, ?>) object; if (size() != map.size()) { return false; } try { for (Entry<K, V> entry : entrySet()) { K key = entry.getKey(); V mine = entry.getValue(); Object theirs = map.get(key); if (mine == null) { if (theirs != null || !map.containsKey(key)) { return false; } } else if (!mine.equals(theirs)) { return false; } } } catch (NullPointerException ignored) { return false; } catch (ClassCastException ignored) { return false; } return true; } return false; }
/** Special version of remove for EntrySet. */ final Entry<T> removeMapping(Object o) { if (!(o instanceof Entry)) { return null; } Entry<T> entry = (Entry<T>) o; int key = entry.getKey(); Entry<T> prev = getEntry(key); Entry<T> e = prev; while (e != null) { Entry<T> next = e.next; if (e.hash == key && e.equals(entry)) { count--; if (prev == e) { table[getIndex(key)] = next; } else { prev.next = next; } return e; } prev = e; e = next; } return e; }
@SuppressWarnings("unchecked") public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof Map)) return false; Map<K, V> m = (Map<K, V>) o; if (m.size() != size()) return false; try { for (Entry<K, V> e : entrySet()) { K key = e.getKey(); V value = e.getValue(); if (value == null) { if (!(m.get(key) == null && m.containsKey(key))) return false; } else { if (!valueEq.equals(value, m.get(key))) return false; } } } catch (ClassCastException unused) { return false; } catch (NullPointerException unused) { return false; } return true; }
/** * Compares the specified object with this map for equality. Returns <tt>true</tt> if the given * object is also a map and the two maps represent the same mappings. More formally, two maps * <tt>t1</tt> and <tt>t2</tt> represent the same mappings if * <tt>t1.keySet().equals(t2.keySet())</tt> and for every key <tt>k</tt> in <tt>t1.keySet()</tt>, * <tt> (t1.get(k)==null ? t2.get(k)==null : t1.get(k).equals(t2.get(k))) </tt>. This ensures that * the <tt>equals</tt> method works properly across different implementations of the map * interface. * * <p>This implementation first checks if the specified object is this map; if so it returns * <tt>true</tt>. Then, it checks if the specified object is a map whose size is identical to the * size of this set; if not, it it returns <tt>false</tt>. If so, it iterates over this map's * <tt>entrySet</tt> collection, and checks that the specified map contains each mapping that this * map contains. If the specified map fails to contain such a mapping, <tt>false</tt> is returned. * If the iteration completes, <tt>true</tt> is returned. * * @param o object to be compared for equality with this map. * @return <tt>true</tt> if the specified object is equal to this map. */ public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof Map)) return false; Map t = (Map) o; if (t.size() != size()) return false; try { Iterator i = entrySet().iterator(); while (i.hasNext()) { Entry e = (Entry) i.next(); Object key = e.getKey(); Object value = e.getValue(); if (value == null) { if (!(t.get(key) == null && t.containsKey(key))) return false; } else { if (!value.equals(t.get(key))) return false; } } } catch (ClassCastException unused) { return false; } catch (NullPointerException unused) { return false; } return true; }