1 package org.opentrafficsim.core.egtf;
2
3
4
5
6
7
8
9
10
11
12
13
14 public class Quantity<T extends Number, K>
15 {
16
17 public static final Quantity<Double, double[][]> SPEED_SI = new Quantity<>("Speed", true, Converter.SI);
18
19
20 public static final Quantity<Double, double[][]> FLOW_SI = new Quantity<>("Flow", Converter.SI);
21
22
23 public static final Quantity<Double, double[][]> DENSITY_SI = new Quantity<>("Density", Converter.SI);
24
25
26 private final String name;
27
28
29 private final boolean speed;
30
31
32 private final Converter<K> converter;
33
34
35
36
37
38
39 public Quantity(final String name, final Converter<K> converter)
40 {
41 this(name, false, converter);
42 }
43
44
45
46
47
48
49
50 protected Quantity(final String name, final boolean speed, final Converter<K> converter)
51 {
52 this.name = name;
53 this.speed = speed;
54 this.converter = converter;
55 }
56
57
58
59
60
61
62 public static Quantity<?, double[][]> si(final String name)
63 {
64 return new SI<>(name);
65 }
66
67
68
69
70
71 public final String getName()
72 {
73 return this.name;
74 }
75
76
77
78
79
80 final boolean isSpeed()
81 {
82 return this.speed;
83 }
84
85
86
87
88
89
90 final K convert(final double[][] data)
91 {
92 return this.converter.convert(data);
93 }
94
95
96 @Override
97 public int hashCode()
98 {
99 final int prime = 31;
100 int result = 1;
101 result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
102 return result;
103 }
104
105
106 @Override
107 public boolean equals(final Object obj)
108 {
109 if (this == obj)
110 {
111 return true;
112 }
113 if (obj == null)
114 {
115 return false;
116 }
117 if (getClass() != obj.getClass())
118 {
119 return false;
120 }
121 Quantity<?, ?> other = (Quantity<?, ?>) obj;
122 if (this.name == null)
123 {
124 if (other.name != null)
125 {
126 return false;
127 }
128 }
129 else if (!this.name.equals(other.name))
130 {
131 return false;
132 }
133 return true;
134 }
135
136
137 @Override
138 public String toString()
139 {
140 return "Quantity [name=" + this.name + "]";
141 }
142
143
144
145
146
147 private static class SI<T extends Number> extends Quantity<T, double[][]>
148 {
149
150
151
152
153
154 SI(final String name)
155 {
156 super(name, Converter.SI);
157 }
158
159
160 @Override
161 public String toString()
162 {
163 return "SI []";
164 }
165
166 }
167
168 }