1 package org.opentrafficsim.road;
2
3 import java.lang.reflect.Field;
4 import java.util.Set;
5
6 import org.opentrafficsim.base.parameters.ParameterException;
7 import org.opentrafficsim.base.parameters.ParameterSet;
8 import org.opentrafficsim.base.parameters.ParameterTypeBoolean;
9 import org.opentrafficsim.base.parameters.ParameterTypeDouble;
10 import org.opentrafficsim.base.parameters.ParameterTypeInteger;
11 import org.opentrafficsim.base.parameters.ParameterTypeNumeric;
12 import org.opentrafficsim.base.parameters.ParameterTypes;
13
14 import nl.tudelft.simulation.language.reflection.ClassUtil;
15
16
17
18
19
20
21
22
23
24
25 public final class DefaultTestParameters
26 {
27
28
29
30
31 private DefaultTestParameters()
32 {
33
34 }
35
36
37
38
39
40 @SuppressWarnings("unchecked")
41 public static ParameterSet create()
42 {
43 ParameterSet params = new ParameterSet();
44
45
46 Set<Field> fields = ClassUtil.getAllFields(ParameterTypes.class);
47 try
48 {
49 for (Field field : fields)
50 {
51 try
52 {
53 if (ParameterTypeNumeric.class.isAssignableFrom(field.getType()))
54 {
55 field.setAccessible(true);
56 @SuppressWarnings("rawtypes")
57 ParameterTypeNumeric p = (ParameterTypeNumeric) field.get(ParameterTypes.class);
58 params.setParameter(p, p.getDefaultValue());
59 }
60 else if (ParameterTypeBoolean.class.equals(field.getType()))
61 {
62 field.setAccessible(true);
63 ParameterTypeBoolean p = (ParameterTypeBoolean) field.get(ParameterTypes.class);
64 params.setParameter(p, p.getDefaultValue());
65 }
66 else if (ParameterTypeDouble.class.equals(field.getType()))
67 {
68 field.setAccessible(true);
69 ParameterTypeDouble p = (ParameterTypeDouble) field.get(ParameterTypes.class);
70 params.setParameter(p, p.getDefaultValue());
71 }
72 else if (ParameterTypeInteger.class.equals(field.getType()))
73 {
74 field.setAccessible(true);
75 ParameterTypeInteger p = (ParameterTypeInteger) field.get(ParameterTypes.class);
76 params.setParameter(p, p.getDefaultValue());
77 }
78
79 }
80 catch (ParameterException pe)
81 {
82
83
84 }
85 }
86 }
87 catch (IllegalArgumentException iare)
88 {
89 iare.printStackTrace();
90 }
91 catch (IllegalAccessException iace)
92 {
93 iace.printStackTrace();
94 }
95 return params;
96 }
97
98 }