Clover Coverage Report - Subsonic-Android Coverage Report
Coverage timestamp: ven dic 19 2014 17:57:13 EST
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
7   55   6   1,4
2   25   0,86   5
5     1,2  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  TimeLimitedCache       Line # 28 7 6 100% 1.0
 
No Tests
 
1    /*
2    This file is part of Subsonic.
3   
4    Subsonic is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8   
9    Subsonic is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12    GNU General Public License for more details.
13   
14    You should have received a copy of the GNU General Public License
15    along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
16   
17    Copyright 2009 (C) Sindre Mehus
18    */
19    package net.sourceforge.subsonic.androidapp.util;
20   
21    import java.lang.ref.SoftReference;
22    import java.util.concurrent.TimeUnit;
23   
24    /**
25    * @author Sindre Mehus
26    * @version $Id$
27    */
 
28    public class TimeLimitedCache<T> {
29   
30    private SoftReference<T> value;
31    private final long ttlMillis;
32    private long expires;
33   
 
34  9 toggle public TimeLimitedCache(long ttl, TimeUnit timeUnit) {
35  9 this.ttlMillis = TimeUnit.MILLISECONDS.convert(ttl, timeUnit);
36    }
37   
 
38  22 toggle public T get() {
39  22 return System.currentTimeMillis() < expires ? value.get() : null;
40    }
41   
 
42  12 toggle public void set(T value) {
43  12 set(value, ttlMillis, TimeUnit.MILLISECONDS);
44    }
45   
 
46  13 toggle public void set(T value, long ttl, TimeUnit timeUnit) {
47  13 this.value = new SoftReference<T>(value);
48  13 expires = System.currentTimeMillis() + timeUnit.toMillis(ttl);
49    }
50   
 
51  6 toggle public void clear() {
52  6 expires = 0L;
53  6 value = null;
54    }
55    }