Package de.mhus.lib.core.util
Class SoftTimeoutMap<K,V>
- java.lang.Object
-
- de.mhus.lib.core.util.SoftTimeoutMap<K,V>
-
-
Constructor Summary
Constructors Constructor Description SoftTimeoutMap()SoftTimeoutMap(long timeout)SoftTimeoutMap(long timeout, boolean refreshOnAccess)SoftTimeoutMap(long timeout, long checkTimeout, boolean refreshOnAccess)SoftTimeoutMap(long timeout, long checkTimeout, boolean refreshOnAccess, SoftTimeoutMap.Invalidator<K,V> invalidator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Vcompute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)VcomputeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)VcomputeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)booleancontainsKey(Object key)booleancontainsValue(Object value)voiddoValidationCheck()Set<Map.Entry<K,V>>entrySet()booleanequals(Object o)voidforEach(BiConsumer<? super K,? super V> action)Vget(Object key)longgetAccessCount(Object key)longgetCheckTimeout()SoftTimeoutMap.Invalidator<K,V>getInvalidator()VgetOrDefault(Object key, V defaultValue)longgetTimeout()inthashCode()booleanisEmpty()booleanisRefreshOnAccess()Set<K>keySet()Vmerge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)Vput(K key, V value)voidputAll(Map<? extends K,? extends V> m)VputIfAbsent(K key, V value)Vremove(Object key)booleanremove(Object key, Object value)Vreplace(K key, V value)booleanreplace(K key, V oldValue, V newValue)voidreplaceAll(BiFunction<? super K,? super V,? extends V> function)voidsetCheckTimeout(long checkTimeout)Set the time after a full check should be done.voidsetInvalidator(SoftTimeoutMap.Invalidator<K,V> invalidator)Set a function which can decide if the entry is no more valid.voidsetRefreshOnAccess(boolean refreshOnAccess)Set to true if also get requests will reset the timeout.voidsetTimeout(long timeout)Set the maximal life time for every entry.intsize()Collection<V>values()
-
-
-
Constructor Detail
-
SoftTimeoutMap
public SoftTimeoutMap()
-
SoftTimeoutMap
public SoftTimeoutMap(long timeout)
-
SoftTimeoutMap
public SoftTimeoutMap(long timeout, boolean refreshOnAccess)
-
SoftTimeoutMap
public SoftTimeoutMap(long timeout, long checkTimeout, boolean refreshOnAccess)
-
SoftTimeoutMap
public SoftTimeoutMap(long timeout, long checkTimeout, boolean refreshOnAccess, SoftTimeoutMap.Invalidator<K,V> invalidator)
-
-
Method Detail
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<K,V>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<K,V>
-
getAccessCount
public long getAccessCount(Object key)
-
doValidationCheck
public void doValidationCheck()
-
equals
public boolean equals(Object o)
-
hashCode
public int hashCode()
-
getOrDefault
public V getOrDefault(Object key, V defaultValue)
- Specified by:
getOrDefaultin interfaceMap<K,V>
-
forEach
public void forEach(BiConsumer<? super K,? super V> action)
-
replaceAll
public void replaceAll(BiFunction<? super K,? super V,? extends V> function)
- Specified by:
replaceAllin interfaceMap<K,V>
-
computeIfAbsent
public V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
- Specified by:
computeIfAbsentin interfaceMap<K,V>
-
computeIfPresent
public V computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
- Specified by:
computeIfPresentin interfaceMap<K,V>
-
merge
public V merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)
-
getTimeout
public long getTimeout()
-
setTimeout
public void setTimeout(long timeout)
Set the maximal life time for every entry. After the timeout the entry will be removed.- Parameters:
timeout- timeout in ms
-
getCheckTimeout
public long getCheckTimeout()
-
setCheckTimeout
public void setCheckTimeout(long checkTimeout)
Set the time after a full check should be done. If the map is accesses after timeout a full check over all elements will be performed. Set to -1 to disable.- Parameters:
checkTimeout- timeout in ms
-
getInvalidator
public SoftTimeoutMap.Invalidator<K,V> getInvalidator()
-
setInvalidator
public void setInvalidator(SoftTimeoutMap.Invalidator<K,V> invalidator)
Set a function which can decide if the entry is no more valid.- Parameters:
invalidator-
-
isRefreshOnAccess
public boolean isRefreshOnAccess()
-
setRefreshOnAccess
public void setRefreshOnAccess(boolean refreshOnAccess)
Set to true if also get requests will reset the timeout. If set to false it will timeout even it was read. Default is true.- Parameters:
refreshOnAccess-
-
-