Package jadex.commons.collection
Class LeaseTimeMap<K,V>
- java.lang.Object
- 
- jadex.commons.collection.LeaseTimeMap<K,V>
 
- 
- All Implemented Interfaces:
- java.util.Map<K,V>
 
 public class LeaseTimeMap<K,V> extends java.lang.Object implements java.util.Map<K,V>Lease time map with supervised write/update access. For every entry a (potentially different) leasetime is used. Note: When not set to passive, the map internally uses a timer to prune expired entries. It should thus be used as synchronized map (default for non-passive) besides it is used with a specific timer that runs on same thread as normal access. The passive variant should only be called from same thread or externally synchronized or explicitly setting sync to true.
- 
- 
Field SummaryFields Modifier and Type Field Description protected java.util.Map<K,V>mapThe map.protected ILeaseTimeSet<K>timesLease time map with keys.protected booleantouchonreadFlag if touch on read.protected booleantouchonwriteFlag if touch on read.
 - 
Constructor SummaryConstructors Constructor Description LeaseTimeMap(long leasetime)Create a new lease time map.LeaseTimeMap(long leasetime, boolean passive, ICommand<Tuple2<java.util.Map.Entry<K,V>,java.lang.Long>> removecmd)Create a new lease time map.LeaseTimeMap(long leasetime, ICommand<Tuple2<java.util.Map.Entry<K,V>,java.lang.Long>> removecmd, boolean touchonread, boolean touchonwrite, boolean passive)Create a new lease time map.LeaseTimeMap(long leasetime, ICommand<Tuple2<java.util.Map.Entry<K,V>,java.lang.Long>> removecmd, boolean touchonread, boolean touchonwrite, boolean passive, IDelayRunner timer, boolean sync)Create a new lease time map.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckStale()Check for stale entries and remove them.voidclear()Removes all mappings from this map.booleancontainsKey(java.lang.Object key)ReturnsbooleancontainsValue(java.lang.Object value)Returnsjava.util.Set<java.util.Map.Entry<K,V>>entrySet()Returns a set view of the mappings contained in this map.booleanequals(java.lang.Object o)Compares the specified object with this map for equality.Vget(java.lang.Object key)Returns the collection to which this map maps the specified key.inthashCode()Returns the hash code value for this map.booleanisEmpty()Returnsjava.util.Set<K>keySet()Returns a set view of the keys contained in this map.static voidmain(java.lang.String[] args)Main for testing.Vput(K key, V value)Associates the specified value with the specified key in this map (optional operation).Vput(K key, V value, long leasetime)voidputAll(java.util.Map<? extends K,? extends V> t)Copies all of the mappings from the specified map to this map (optional operation).voidputAll(java.util.Map<? extends K,? extends V> t, long leasetime)Vremove(java.lang.Object key)Removes the mapping for this key from this map if it is present.intsize()Returns the number of elements added to this map.java.lang.StringtoString()Create a string representation of this map.voidtouch(K key)Update the timestamp of e.java.util.Collection<V>values()Unsupported Operation.
 
- 
- 
- 
Field Detail- 
timesprotected ILeaseTimeSet<K> times Lease time map with keys.
 - 
touchonreadprotected boolean touchonread Flag if touch on read.
 - 
touchonwriteprotected boolean touchonwrite Flag if touch on read.
 
- 
 - 
Constructor Detail- 
LeaseTimeMappublic LeaseTimeMap(long leasetime) Create a new lease time map.
 - 
LeaseTimeMappublic LeaseTimeMap(long leasetime, boolean passive, ICommand<Tuple2<java.util.Map.Entry<K,V>,java.lang.Long>> removecmd)Create a new lease time map.
 - 
LeaseTimeMappublic LeaseTimeMap(long leasetime, ICommand<Tuple2<java.util.Map.Entry<K,V>,java.lang.Long>> removecmd, boolean touchonread, boolean touchonwrite, boolean passive)Create a new lease time map.
 - 
LeaseTimeMappublic LeaseTimeMap(long leasetime, ICommand<Tuple2<java.util.Map.Entry<K,V>,java.lang.Long>> removecmd, boolean touchonread, boolean touchonwrite, boolean passive, IDelayRunner timer, boolean sync)Create a new lease time map.
 
- 
 - 
Method Detail- 
sizepublic int size() Returns the number of elements added to this map.
 - 
isEmptypublic boolean isEmpty() Returns- 
containsKeypublic boolean containsKey(java.lang.Object key) Returns- Specified by:
- containsKeyin interface- java.util.Map<K,V>
- Parameters:
- key- key whose presence in this map is to be tested.
- Returns:
- 
- Throws:
java.lang.ClassCastException- if the key is of an inappropriate type for this map (optional).java.lang.NullPointerException- if the key is
 - 
