1 package org.opentrafficsim.kpi.sampling.data;
2
3 import java.util.Arrays;
4
5 import org.djutils.exceptions.Throw;
6 import org.opentrafficsim.kpi.interfaces.GtuData;
7 import org.opentrafficsim.kpi.sampling.SamplingException;
8
9
10
11
12
13
14
15
16
17
18
19
20 public abstract class ExtendedDataNumber<G extends GtuData> extends ExtendedDataType<Float, float[], float[], G>
21 {
22
23
24
25
26
27
28 public ExtendedDataNumber(final String id, final String description)
29 {
30 super(id, description, Float.class);
31 }
32
33
34 @Override
35 public float[] setValue(final float[] storage, final int index, final Float value)
36 {
37 float[] out;
38 if (index == storage.length)
39 {
40 int cap = (index - 1) + ((index - 1) >> 1);
41 out = Arrays.copyOf(storage, cap);
42 }
43 else
44 {
45 out = storage;
46 }
47 out[index] = value;
48 return out;
49 }
50
51
52 @Override
53 public Float getOutputValue(final float[] output, final int index) throws SamplingException
54 {
55 return output[index];
56 }
57
58
59 @Override
60 public Float getStorageValue(final float[] storage, final int index) throws SamplingException
61 {
62 Throw.when(index < 0 || index >= storage.length, SamplingException.class, "Index %d out of range.", index);
63 return storage[index];
64 }
65
66
67 @Override
68 public float[] initializeStorage()
69 {
70 return new float[10];
71 }
72
73
74 @Override
75 public float[] convert(final float[] storage, final int size)
76 {
77 return Arrays.copyOf(storage, size);
78 }
79
80
81 @Override
82 public Float parseValue(final String string)
83 {
84 return Float.valueOf(string);
85 }
86
87 }