| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
package com.ibm.icu.impl; |
| 9 |
|
|
| 10 |
|
import java.lang.ref.Reference; |
| 11 |
|
import java.lang.ref.SoftReference; |
| 12 |
|
import java.lang.ref.WeakReference; |
| 13 |
|
import java.util.Collections; |
| 14 |
|
import java.util.HashMap; |
| 15 |
|
import java.util.Map; |
| 16 |
|
|
|
|
|
| 90.7% |
Uncovered Elements: 4 (43) |
Complexity: 13 |
Complexity Density: 0.57 |
|
| 17 |
|
public class SimpleCache implements ICUCache { |
| 18 |
|
private static final int DEFAULT_CAPACITY = 16; |
| 19 |
|
|
| 20 |
|
private Reference cacheRef = null; |
| 21 |
|
private int type = ICUCache.SOFT; |
| 22 |
|
private int capacity = DEFAULT_CAPACITY; |
| 23 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 24 |
9
|
public SimpleCache() {... |
| 25 |
|
} |
| 26 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 27 |
0
|
public SimpleCache(int cacheType) {... |
| 28 |
0
|
this(cacheType, DEFAULT_CAPACITY); |
| 29 |
|
} |
| 30 |
|
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 31 |
52749
|
public SimpleCache(int cacheType, int initialCapacity) {... |
| 32 |
52749
|
if (cacheType == ICUCache.WEAK) { |
| 33 |
52749
|
type = cacheType; |
| 34 |
|
} |
| 35 |
52749
|
if (initialCapacity > 0) { |
| 36 |
52749
|
capacity = initialCapacity; |
| 37 |
|
} |
| 38 |
|
} |
| 39 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 40 |
10852056
|
public Object get(Object key) {... |
| 41 |
10852056
|
Reference ref = cacheRef; |
| 42 |
10852056
|
if (ref != null) { |
| 43 |
10310966
|
Map map = (Map)ref.get(); |
| 44 |
10310966
|
if (map != null) { |
| 45 |
10040261
|
return map.get(key); |
| 46 |
|
} |
| 47 |
|
} |
| 48 |
811795
|
return null; |
| 49 |
|
} |
| 50 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 51 |
592634
|
public void put(Object key, Object value) {... |
| 52 |
592634
|
Reference ref = cacheRef; |
| 53 |
592634
|
Map map = null; |
| 54 |
592634
|
if (ref != null) { |
| 55 |
542978
|
map = (Map)ref.get(); |
| 56 |
|
} |
| 57 |
592634
|
if (map == null) { |
| 58 |
52037
|
map = Collections.synchronizedMap(new HashMap(capacity)); |
| 59 |
52037
|
if (type == ICUCache.WEAK) { |
| 60 |
51972
|
ref = new WeakReference(map); |
| 61 |
|
} else { |
| 62 |
65
|
ref = new SoftReference(map); |
| 63 |
|
} |
| 64 |
52037
|
cacheRef = ref; |
| 65 |
|
} |
| 66 |
592634
|
map.put(key, value); |
| 67 |
|
} |
| 68 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 69 |
35
|
public void clear() {... |
| 70 |
35
|
cacheRef = null; |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
} |