From c6cd09b50d43f9b5dcdb6d5b6b416420e3c7eec3 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 10 Mar 2016 07:22:47 +0000 Subject: [PATCH] Fix isStale condition --- source/net/filebot/Cache.java | 10 +++------- source/net/filebot/web/ID3Lookup.java | 1 - 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/source/net/filebot/Cache.java b/source/net/filebot/Cache.java index 835032cc..76cd89aa 100644 --- a/source/net/filebot/Cache.java +++ b/source/net/filebot/Cache.java @@ -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 isAbsent() { - return (element) -> element == null; - } - public static Predicate 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 diff --git a/source/net/filebot/web/ID3Lookup.java b/source/net/filebot/web/ID3Lookup.java index 5162319d..60fd842e 100644 --- a/source/net/filebot/web/ID3Lookup.java +++ b/source/net/filebot/web/ID3Lookup.java @@ -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;