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