Skip to content

Commit 0a56674

Browse files
committed
CSSTUDIO-3420 Change type from LinkedList<Double> to ArrayList<Double> for representing waveforms.
1 parent 5f707e4 commit 0a56674

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

app/display/waterfallplot/src/main/java/org/phoebus/applications/waterfallplotwidget/WaterfallPlotController.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717

1818
import java.time.Duration;
1919
import java.time.Instant;
20+
import java.util.ArrayList;
2021
import java.util.LinkedList;
2122
import java.util.List;
2223
import java.util.Optional;
23-
import java.util.SortedMap;
24-
import java.util.TreeMap;
2524
import java.util.concurrent.ConcurrentSkipListMap;
2625
import java.util.concurrent.atomic.AtomicBoolean;
27-
import java.util.concurrent.atomic.AtomicReference;
2826

2927
public class WaterfallPlotController {
3028

@@ -310,7 +308,7 @@ public synchronized void redraw(WaterfallPlotRuntime.PVData pvData) {
310308
previousT2[0] = Optional.of(t2);
311309

312310
LinkedList<Double> timeValuesLinkedList = new LinkedList<>();
313-
LinkedList<LinkedList<Double>> zValuesLinkedList = new LinkedList<>();
311+
LinkedList<ArrayList<Double>> zValuesLinkedList = new LinkedList<>();
314312
int waveformLength = 1;
315313

316314
double minFromPV = Double.NaN;
@@ -321,7 +319,7 @@ public synchronized void redraw(WaterfallPlotRuntime.PVData pvData) {
321319
minFromPV = waveformPVData.minFromPV().get();
322320
maxFromPV = waveformPVData.maxFromPV().get();
323321

324-
ConcurrentSkipListMap<Instant, LinkedList<Double>> instantToWaveform = waveformPVData.instantToValue();
322+
ConcurrentSkipListMap<Instant, ArrayList<Double>> instantToWaveform = waveformPVData.instantToValue();
325323
Instant startKey = instantToWaveform.ceilingKey(Instant.MIN);
326324
for (Instant t = t1.plus(stepsize); t.compareTo(t2) <= 0; t = t.plus(stepsize)) {
327325
timeValuesLinkedList.add(((double) t.toEpochMilli()) / 1000.0);
@@ -332,7 +330,7 @@ public synchronized void redraw(WaterfallPlotRuntime.PVData pvData) {
332330
else {
333331
var instant = instantToWaveform.floorKey(t);
334332

335-
LinkedList<Double> waveform = instantToWaveform.get(instant);
333+
ArrayList<Double> waveform = instantToWaveform.get(instant);
336334
waveformLength = Math.max(waveformLength, waveform.size());
337335
zValuesLinkedList.add(waveform);
338336
}
@@ -348,7 +346,7 @@ public synchronized void redraw(WaterfallPlotRuntime.PVData pvData) {
348346

349347
for (Instant t = t1.plus(stepsize); t.compareTo(t2) <= 0; t = t.plus(stepsize)) {
350348
timeValuesLinkedList.add(((double) t.toEpochMilli()) / 1000.0);
351-
LinkedList<Double> zValues = new LinkedList<>();
349+
ArrayList<Double> zValues = new ArrayList<>();
352350

353351
for (var pvNameAndInstantToValue : pvNameToInstantToValue) {
354352
String pvName = pvNameAndInstantToValue.getKey();
@@ -367,7 +365,7 @@ public synchronized void redraw(WaterfallPlotRuntime.PVData pvData) {
367365

368366
// Append the last value one more time in order to
369367
// fix the plotting when there is only 1 scalar PV:
370-
var lastValue = zValues.getLast();
368+
var lastValue = zValues.get(zValues.size()-1);
371369
zValues.add(lastValue);
372370

373371
zValuesLinkedList.add(zValues);
@@ -396,7 +394,7 @@ public synchronized void redraw(WaterfallPlotRuntime.PVData pvData) {
396394
}
397395

398396
for (int n = 0; n < zValuesLinkedList.size(); n++) {
399-
LinkedList<Double> waveformValues = zValuesLinkedList.get(n);
397+
ArrayList<Double> waveformValues = zValuesLinkedList.get(n);
400398

401399
for (int m = 0; m < waveformLength; m++) {
402400
double value;
@@ -435,7 +433,7 @@ public synchronized void redraw(WaterfallPlotRuntime.PVData pvData) {
435433
}
436434

437435
for (int n = 0; n < zValuesLinkedList.size(); n++) {
438-
LinkedList<Double> waveformValues = zValuesLinkedList.get(n);
436+
ArrayList<Double> waveformValues = zValuesLinkedList.get(n);
439437

440438
for (int m = 0; m < waveformLength; m++) {
441439
double value;

app/display/waterfallplot/src/main/java/org/phoebus/applications/waterfallplotwidget/WaterfallPlotRuntime.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.python.google.common.util.concurrent.AtomicDouble;
2323

2424
import java.time.Instant;
25+
import java.util.ArrayList;
2526
import java.util.LinkedList;
2627
import java.util.List;
2728
import java.util.concurrent.ConcurrentSkipListMap;
@@ -71,7 +72,7 @@ public sealed interface PVData permits WaveformPVData, ScalarPVsData {}
7172
// The type ConcurrentSkipListMap is used for the data points to allow for concurrent insertions and deletions:
7273
public record WaveformPVData (AtomicDouble minFromPV,
7374
AtomicDouble maxFromPV,
74-
ConcurrentSkipListMap<Instant, LinkedList<Double>> instantToValue) implements PVData {}
75+
ConcurrentSkipListMap<Instant, ArrayList<Double>> instantToValue) implements PVData {}
7576
public record ScalarPVsData (AtomicDouble minFromPV,
7677
AtomicDouble maxFromPV,
7778
LinkedList<Pair<String, ConcurrentSkipListMap<Instant, Double>>> pvNameToInstantToValue) implements PVData {}
@@ -144,7 +145,8 @@ else if (pvData instanceof WaveformPVData waveformPVData && pvNames.size() == 1)
144145
runtimePV.addListener((pv, vType) -> {
145146
if (vType instanceof VNumberArray vNumberArray) {
146147

147-
LinkedList<Double> waveform = new LinkedList<>();
148+
int size = vNumberArray.getData().size();
149+
ArrayList<Double> waveform = new ArrayList<>(size);
148150
for (int m = 0; m < vNumberArray.getData().size(); m++) {
149151
var value = vNumberArray.getData().getDouble(m);
150152
waveform.add(value);
@@ -160,7 +162,8 @@ else if (pvData instanceof WaveformPVData waveformPVData && pvNames.size() == 1)
160162
}
161163
} else if (vType instanceof VEnumArray vEnumArray) {
162164

163-
LinkedList<Double> waveform = new LinkedList<>();
165+
int size = vEnumArray.getData().size();
166+
ArrayList<Double> waveform = new ArrayList<>(size);
164167
ListNumber listNumber = vEnumArray.getIndexes();
165168
for (int m = 0; m < vEnumArray.getData().size(); m++) {
166169
var value = listNumber.getDouble(m);
@@ -188,7 +191,8 @@ else if (pvData instanceof WaveformPVData waveformPVData && pvNames.size() == 1)
188191
for (var vtype : values) {
189192
if (vtype instanceof VNumberArray vNumberArray) {
190193

191-
LinkedList<Double> waveform = new LinkedList<>();
194+
int size = vNumberArray.getData().size();
195+
ArrayList<Double> waveform = new ArrayList<>(size);
192196
for (int m = 0; m < vNumberArray.getData().size(); m++) {
193197
var value = vNumberArray.getData().getDouble(m);
194198
waveform.add(value);
@@ -198,7 +202,8 @@ else if (pvData instanceof WaveformPVData waveformPVData && pvNames.size() == 1)
198202
}
199203
else if (vtype instanceof VEnumArray vEnumArray) {
200204

201-
LinkedList<Double> waveform = new LinkedList<>();
205+
int size = vEnumArray.getData().size();
206+
ArrayList<Double> waveform = new ArrayList<>(size);
202207
ListNumber listNumber = vEnumArray.getIndexes();
203208
for (int m = 0; m < vEnumArray.getData().size(); m++) {
204209
var value = listNumber.getDouble(m);

0 commit comments

Comments
 (0)