tuweni / org.apache.tuweni.concurrent / ExpiringMap / putIfAbsent

putIfAbsent

@Nullable fun putIfAbsent(key: K, value: V): V? (source) @Nullable fun putIfAbsent(key: K, value: V, expiry: Long): V? (source)

If the specified key is not already associated with a value, associates the specified value with the specified key in this map, and expires the entry when the specified expiry time is reached.

Parameters

key - K: The key with which the specified value is to be associated.

value - V: The value to be associated with the specified key.

expiry - Long: The expiry time for the value, in milliseconds since the epoch.

Return
V?: The previous value associated with key, or null if there was no mapping for key.

@Nullable fun putIfAbsent(key: K, value: V, expiry: Long, @Nullable expiryListener: BiConsumer<K, V>?): V? (source)

If the specified key is not already associated with a value, associates the specified value with the specified key in this map, and expires the entry when the specified expiry time is reached.

Parameters

key - K: The key with which the specified value is to be associated.

value - V: The value to be associated with the specified key.

expiry - Long: The expiry time for the value, in milliseconds since the epoch.

expiryListener - BiConsumer<K, V>?: A listener that will be invoked when the entry expires.

Return
V?: The previous value associated with key, or null if there was no mapping for key.