1 |
package dk.thoerup.traininfoservice.banedk; |
package dk.thoerup.traininfoservice.banedk; |
2 |
|
|
3 |
import java.util.concurrent.ConcurrentHashMap; |
import java.util.ArrayList; |
4 |
import java.util.Collection; |
import java.util.Collection; |
5 |
import java.util.Map; |
import java.util.Map; |
6 |
import java.util.Set; |
import java.util.Set; |
7 |
|
import java.util.concurrent.ConcurrentHashMap; |
8 |
|
|
9 |
|
|
|
import com.sun.xml.rpc.processor.schema.UnimplementedFeatureException; |
|
10 |
|
|
11 |
public class TimeoutMap<K,V> implements Map<K,V>{ |
public class TimeoutMap<K,V> implements Map<K,V>{ |
12 |
|
|
36 |
} |
} |
37 |
|
|
38 |
@Override |
@Override |
39 |
public boolean containsKey(Object arg0) { |
public boolean containsKey(Object key) { |
40 |
CacheItem<V> item = cache.get(arg0); |
return cache.containsKey(key); |
|
|
|
|
return (item != null); |
|
41 |
} |
} |
42 |
|
|
43 |
@Override |
@Override |
44 |
public boolean containsValue(Object arg0) { |
public boolean containsValue(Object arg0) { |
45 |
//TODO someday implement this |
return values().contains(arg0); |
|
throw new UnsupportedOperationException(); |
|
|
|
|
46 |
} |
} |
47 |
|
|
48 |
@Override |
@Override |
63 |
|
|
64 |
@Override |
@Override |
65 |
public void putAll(Map<? extends K, ? extends V> arg0) { |
public void putAll(Map<? extends K, ? extends V> arg0) { |
66 |
//TODO someday implement this |
for(K key : arg0.keySet()) { |
67 |
throw new UnsupportedOperationException(); |
this.put(key, arg0.get(key) ); |
68 |
|
} |
69 |
} |
} |
70 |
|
|
71 |
@Override |
@Override |
80 |
|
|
81 |
@Override |
@Override |
82 |
public Collection<V> values() { |
public Collection<V> values() { |
83 |
//TODO someday implement this |
ArrayList<V> values = new ArrayList<V>(); |
84 |
throw new UnsupportedOperationException(); |
for (CacheItem<V> item : cache.values()) { |
85 |
|
values.add( item.value ); |
86 |
|
} |
87 |
|
|
88 |
|
return values; |
89 |
|
|
90 |
} |
} |
91 |
|
|
92 |
@Override |
@Override |
111 |
public V put(K key, V value) { |
public V put(K key, V value) { |
112 |
CacheItem<V> item= new CacheItem<V>(value); |
CacheItem<V> item= new CacheItem<V>(value); |
113 |
|
|
114 |
return cache.put(key, item).value; |
item = cache.put(key, item); |
115 |
|
|
116 |
|
if (item != null) |
117 |
|
return item.value; |
118 |
|
else |
119 |
|
return null; |
120 |
} |
} |
121 |
|
|
122 |
} |
} |