File: BasicMapEntry.java

package info (click to toggle)
geogebra 4.0.34.0%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 23,680 kB
  • sloc: java: 221,001; xml: 786; sh: 116; makefile: 26
file content (80 lines) | stat: -rw-r--r-- 1,794 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package edu.uci.ics.jung.algorithms.util;

import java.util.HashMap;
import java.util.Map;

/**
 * An simple minimal implementation of <code>Map.Entry</code>.
 *
 * @param <K> the key type
 * @param <V> the value type
 */
public class BasicMapEntry<K,V> implements Map.Entry<K,V> {
    final K key;
    V value;
    
    /**
     * Create new entry.
     */
    public BasicMapEntry(K k, V v) {
        value = v;
        key = k;
    }

    public K getKey() {
        return key;
    }

    public V getValue() {
        return value;
    }

    public V setValue(V newValue) {
    V oldValue = value;
        value = newValue;
        return oldValue;
    }

    @SuppressWarnings("unchecked")
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Map.Entry))
            return false;
        Map.Entry e = (Map.Entry)o;
        Object k1 = getKey();
        Object k2 = e.getKey();
        if (k1 == k2 || (k1 != null && k1.equals(k2))) {
            Object v1 = getValue();
            Object v2 = e.getValue();
            if (v1 == v2 || (v1 != null && v1.equals(v2))) 
                return true;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return (key==null ? 0 : key.hashCode()) ^
               (value==null   ? 0 : value.hashCode());
    }

    @Override
    public String toString() {
        return getKey() + "=" + getValue();
    }

    /**
     * This method is invoked whenever the value in an entry is
     * overwritten by an invocation of put(k,v) for a key k that's already
     * in the HashMap.
     */
    void recordAccess(HashMap<K,V> m) {
    }

    /**
     * This method is invoked whenever the entry is
     * removed from the table.
     */
    void recordRemoval(HashMap<K,V> m) {
    }
}