containsValuepublic boolean containsValue(java.lang.Object value) Returns- Specified by:
- containsValuein interface- java.util.Map<K,V>
- Parameters:
- value- value whose presence in this map is to be tested.
- Returns:
- 
- Throws:
java.lang.ClassCastException- if the value is of an inappropriate type for this map (optional).java.lang.NullPointerException- if the value is
 - 
getpublic V get(java.lang.Object key) Returns the collection to which this map maps the specified key. Returns- Specified by:
- getin interface- java.util.Map<K,V>
- Parameters:
- key- key whose associated collection is to be returned.
- Returns:
- the collection to which this map maps the specified key, or
               
- Throws:
java.lang.ClassCastException- if the key is of an inappropriate type for this map (optional).java.lang.NullPointerException- key is
- See Also:
containsKey(Object)
 - 
putpublic V put(K key, V value) Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for this key, the old value is replaced by the specified value. (A mapm.containsKey(k)would return- Specified by:
- putin interface- java.util.Map<K,V>
- Parameters:
- key- key with which the specified value is to be associated.
- value- value to be associated with the specified key.
- Returns:
- The collection associated to the key.
- Throws:
- java.lang.UnsupportedOperationException- if the- java.lang.ClassCastException- if the class of the specified key or value prevents it from being stored in this map.- java.lang.IllegalArgumentException- if some aspect of this key or value prevents it from being stored in this map.- java.lang.NullPointerException- this map does not permit
 - 
putAllpublic void putAll(java.util.Map<? extends K,? extends V> t) Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of callingput(k, v)on this map once for each mapping from key- Specified by:
- putAllin interface- java.util.Map<K,V>
- Parameters:
- t- Mappings to be stored in this map.
- Throws:
- java.lang.UnsupportedOperationException- if the- java.lang.ClassCastException- if the class of a key or value in the specified map prevents it from being stored in this map.- java.lang.IllegalArgumentException- some aspect of a key or value in the specified map prevents it from being stored in this map.- java.lang.NullPointerException- the specified map is
 - 
clearpublic void clear() Removes all mappings from this map.
 - 
keySetpublic java.util.Set<K> keySet() Returns a set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the- Specified by:
- keySetin interface- java.util.Map<K,V>
- Returns:
- a set view of the keys contained in this map.
 - 
valuespublic java.util.Collection<V> values() Unsupported Operation.
 - 
entrySetpublic java.util.Set<java.util.Map.Entry<K,V>> entrySet() Returns a set view of the mappings contained in this map. Each element in the returned set is a map entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the- Specified by:
- entrySetin interface- java.util.Map<K,V>
- Returns:
- a set view of the mappings contained in this map.
 - 
equalspublic boolean equals(java.lang.Object o) Compares the specified object with this map for equality. Returns- Specified by:
- equalsin interface- java.util.Map<K,V>
- Overrides:
- equalsin class- java.lang.Object
- Parameters:
- o- object to be compared for equality with this map.
- Returns:
 - 
hashCodepublic int hashCode() Returns the hash code value for this map.- Specified by:
- hashCodein interface- java.util.Map<K,V>
- Overrides:
- hashCodein class- java.lang.Object
- Returns:
- the hash code value for this map.
- See Also:
- Object.hashCode(),- Object.equals(Object),- equals(Object)
 
 - 
toStringpublic java.lang.String toString() Create a string representation of this map.- Overrides:
- toStringin class- java.lang.Object
 
 - 
removepublic V remove(java.lang.Object key) Removes the mapping for this key from this map if it is present. More formally, if this map contains a mapping from key (key==null ? k==null : key.equals(k)), that mapping is removed. (The map can contain at most one such mapping.)- Specified by:
- removein interface- java.util.Map<K,V>
- Parameters:
- key- key whose mapping is to be removed from the map.
- Returns:
- collection associated with specified key, or 
- Throws:
java.lang.ClassCastException- if the key is of an inappropriate type for this map (optional).java.lang.NullPointerException- if the key is
 - 
touchpublic void touch(K key) Update the timestamp of e.- Parameters:
- entry- The entry.
 
 - 
checkStalepublic void checkStale() Check for stale entries and remove them. This operation is only permissible in passive mode.
 - 
mainpublic static void main(java.lang.String[] args) Main for testing.
 
 
 
 
 
 
 
 
 
 
- 
 
- 
 
-