/[projects]/android/TrainInfo/src/dk/thoerup/traininfo/util/AndroidTimeoutCache.java
ViewVC logotype

Diff of /android/TrainInfo/src/dk/thoerup/traininfo/util/AndroidTimeoutCache.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1032 by torben, Wed Sep 8 09:29:42 2010 UTC revision 1033 by torben, Wed Sep 8 10:23:44 2010 UTC
# Line 16  public class AndroidTimeoutCache<K,V> { Line 16  public class AndroidTimeoutCache<K,V> {
16                          lastupdate = android.os.SystemClock.elapsedRealtime();                          lastupdate = android.os.SystemClock.elapsedRealtime();
17                  }                  }
18                                    
19                    public boolean isExpired(long now) {
20                            return ( (lastupdate+timeout) < now);
21                    }
22                    
23                  public long lastupdate;                  public long lastupdate;
24                  public T value;                  public T value;
25          }          }
# Line 38  public class AndroidTimeoutCache<K,V> { Line 42  public class AndroidTimeoutCache<K,V> {
42                          K key = it.next();                          K key = it.next();
43                                                    
44                          CacheItem<V> item = cache.get(key);                          CacheItem<V> item = cache.get(key);
45                          if ( (item.lastupdate+timeout) < now) { //item too old                          if ( item.isExpired(now)) { //item too old
46                                  it.remove();                                  it.remove();
47                                  //Log.e("Purge", "removing");                                  //Log.e("Purge", "removing");
48                          }                                                }                      
# Line 58  public class AndroidTimeoutCache<K,V> { Line 62  public class AndroidTimeoutCache<K,V> {
62                                                                    
63                                    
64                  if (item != null) {                  if (item != null) {
65                          if ( (item.lastupdate+timeout) < now) { //item too old                          if ( item.isExpired(now) ) { //item too old
66                                  return null;                                  return null;
67                          } else {                          } else {
68                                  return item.value; //item still good                                  return item.value; //item still good

Legend:
Removed from v.1032  
changed lines
  Added in v.1033

  ViewVC Help
Powered by ViewVC 1.1.20