if (isTimestampInPast(nextCleaningTime)) cleanExpired();
if (isTimestampInPast(nextCleaningTime)) cleanExpired();
final ExpirationMapEntry<V> val = map.putIfAbsent(key, new ExpirationMapEntry<>(value));
final ExpirationMapEntry<V> val = map.putIfAbsent(key, new ExpirationMapEntry<>(value));
return val == null ? null : val.value;
return val == null ? null : val.touch().value;
}
}
@Override public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
@Override public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
if (isTimestampInPast(nextCleaningTime)) cleanExpired();
if (isTimestampInPast(nextCleaningTime)) cleanExpired();
return map.computeIfAbsent(key, k -> new ExpirationMapEntry<>(mappingFunction.apply(k))).value;
return map.computeIfAbsent(key, k -> new ExpirationMapEntry<>(mappingFunction.apply(k))).touch().value;
}
}
@Override public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
@Override public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
if (isTimestampInPast(nextCleaningTime)) cleanExpired();
if (isTimestampInPast(nextCleaningTime)) cleanExpired();
final ExpirationMapEntry<V> found = map.computeIfPresent(key, (k, vExpirationMapEntry) -> new ExpirationMapEntry<>(remappingFunction.apply(k, vExpirationMapEntry.value)));
final ExpirationMapEntry<V> found = map.computeIfPresent(key, (k, vExpirationMapEntry) -> new ExpirationMapEntry<>(remappingFunction.apply(k, vExpirationMapEntry.value)));
return found == null ? null : found.value;
return found == null ? null : found.touch().value;
}
}
@AllArgsConstructor
@AllArgsConstructor
private static class EMEntry<K, V> implements Entry<K, V> {
private static class EMEntry<K, V> implements Entry<K, V> {
@Getter private K key;
@Getter private V value;
@Getter private final K key;
@Getter private final V value;
@Override public V setValue(V value) { return notSupported("setValue"); }
@Override public V setValue(V value) { return notSupported("setValue"); }
}
}
@Override public Set<Entry<K, V>> entrySet() {
@Override public Set<Entry<K, V>> entrySet() {
if (isTimestampInPast(nextCleaningTime)) cleanExpired();
if (isTimestampInPast(nextCleaningTime)) cleanExpired();
return map.entrySet().stream().map(e -> new EMEntry<>(e.getKey(), e.getValue().value)).collect(Collectors.toSet());
return map.entrySet().stream().map(e -> new EMEntry<>(e.getKey(), e.getValue().touch().value)).collect(Collectors.toSet());