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