Clover Coverage Report
Coverage timestamp: Fri Jun 27 2008 17:20:33 EDT
../../../../img/srcFileCovDistChart9.png 50% of files have more coverage
23   73   13   3.83
14   56   0.57   6
6     2.17  
1    
 
  SimpleCache       Line # 17 23 13 90.7% 0.90697676
 
No Tests
 
1    /*
2    ****************************************************************************
3    * Copyright (c) 2007-2008 International Business Machines Corporation and *
4    * others. All rights reserved. *
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   
 
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   
 
24  9 toggle public SimpleCache() {
25    }
26   
 
27  0 toggle public SimpleCache(int cacheType) {
28  0 this(cacheType, DEFAULT_CAPACITY);
29    }
30   
 
31  52749 toggle 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   
 
40  10852056 toggle 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   
 
51  592634 toggle 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   
 
69  35 toggle public void clear() {
70  35 cacheRef = null;
71    }
72   
73    }