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 public final class DefaultTestParameters
24 {
25
26
27
28
29 private DefaultTestParameters()
30 {
31
32 }
33
34
35
36
37
38 @SuppressWarnings("unchecked")
39 public static ParameterSet create()
40 {
41 ParameterSet params = new ParameterSet();
42
43
44 Set<Field> fields = ClassUtil.getAllFields(ParameterTypes.class);
45 try
46 {
47 for (Field field : fields)
48 {
49 try
50 {
51 if (ParameterTypeNumeric.class.isAssignableFrom(field.getType()))
52 {
53 field.setAccessible(true);
54 @SuppressWarnings("rawtypes")
55 ParameterTypeNumeric p = (ParameterTypeNumeric) field.get(ParameterTypes.class);
56 params.setParameter(p, p.getDefaultValue());
57 }
58 else if (ParameterTypeBoolean.class.equals(field.getType()))
59 {
60 field.setAccessible(true);
61 ParameterTypeBoolean p = (ParameterTypeBoolean) field.get(ParameterTypes.class);
62 params.setParameter(p, p.getDefaultValue());
63 }
64 else if (ParameterTypeDouble.class.equals(field.getType()))
65 {
66 field.setAccessible(true);
67 ParameterTypeDouble p = (ParameterTypeDouble) field.get(ParameterTypes.class);
68 params.setParameter(p, p.getDefaultValue());
69 }
70 else if (ParameterTypeInteger.class.equals(field.getType()))
71 {
72 field.setAccessible(true);
73 ParameterTypeInteger p = (ParameterTypeInteger) field.get(ParameterTypes.class);
74 params.setParameter(p, p.getDefaultValue());
75 }
76
77 }
78 catch (ParameterException pe)
79 {
80
81
82 }
83 }
84 }
85 catch (IllegalArgumentException iare)
86 {
87 iare.printStackTrace();
88 }
89 catch (IllegalAccessException iace)
90 {
91 iace.printStackTrace();
92 }
93 return params;
94 }
95
96 }