com.aol.cyclops.lambda.api.Gettable Maven / Gradle / Ivy
package com.aol.cyclops.lambda.api;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.function.Supplier;
import com.aol.cyclops.invokedynamic.ExceptionSoftener;
import com.aol.cyclops.invokedynamic.InvokeDynamic;
public interface Gettable extends Supplier {
default Object unwrap(){
return this;
}
default List getSupplierMethodNames(){
return Arrays.asList("get","call");
}
default T get(){
Object gettable = unwrap();
if(gettable instanceof Supplier)
return ((Supplier)gettable).get();
if(gettable instanceof Callable){
try {
return ((Callable)gettable).call();
} catch (Exception e) {
ExceptionSoftener.throwSoftenedException(e);
}
}
return new InvokeDynamic().supplier(gettable,getSupplierMethodNames()).get();
}
}