This commit is contained in:
Reinhard Pointner 2016-03-09 10:32:49 +00:00
parent 67431e1745
commit bf2571f04f
6 changed files with 29 additions and 20 deletions

View File

@ -200,10 +200,8 @@ public class ArgumentProcessor {
return uri.getSchemeSpecificPart();
}
// remote script
// check remote script for updates (weekly for stable and daily for devel branches)
Cache cache = Cache.getCache(NAME, CacheType.Persistent);
// fetch remote script only if modified
return cache.text(uri.toString(), s -> {
return new URL(resolveTemplate(uri));
}).expire(SCHEME_REMOTE_DEVEL.equals(uri.getScheme()) ? Cache.ONE_DAY : Cache.ONE_WEEK).get();

View File

@ -328,11 +328,11 @@ public class ExpressionFormatMethods {
/**
* Join non-empty String values and prepend prefix / append suffix values
*
*
* e.g. (1..3).join('-', '[', ']')
*
*
* Unwind if list is empty
*
*
* e.g. [].join('-', '[', ']') => Exception: List is empty
*/
public static String join(Collection<?> self, String delimiter, String prefix, String suffix) throws Exception {

View File

@ -447,7 +447,7 @@ public class MediaBindingBean {
// calculate checksum from file
Cache cache = Cache.getCache("crc32", CacheType.Ephemeral);
return (String) cache.computeIfAbsent(inferredMediaFile.getCanonicalPath(), it -> crc32(inferredMediaFile));
return (String) cache.computeIf(inferredMediaFile.getCanonicalPath(), Cache.isAbsent(), it -> crc32(inferredMediaFile));
}
@Define("fn")

View File

@ -96,11 +96,11 @@ public class JsonUtilities {
return null;
}
public static <K extends Enum<K>> EnumMap<K, String> mapStringValues(Object node, Class<K> cls) {
return mapValues(node, cls, StringUtilities::asNonEmptyString);
public static <K extends Enum<K>> EnumMap<K, String> getEnumMap(Object node, Class<K> cls) {
return getEnumMap(node, cls, StringUtilities::asNonEmptyString);
}
public static <K extends Enum<K>, V> EnumMap<K, V> mapValues(Object node, Class<K> cls, Function<Object, V> converter) {
public static <K extends Enum<K>, V> EnumMap<K, V> getEnumMap(Object node, Class<K> cls, Function<Object, V> converter) {
Map<?, ?> values = asMap(node);
EnumMap<K, V> map = new EnumMap<K, V>(cls);
for (K key : cls.getEnumConstants()) {
@ -115,4 +115,8 @@ public class JsonUtilities {
return map;
}
private JsonUtilities() {
throw new UnsupportedOperationException();
}
}

View File

@ -1,6 +1,7 @@
package net.filebot.util;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Stream;
@ -143,6 +144,17 @@ public final class XPathUtilities {
return IntStream.range(0, nodes.getLength()).mapToObj(nodes::item);
}
public static <K extends Enum<K>> EnumMap<K, String> getEnumMap(Node node, Class<K> cls) {
EnumMap<K, String> map = new EnumMap<K, String>(cls);
for (K key : cls.getEnumConstants()) {
String value = getTextContent(key.name(), node);
if (value != null && value.length() > 0) {
map.put(key, value);
}
}
return map;
}
private XPathUtilities() {
throw new UnsupportedOperationException();
}

View File

@ -1,6 +1,5 @@
package net.filebot.web;
import static java.util.Collections.*;
import static java.util.stream.Collectors.*;
import static net.filebot.util.JsonUtilities.*;
@ -49,13 +48,13 @@ public class FanartTVClient implements Datasource {
Cache cache = Cache.getCache(getName(), CacheType.Weekly);
Object json = cache.json(path, s -> getResource(s)).expire(Cache.ONE_WEEK);
return asMap(json).entrySet().stream().flatMap(it -> {
return streamJsonObjects(it.getValue()).map(item -> {
Map<FanartProperty, String> map = mapStringValues(item, FanartProperty.class);
map.put(FanartProperty.type, it.getKey().toString());
return asMap(json).entrySet().stream().flatMap(type -> {
return streamJsonObjects(type.getValue()).map(item -> {
Map<FanartProperty, String> map = getEnumMap(item, FanartProperty.class);
map.put(FanartProperty.type, type.getKey().toString());
return new FanartDescriptor(map);
}).filter(a -> a.getProperties().size() > 1);
}).filter(art -> art.getUrl() != null);
}).collect(toList());
}
@ -80,10 +79,6 @@ public class FanartTVClient implements Datasource {
this.properties = new EnumMap<FanartProperty, String>(fields);
}
public Map<FanartProperty, String> getProperties() {
return unmodifiableMap(properties);
}
public String get(Object key) {
return properties.get(FanartProperty.valueOf(key.toString()));
}