1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.spring.env;
17
18 import java.io.File;
19
20 import org.kuali.common.util.Assert;
21
22 public final class EnvContext<T> {
23
24 public EnvContext(String key, Class<T> type) {
25 this(key, type, null);
26 }
27
28 public EnvContext(String key, Class<T> type, T defaultValue) {
29 Assert.noNulls(type);
30 Assert.noBlanks(key);
31 this.key = key;
32 this.type = type;
33 this.defaultValue = defaultValue;
34 }
35
36 private final String key;
37 private final Class<T> type;
38 private final T defaultValue;
39
40 public String getKey() {
41 return key;
42 }
43
44 public Class<T> getType() {
45 return type;
46 }
47
48 public T getDefaultValue() {
49 return defaultValue;
50 }
51
52 public static <T> EnvContext<T> newCtx(String key, Class<T> type, T defaultValue) {
53 return new EnvContext<T>(key, type, defaultValue);
54 }
55
56 public static EnvContext<String> newString(String key, String defaultValue) {
57 return newCtx(key, String.class, defaultValue);
58 }
59
60 public static EnvContext<Boolean> newBoolean(String key, Boolean defaultValue) {
61 return newCtx(key, Boolean.class, defaultValue);
62 }
63
64 public static EnvContext<Integer> newInteger(String key, Integer defaultValue) {
65 return newCtx(key, Integer.class, defaultValue);
66 }
67
68 public static EnvContext<File> newFile(String key, File defaultValue) {
69 return newCtx(key, File.class, defaultValue);
70 }
71
72 }