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

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

package com.aol.cyclops.lambda.api;

import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

import lombok.Value;

public class AsSupplier {
	/**
	 * Create a Duck typing  based Supplier
	 * 
	 * 
	 * 
	 * @param toCoerce Object to convert into a Supplier, 
	 * 		must have a non-void get() method
	 * @return Supplier that delegates to the supplied object
	 */
	public static   Supplier asSupplier(Object toCoerce){
		return new CoercedSupplier(toCoerce,Arrays.asList("get","call"));
	}
	/**
	 * Create a Duck typing  based Supplier
	 * That returns the result of a call to the supplied method name
	 * 
	 * @param toCoerce Object to convert into a supplier
	 * @param method Method to call when Supplier.get() called
	 * @return Supplier that delegates to supplied object
	 */
	public static   Supplier asSupplier(Object toCoerce, String method){
		return new CoercedSupplier(toCoerce,Arrays.asList(method));
	}
	@Value
	public static class CoercedSupplier implements Gettable{
		private final Object dValue;
		private final List supplierMethodNames;
		public Object unwrap(){
			return dValue;
		}
		
		
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy