1 package edu.uci.ics.jung.algorithms.util;
3 import java.util.HashMap;
7 * An simple minimal implementation of <code>Map.Entry</code>.
9 * @param <K> the key type
10 * @param <V> the value type
12 public class BasicMapEntry<K,V> implements Map.Entry<K,V> {
19 public BasicMapEntry(K k, V v) {
32 public V setValue(V newValue) {
38 @SuppressWarnings("unchecked")
40 public boolean equals(Object o) {
41 if (!(o instanceof Map.Entry))
43 Map.Entry e = (Map.Entry)o;
45 Object k2 = e.getKey();
46 if (k1 == k2 || (k1 != null && k1.equals(k2))) {
47 Object v1 = getValue();
48 Object v2 = e.getValue();
49 if (v1 == v2 || (v1 != null && v1.equals(v2)))
56 public int hashCode() {
57 return (key==null ? 0 : key.hashCode()) ^
58 (value==null ? 0 : value.hashCode());
62 public String toString() {
63 return getKey() + "=" + getValue();
67 * This method is invoked whenever the value in an entry is
68 * overwritten by an invocation of put(k,v) for a key k that's already
71 void recordAccess(HashMap<K,V> m) {
75 * This method is invoked whenever the entry is
76 * removed from the table.
78 void recordRemoval(HashMap<K,V> m) {