1 package org.opentrafficsim.core.egtf.typed;
2
3 import org.djunits.unit.FrequencyUnit;
4 import org.djunits.unit.LinearDensityUnit;
5 import org.djunits.unit.SpeedUnit;
6 import org.djunits.unit.Unit;
7 import org.djunits.value.Scalar;
8 import org.djunits.value.StorageType;
9 import org.djunits.value.ValueException;
10 import org.djunits.value.vdouble.matrix.DoubleMatrixInterface;
11 import org.djunits.value.vdouble.matrix.FrequencyMatrix;
12 import org.djunits.value.vdouble.matrix.LinearDensityMatrix;
13 import org.djunits.value.vdouble.matrix.SpeedMatrix;
14 import org.djunits.value.vdouble.scalar.Frequency;
15 import org.djunits.value.vdouble.scalar.LinearDensity;
16 import org.djunits.value.vdouble.scalar.Speed;
17 import org.opentrafficsim.core.egtf.Converter;
18 import org.opentrafficsim.core.egtf.Quantity;
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 public class TypedQuantity<U extends Unit<U>, T extends Scalar<U>, K extends DoubleMatrixInterface<U>> extends Quantity<T, K>
35 {
36
37 public static final Quantity<Speed, SpeedMatrix> SPEED = new TypedQuantity<>("Speed", true, new Converter<SpeedMatrix>()
38 {
39 @Override
40 public SpeedMatrix convert(final double[][] data)
41 {
42 try
43 {
44 return new SpeedMatrix(data, SpeedUnit.SI, StorageType.DENSE);
45 }
46 catch (ValueException exception)
47 {
48
49 throw new RuntimeException("Unexcepted exception: data is null when converting.", exception);
50 }
51 }
52 });
53
54
55 public static final Quantity<Frequency, FrequencyMatrix> FLOW = new TypedQuantity<>("Flow", new Converter<FrequencyMatrix>()
56 {
57 @Override
58 public FrequencyMatrix convert(final double[][] data)
59 {
60 try
61 {
62 return new FrequencyMatrix(data, FrequencyUnit.SI, StorageType.DENSE);
63 }
64 catch (ValueException exception)
65 {
66
67 throw new RuntimeException("Unexcepted exception: data is null when converting.", exception);
68 }
69 }
70 });
71
72
73 public static final Quantity<LinearDensity, LinearDensityMatrix> DENSITY =
74 new TypedQuantity<>("Density", new Converter<LinearDensityMatrix>()
75 {
76 @Override
77 public LinearDensityMatrix convert(final double[][] data)
78 {
79 try
80 {
81 return new LinearDensityMatrix(data, LinearDensityUnit.SI, StorageType.DENSE);
82 }
83 catch (ValueException exception)
84 {
85
86 throw new RuntimeException("Unexcepted exception: data is null when converting.", exception);
87 }
88 }
89 });
90
91
92
93
94
95
96 public TypedQuantity(final String name, final Converter<K> converter)
97 {
98 super(name, false, converter);
99 }
100
101
102
103
104
105
106
107 protected TypedQuantity(final String name, final boolean speed, final Converter<K> converter)
108 {
109 super(name, speed, converter);
110 }
111
112
113 @Override
114 public String toString()
115 {
116 return "TypedQuantity []";
117 }
118
119 }