From 4452446c58411c3f8e13f1fb5c3eecd0e9140d15 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Tue, 7 Apr 2020 23:54:05 +0200 Subject: [PATCH] move isCache/cleanCache to BasicLibrary, improve filter() --- .../nikiroo/fanfix/library/BasicLibrary.java | 50 +++++++++++++------ .../nikiroo/fanfix/library/CacheLibrary.java | 23 +-------- .../fanfix/library/MetaResultList.java | 10 ++++ 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/src/be/nikiroo/fanfix/library/BasicLibrary.java b/src/be/nikiroo/fanfix/library/BasicLibrary.java index b92e5b0..c6ce22d 100644 --- a/src/be/nikiroo/fanfix/library/BasicLibrary.java +++ b/src/be/nikiroo/fanfix/library/BasicLibrary.java @@ -345,6 +345,36 @@ abstract public class BasicLibrary { // We will let it fail later } } + + /** + * Check if the {@link Story} denoted by this Library UID is present in the + * cache (if we have no cache, we default to true). + * + * @param luid + * the Library UID + * + * @return TRUE if it is + */ + public boolean isCached(String luid) { + // By default, everything is cached + return true; + } + + /** + * Clear the {@link Story} from the cache, if needed. + *

+ * The next time we try to retrieve the {@link Story}, it may be required to + * cache it again. + * + * @param luid + * the story to clear + * + * @throws IOException + * in case of I/O error + */ + public void clearFromCache(String luid) throws IOException { + // By default, this is a noop. + } /** * List all the known types (sources) of stories. @@ -584,17 +614,11 @@ abstract public class BasicLibrary { * @throws IOException in case of IOException * * @deprecated use {@link BasicLibrary#getList(Progress)} and - * {@link MetaResultList#filter(List, List, List)} + * {@link MetaResultList#filter(String, String, String)} */ @Deprecated public synchronized List getListBySource(String source) throws IOException { - List sources = null; - if (source != null) { - sources = new ArrayList(); - sources.add(source); - } - - return getList(null).filter(sources, null, null); + return getList(null).filter(source, null, null); } /** @@ -612,16 +636,10 @@ abstract public class BasicLibrary { * in case of IOException * * @deprecated use {@link BasicLibrary#getList(Progress)} and - * {@link MetaResultList#filter(List, List, List)} + * {@link MetaResultList#filter(String, String, String)} */ public synchronized List getListByAuthor(String author) throws IOException { - List authors = null; - if (author != null) { - authors = new ArrayList(); - authors.add(author); - } - - return getList(null).filter(null, authors, null); + return getList(null).filter(null, author, null); } /** diff --git a/src/be/nikiroo/fanfix/library/CacheLibrary.java b/src/be/nikiroo/fanfix/library/CacheLibrary.java index 14d28cf..9c83e62 100644 --- a/src/be/nikiroo/fanfix/library/CacheLibrary.java +++ b/src/be/nikiroo/fanfix/library/CacheLibrary.java @@ -317,15 +317,7 @@ public class CacheLibrary extends BasicLibrary { invalidateInfo(luid); } - /** - * Check if the {@link Story} denoted by this Library UID is present in the - * cache. - * - * @param luid - * the Library UID - * - * @return TRUE if it is - */ + @Override public boolean isCached(String luid) { try { return cacheLib.getInfo(luid) != null; @@ -334,18 +326,7 @@ public class CacheLibrary extends BasicLibrary { } } - /** - * Clear the {@link Story} from the cache. - *

- * The next time we try to retrieve the {@link Story}, it may be required to - * cache it again. - * - * @param luid - * the story to clear - * - * @throws IOException - * in case of I/O error - */ + @Override public void clearFromCache(String luid) throws IOException { if (isCached(luid)) { cacheLib.delete(luid); diff --git a/src/be/nikiroo/fanfix/library/MetaResultList.java b/src/be/nikiroo/fanfix/library/MetaResultList.java index 3aa167f..886defe 100644 --- a/src/be/nikiroo/fanfix/library/MetaResultList.java +++ b/src/be/nikiroo/fanfix/library/MetaResultList.java @@ -1,6 +1,7 @@ package be.nikiroo.fanfix.library; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -88,6 +89,15 @@ public class MetaResultList { return authors; } + // helper + public List filter(String source, String author, String tag) { + List sources = source == null ? null : Arrays.asList(source); + List authors = author == null ? null : Arrays.asList(author); + List tags = tag == null ? null : Arrays.asList(tag); + + return filter(sources, authors, tags); + } + // null or empty -> no check, rest = must be included // source: a source ending in "/" means "this or any source starting with this", // i;e., to enable source hierarchy -- 2.27.0