1 package cz.cuni.amis.pogamut.base.utils.guice; 2 3 import com.google.inject.Provider; 4 5 /** 6 * Simple implementation of the Guice {@link Provider} interface that allows you to 7 * set the value directly into the provider via {@link AdaptableProvider#set(Object)}. 8 * <p><p> 9 * This class is meant to be used by agent factories that has to preconfigure some providers 10 * before they can instantiate a new agent. 11 * 12 * @author Jimmy 13 * 14 * @param <T> 15 */ 16 public class AdaptableProvider<T> implements Provider<T> { 17 18 /** 19 * Current object the provider is holding/returning 20 */ 21 private T value; 22 23 /** 24 * Creates a provider with 'null' initial value. 25 */ 26 public AdaptableProvider() { 27 value = null; 28 } 29 30 /** 31 * Creates a provider with initial value. 32 * 33 * @param initialProvidedValue 34 */ 35 public AdaptableProvider(T initialProvidedValue) { 36 this.value = initialProvidedValue; 37 } 38 39 /** 40 * Sets the provided value to 'value'. 41 * @param value 42 */ 43 public void set(T value) { 44 this.value = value; 45 } 46 47 @Override 48 public T get() { 49 return value; 50 } 51 52 }