1 package org.djunits.generator;
2
3 import java.lang.reflect.Field;
4 import java.lang.reflect.Modifier;
5
6 import org.djunits.unit.Unit;
7
8
9
10
11
12
13
14
15
16
17
18
19 public final class GenerateStaticUNITS
20 {
21
22
23
24
25 private GenerateStaticUNITS()
26 {
27
28 }
29
30
31
32
33 public static void main(String[] args)
34 {
35 for (String className : Unit.STANDARD_UNITS)
36 {
37 if (!className.contains("Money") && !className.contains("Dimensionless"))
38 {
39 System.out.println();
40 System.out.println(
41 " /****************************************************************************************************************/");
42 String s =
43 " /******************************************************XX********************************************************/";
44 String cs = className.toUpperCase().replace("UNIT", "");
45 int i = cs.length() + 2;
46 cs = (i % 2 == 1) ? cs + " " : cs;
47 i = (i % 2 == 1) ? i + 2 : i;
48 i = i / 2;
49 s = s.replace("********************".substring(0, i - 1) + "X", " " + cs + " ");
50 s = s.replace("X********************".substring(0, i), "");
51 System.out.println(s);
52 System.out.println(
53 " /****************************************************************************************************************/");
54 System.out.println();
55
56 @SuppressWarnings("rawtypes")
57 Class c;
58 try
59 {
60 c = Class.forName("org.djunits.unit." + className);
61 }
62 catch (Exception exception)
63 {
64 System.exit(-1);
65 return;
66 }
67
68 int l = 0;
69 for (Field f : c.getFields())
70 {
71 if (Modifier.isPublic(f.getModifiers()) && Modifier.isStatic(f.getModifiers())
72 && Modifier.isFinal(f.getModifiers()) && !f.getName().equals("SI")
73 && !f.getName().equals("STANDARD_UNITS"))
74 {
75 String n = f.getName();
76 if (f.getName().contains("ELECTRONVOLT"))
77 {
78 n = cs.trim() + "_" + n;
79 }
80 l = Math.max(l, n.length());
81 }
82 }
83
84 for (Field f : c.getFields())
85 {
86 if (Modifier.isPublic(f.getModifiers()) && Modifier.isStatic(f.getModifiers())
87 && Modifier.isFinal(f.getModifiers()) && !f.getName().equals("SI")
88 && !f.getName().equals("STANDARD_UNITS"))
89 {
90 String n = f.getName();
91 if (f.getName().contains("ELECTRONVOLT"))
92 {
93 n = cs.trim() + "_" + n;
94 }
95
96 String un = (n + " ").substring(0, l);
97 System.out.println(
98 " " + c.getSimpleName() + " " + un + " = " + c.getSimpleName() + "." + f.getName() + ";");
99 }
100 }
101 }
102 }
103 }
104
105 }