View Javadoc

1   package org.kuali.common.util.spring.env;
2   
3   import org.kuali.common.util.Assert;
4   
5   public final class EnvContext<T> {
6   
7   	public EnvContext(String key, Class<T> type) {
8   		this(key, type, null);
9   	}
10  
11  	public EnvContext(String key, Class<T> type, T defaultValue) {
12  		Assert.noNulls(type);
13  		Assert.noBlanks(key);
14  		this.key = key;
15  		this.type = type;
16  		this.defaultValue = defaultValue;
17  	}
18  
19  	private final String key;
20  	private final Class<T> type;
21  	private final T defaultValue;
22  
23  	public String getKey() {
24  		return key;
25  	}
26  
27  	public Class<T> getType() {
28  		return type;
29  	}
30  
31  	public T getDefaultValue() {
32  		return defaultValue;
33  	}
34  
35  	public static <T> EnvContext<T> newCtx(String key, Class<T> type, T defaultValue) {
36  		return new EnvContext<T>(key, type, defaultValue);
37  	}
38  
39  	public static EnvContext<String> newString(String key, String defaultValue) {
40  		return newCtx(key, String.class, defaultValue);
41  	}
42  
43  	public static EnvContext<Boolean> newBoolean(String key, Boolean defaultValue) {
44  		return newCtx(key, Boolean.class, defaultValue);
45  	}
46  
47  	public static EnvContext<Integer> newInteger(String key, Integer defaultValue) {
48  		return newCtx(key, Integer.class, defaultValue);
49  	}
50  
51  }