All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aol.cyclops.lambda.api.Gettable Maven / Gradle / Ivy

There is a newer version: 7.2.4
Show newest version
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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy