mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 08:48:51 -05:00
Refactor
This commit is contained in:
parent
b4498da47e
commit
1e7fa00ef4
@ -1,7 +1,7 @@
|
||||
package net.filebot;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.*;
|
||||
import static net.filebot.CachedResource2.*;
|
||||
import static net.filebot.CachedResource.*;
|
||||
import static net.filebot.Logging.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
@ -10,7 +10,7 @@ import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import net.filebot.CachedResource2.Transform;
|
||||
import net.filebot.CachedResource.Transform;
|
||||
import net.sf.ehcache.Element;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
@ -25,20 +25,20 @@ public class Cache {
|
||||
return CacheManager.getInstance().getCache(name, type);
|
||||
}
|
||||
|
||||
public <T> CachedResource2<T, byte[]> bytes(T key, Transform<T, URL> resource) {
|
||||
return new CachedResource2<T, byte[]>(key, resource, fetchIfModified(), getBytes(), byte[].class::cast, ONE_DAY, this);
|
||||
public <T> CachedResource<T, byte[]> bytes(T key, Transform<T, URL> resource) {
|
||||
return new CachedResource<T, byte[]>(key, resource, fetchIfModified(), getBytes(), byte[].class::cast, ONE_DAY, this);
|
||||
}
|
||||
|
||||
public <T> CachedResource2<T, String> text(T key, Transform<T, URL> resource) {
|
||||
return new CachedResource2<T, String>(key, resource, fetchIfModified(), getText(UTF_8), String.class::cast, ONE_DAY, this);
|
||||
public <T> CachedResource<T, String> text(T key, Transform<T, URL> resource) {
|
||||
return new CachedResource<T, String>(key, resource, fetchIfModified(), getText(UTF_8), String.class::cast, ONE_DAY, this);
|
||||
}
|
||||
|
||||
public <T> CachedResource2<T, Document> xml(T key, Transform<T, URL> resource) {
|
||||
return new CachedResource2<T, Document>(key, resource, fetchIfModified(), validateXml(getText(UTF_8)), getXml(String.class::cast), ONE_DAY, this);
|
||||
public <T> CachedResource<T, Document> xml(T key, Transform<T, URL> resource) {
|
||||
return new CachedResource<T, Document>(key, resource, fetchIfModified(), validateXml(getText(UTF_8)), getXml(String.class::cast), ONE_DAY, this);
|
||||
}
|
||||
|
||||
public <T> CachedResource2<T, Object> json(T key, Transform<T, URL> resource) {
|
||||
return new CachedResource2<T, Object>(key, resource, fetchIfModified(), validateJson(getText(UTF_8)), getJson(String.class::cast), ONE_DAY, this);
|
||||
public <T> CachedResource<T, Object> json(T key, Transform<T, URL> resource) {
|
||||
return new CachedResource<T, Object>(key, resource, fetchIfModified(), validateJson(getText(UTF_8)), getJson(String.class::cast), ONE_DAY, this);
|
||||
}
|
||||
|
||||
private final net.sf.ehcache.Cache cache;
|
||||
|
@ -18,7 +18,7 @@ import net.filebot.web.WebRequest;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
public class CachedResource2<K, R> implements Resource<R> {
|
||||
public class CachedResource<K, R> implements Resource<R> {
|
||||
|
||||
public static final int DEFAULT_RETRY_LIMIT = 2;
|
||||
public static final Duration DEFAULT_RETRY_DELAY = Duration.ofSeconds(2);
|
||||
@ -37,11 +37,11 @@ public class CachedResource2<K, R> implements Resource<R> {
|
||||
|
||||
private final Cache cache;
|
||||
|
||||
public CachedResource2(K key, Transform<K, URL> resource, Fetch fetch, Transform<ByteBuffer, ? extends Object> parse, Transform<? super Object, R> cast, Duration expirationTime, Cache cache) {
|
||||
public CachedResource(K key, Transform<K, URL> resource, Fetch fetch, Transform<ByteBuffer, ? extends Object> parse, Transform<? super Object, R> cast, Duration expirationTime, Cache cache) {
|
||||
this(key, resource, fetch, parse, cast, DEFAULT_RETRY_LIMIT, DEFAULT_RETRY_DELAY, expirationTime, cache);
|
||||
}
|
||||
|
||||
public CachedResource2(K key, Transform<K, URL> resource, Fetch fetch, Transform<ByteBuffer, ? extends Object> parse, Transform<? super Object, R> cast, int retryLimit, Duration retryWait, Duration expirationTime, Cache cache) {
|
||||
public CachedResource(K key, Transform<K, URL> resource, Fetch fetch, Transform<ByteBuffer, ? extends Object> parse, Transform<? super Object, R> cast, int retryLimit, Duration retryWait, Duration expirationTime, Cache cache) {
|
||||
this.key = key;
|
||||
this.resource = resource;
|
||||
this.fetch = fetch;
|
||||
@ -53,17 +53,17 @@ public class CachedResource2<K, R> implements Resource<R> {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
public synchronized CachedResource2<K, R> fetch(Fetch fetch) {
|
||||
public synchronized CachedResource<K, R> fetch(Fetch fetch) {
|
||||
this.fetch = fetch;
|
||||
return this;
|
||||
}
|
||||
|
||||
public synchronized CachedResource2<K, R> expire(Duration expirationTime) {
|
||||
public synchronized CachedResource<K, R> expire(Duration expirationTime) {
|
||||
this.expirationTime = expirationTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public synchronized CachedResource2<K, R> retry(int retryLimit) {
|
||||
public synchronized CachedResource<K, R> retry(int retryLimit) {
|
||||
this.retryLimit = retryLimit;
|
||||
return this;
|
||||
}
|
@ -2,7 +2,7 @@ package net.filebot.web;
|
||||
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.CachedResource2.*;
|
||||
import static net.filebot.CachedResource.*;
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.util.JsonUtilities.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
|
@ -3,7 +3,7 @@ package net.filebot.web;
|
||||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.CachedResource2.*;
|
||||
import static net.filebot.CachedResource.*;
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.util.JsonUtilities.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
|
Loading…
Reference in New Issue
Block a user