--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimeoutCache.java 2009/10/02 15:06:08 387 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimeoutMap.java 2009/10/09 08:52:37 428 @@ -1,9 +1,13 @@ package dk.thoerup.traininfoservice.banedk; import java.util.concurrent.ConcurrentHashMap; +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import com.sun.xml.rpc.processor.schema.UnimplementedFeatureException; -public class TimeoutCache { +public class TimeoutMap implements Map{ class CacheItem { @@ -19,19 +23,74 @@ private ConcurrentHashMap> cache = new ConcurrentHashMap>(); private long timeout; - public TimeoutCache(int timeout) { + public TimeoutMap(int timeout) { this.timeout = timeout; } - - public void put(K k, V v) { - CacheItem item= new CacheItem(v); - cache.put(k, item); + + + @Override + public void clear() { + cache.clear(); + } - - public V get(K k) { + + @Override + public boolean containsKey(Object arg0) { + CacheItem item = cache.get(arg0); + + return (item != null); + } + + @Override + public boolean containsValue(Object arg0) { + //TODO someday implement this + throw new UnsupportedOperationException(); + + } + + @Override + public Set> entrySet() { + //TODO someday implement this + throw new UnsupportedOperationException(); + } + + @Override + public boolean isEmpty() { + return cache.isEmpty(); + } + + @Override + public Set keySet() { + return cache.keySet(); + } + + @Override + public void putAll(Map arg0) { + //TODO someday implement this + throw new UnsupportedOperationException(); + } + + @Override + public V remove(Object arg0) { + return cache.remove(arg0).value; + } + + @Override + public int size() { + return cache.size(); + } + + @Override + public Collection values() { + //TODO someday implement this + throw new UnsupportedOperationException(); + } + + @Override + public V get(Object key) { long now = System.currentTimeMillis(); - CacheItem item = cache.get(k); + CacheItem item = cache.get(key); if (item != null) { @@ -43,7 +102,13 @@ } else { return null; // no item found } + } + + @Override + public V put(K key, V value) { + CacheItem item= new CacheItem(value); + return cache.put(key, item).value; } }