Work around compiler type-inference issues

This commit is contained in:
Reinhard Pointner 2016-11-19 00:12:36 +08:00
parent ca218231ba
commit 592e3ae608
2 changed files with 13 additions and 11 deletions

View File

@ -10,7 +10,14 @@ public interface GVFS {
File getPathForURI(URI uri);
public static GVFS getDefaultVFS() {
return SystemProperty.of("net.filebot.gio.GVFS", path -> new PlatformGVFS(new File(path)), NativeGVFS::new).get();
GVFS gvfs = SystemProperty.of("net.filebot.gio.GVFS", path -> new PlatformGVFS(new File(path))).get();
// default to native implementation GVFS folder is not set
if (gvfs == null) {
gvfs = new NativeGVFS();
}
return gvfs;
}
}

View File

@ -4,31 +4,26 @@ import static net.filebot.Logging.*;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.logging.Level;
public class SystemProperty<T> {
public static <T> SystemProperty<T> of(String key, Function<String, T> valueFunction, T defaultValue) {
return new SystemProperty<T>(key, valueFunction, () -> defaultValue);
}
public static <T> SystemProperty<T> of(String key, Function<String, T> valueFunction) {
return new SystemProperty<T>(key, valueFunction, null);
}
public static <T> SystemProperty<T> of(String key, Function<String, T> valueFunction, Supplier<T> defaultValue) {
public static <T> SystemProperty<T> of(String key, Function<String, T> valueFunction, T defaultValue) {
return new SystemProperty<T>(key, valueFunction, defaultValue);
}
private final String key;
private final Function<String, T> valueFunction;
private final Supplier<T> defaultValueFunction;
private final T defaultValue;
private SystemProperty(String key, Function<String, T> valueFunction, Supplier<T> defaultValue) {
private SystemProperty(String key, Function<String, T> valueFunction, T defaultValue) {
this.key = key;
this.valueFunction = valueFunction;
this.defaultValueFunction = defaultValue;
this.defaultValue = defaultValue;
}
public T get() {
@ -42,7 +37,7 @@ public class SystemProperty<T> {
}
}
return defaultValueFunction == null ? null : defaultValueFunction.get();
return defaultValue;
}
public Optional<T> optional() {