1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 00:38:52 -05:00

Fix isStale condition

This commit is contained in:
Reinhard Pointner 2016-03-10 07:22:47 +00:00
parent 8bb15132d2
commit c6cd09b50d
2 changed files with 3 additions and 8 deletions

View File

@ -63,7 +63,7 @@ public class Cache {
Element element = null;
try {
element = cache.get(key);
if (!condition.test(element)) {
if (element != null && !condition.test(element)) {
return getElementValue(element);
}
} catch (Exception e) {
@ -77,7 +77,7 @@ public class Cache {
}
public Object computeIfAbsent(Object key, Compute<?> compute) throws Exception {
return computeIf(key, isAbsent(), compute);
return computeIf(key, it -> it == null, compute);
}
public void put(Object key, Object value) {
@ -112,12 +112,8 @@ public class Cache {
}
}
public static Predicate<Element> isAbsent() {
return (element) -> element == null;
}
public static Predicate<Element> isStale(Duration expirationTime) {
return (element) -> element == null || element.getObjectValue() == null || System.currentTimeMillis() - element.getLatestOfCreationAndUpdateTime() < expirationTime.toMillis();
return (element) -> System.currentTimeMillis() - element.getLatestOfCreationAndUpdateTime() > expirationTime.toMillis();
}
@FunctionalInterface

View File

@ -9,7 +9,6 @@ import java.io.File;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Level;
import javax.swing.Icon;