MapEntryArrayValues extends MapEntry<K, V[]> { @Override @SuppressWarnings("unchecked") public boolean equals(Object o) { if (o != null && o instanceof Map.Entry) { Map.Entry<K, V[]> entry = (Map.Entry<K, V[]>) o; if (this.getKey() == null ? entry.getKey() == null : this .getKey().equals(entry.getKey())) { V[] values = getValue(); V[] otherValues = entry.getValue(); if (values != null) { if (otherValues != null) { if (values.length == otherValues.length) { boolean same = true; for (int i = 0; i < values.length && same; i++) { same = values[i] == null ? otherValues[i] == null : values[i].equals(otherValues[i]); } return same; } } else { return false; } } else { return otherValues == null; } } } return false; } MapEntryArrayValues(K key, V[] value, boolean modifiable); @Override int hashCode(); @Override @SuppressWarnings("unchecked") boolean equals(Object o);  }
@Test public void testEqualsObject() { MapEntryArrayValues<String, String> entry = new MapEntryArrayValues<String, String>( "key", new String[] { "value1", "value2" }, false); assertFalse(entry.equals(null)); assertFalse(entry.equals("whatever")); MapEntryArrayValues<String, String> entry2 = new MapEntryArrayValues<String, String>( "key", new String[] { "value1", "value2" }, false); assertTrue(entry.equals(entry2)); entry2 = new MapEntryArrayValues<String, String>( "key", null, false); assertFalse(entry.equals(entry2)); entry2 = new MapEntryArrayValues<String, String>("key2", new String[] { "value1", "value2" }, false); assertFalse(entry.equals(entry2)); entry2 = new MapEntryArrayValues<String, String>("key", new String[] { "value1", "value3" }, false); assertFalse(entry.equals(entry2)); entry = new MapEntryArrayValues<String, String>(null, new String[] { "value1", "value2" }, false); entry2 = new MapEntryArrayValues<String, String>(null, new String[] { "value1", "value2" }, false); assertTrue(entry.equals(entry2)); entry = new MapEntryArrayValues<String, String>("key", null, false); entry2 = new MapEntryArrayValues<String, String>("key", null, false); assertTrue(entry.equals(entry2)); entry2 = new MapEntryArrayValues<String, String>("key", new String[] { "value1", "value2" }, false); assertFalse(entry.equals(entry2)); entry = new MapEntryArrayValues<String, String>(null, new String[] { null, "value2" }, false); entry2 = new MapEntryArrayValues<String, String>(null, new String[] { null, "value2" }, false); assertTrue(entry.equals(entry2)); entry2 = new MapEntryArrayValues<String, String>(null, new String[] { "value1", "value2" }, false); assertFalse(entry.equals(entry2)); }