public
Created

  • Download Gist
model.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
package tmp;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
public class Model {
public Map<String, Class> parameterTypes;
public Map<String, Object> defaultValues;
public Map<String, Object> currentValues;
public Model(List<IGenerator> generators) {
parameterTypes = new HashMap<String, Class>();
defaultValues = new HashMap<String, Object>();
currentValues = new HashMap<String, Object>();
for (IGenerator generator : generators) {
for (String parameterName : generator.getParameterNames()) {
register(parameterName,
generator.getParameterType(parameterName),
generator.getParameterDefault(parameterName));
}
}
}
public void register(String parameter, Class type, Object defaultValue) {
parameterTypes.put(parameter, type);
defaultValues.put(parameter, defaultValue);
}
public Object get(String parameterName) {
if (currentValues.containsKey(parameterName)) {
return currentValues.get(parameterName);
} else {
return defaultValues.get(parameterName);
}
}
public void set(String parameterName, Object value) throws Exception {
Class requiredClass = parameterTypes.get(parameterName);
if (value.getClass() == requiredClass) {
currentValues.put(parameterName, value);
} else {
throw new Exception();
}
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.