summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/util/TimeoutHashMap.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-06-22 17:30:12 +0200
committerSimon Rettberg2015-06-22 17:30:12 +0200
commitba691ef7a9ee4b0abd121dd487859f8fb38a0fa1 (patch)
tree816edb3ebd8b083057fc3de588657277d8e1c091 /src/main/java/org/openslx/util/TimeoutHashMap.java
parentAdd more Thrift calls (diff)
downloadmaster-sync-shared-ba691ef7a9ee4b0abd121dd487859f8fb38a0fa1.tar.gz
master-sync-shared-ba691ef7a9ee4b0abd121dd487859f8fb38a0fa1.tar.xz
master-sync-shared-ba691ef7a9ee4b0abd121dd487859f8fb38a0fa1.zip
Update api
Diffstat (limited to 'src/main/java/org/openslx/util/TimeoutHashMap.java')
-rw-r--r--src/main/java/org/openslx/util/TimeoutHashMap.java102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/util/TimeoutHashMap.java b/src/main/java/org/openslx/util/TimeoutHashMap.java
new file mode 100644
index 0000000..3efb367
--- /dev/null
+++ b/src/main/java/org/openslx/util/TimeoutHashMap.java
@@ -0,0 +1,102 @@
+package org.openslx.util;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+public class TimeoutHashMap<K, V> implements Map<K, V>
+{
+
+ private final Map<K, TimeoutReference<V>> map;
+ private final long timeout;
+
+ public TimeoutHashMap( long timeout )
+ {
+ this.map = new HashMap<>();
+ this.timeout = timeout;
+ }
+
+ @Override
+ public int size()
+ {
+ return map.size();
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ return map.isEmpty();
+ }
+
+ @Override
+ public boolean containsKey( Object key )
+ {
+ return map.containsKey( key );
+ }
+
+ @Override
+ public boolean containsValue( Object value )
+ {
+ return map.containsValue( value );
+ }
+
+ @Override
+ public V get( Object key )
+ {
+ TimeoutReference<V> timeoutReference = map.get( key );
+ if ( timeoutReference == null )
+ return null;
+ return timeoutReference.get();
+ }
+
+ @Override
+ public V put( K key, V value )
+ {
+ map.put( key, new TimeoutReference<V>(
+ false, timeout, value ) );
+ return value;
+ }
+
+ @Override
+ public V remove( Object key )
+ {
+ TimeoutReference<V> remove = map.remove( key );
+ if ( remove == null )
+ return null;
+ return remove.get();
+ }
+
+ @Override
+ public void putAll( Map<? extends K, ? extends V> m )
+ {
+ for ( java.util.Map.Entry<? extends K, ? extends V> entry : m.entrySet() ) {
+ put( entry.getKey(), entry.getValue() );
+ }
+ }
+
+ @Override
+ public void clear()
+ {
+ map.clear();
+ }
+
+ @Override
+ public Set<K> keySet()
+ {
+ return map.keySet();
+ }
+
+ @Override
+ public Collection<V> values()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Set<java.util.Map.Entry<K, V>> entrySet()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+}