1
zj
2025-05-25 370c0e6d54be9222fcaa416fdd605f09e3c49e8a
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package db.map;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
 
public class CacheMap<K, V> {
    /**    
     * map cache
     */
    private final Map<K, V> map = Collections.synchronizedMap(new ConcurrentHashMap<K, V>());
 
    // private final Map<K, V> map = new ConcurrentHashMap<K, V>();
 
    /**    
     * Associates the specified value with the specified key in this map
     * 
     * @param key key with which the specified value is to be associated
     * @param value value to be associated with the specified key
     */
    public void put(K key, V value) {
        map.put(key, value);
    }
 
    /**    
     * Removes the mapping for a key from this map if it is present
     * 
     * @param key key whose mapping is to be removed from the map
     */
    public void remove(K key) {
        map.remove(key);
    }
 
    /**    
     * Returns the number of key-value mappings in this map.
     * 
     * @return the size of map
     */
    public int size() {
        return map.size();
    }
 
    /**    
     * Removes all of the mappings from this map.
     */
    public void clear() {
        map.clear();
    }
 
    /**    
     * Returns a {@link Collection} view of the values contained in this map.
     * 
     * @return  a collection view of the values contained in this map
     */
    public Collection<V> values() {
        return map.values();
    }
 
    /**    
     * Copy a the values contained in this map to a list.
     * 
     * @return a list of the values contained in this map
     */
    public List<V> valuesCopy() {
        Collection<V> values = map.values();
 
        return new ArrayList<V>(values);
    }
 
    /**    
     * Returns the value to which the specified key is mapped
     * 
     * @param key the key whose associated value is to be returned
     * @return the value to which the specified key is mapped, or
     *         {@code null} if this map contains no mapping for the key
     */
    public V get(K key) {
        return map.get(key);
    }
 
    /**    
     * Returns <tt>true</tt> if this map contains a mapping for the specified
     * key.
     * @param key key whose presence in this map is to be tested
     * @return <tt>true</tt> if this map contains a mapping for the specified
     *         key
     */
    public boolean containsKey(K key) {
        return map.containsKey(key);
    }
}