1 /*******************************************************************************
2 * Copyright (c) 2015, 2016 EfficiOS Inc., Alexandre Montplaisir
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.module
;
12 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
14 import java
.util
.List
;
15 import java
.util
.Optional
;
16 import java
.util
.stream
.Collectors
;
18 import org
.eclipse
.jdt
.annotation
.NonNull
;
19 import org
.eclipse
.jdt
.annotation
.Nullable
;
20 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.types
.LamiData
;
21 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.types
.LamiTimeRange
;
22 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.types
.LamiTimestamp
;
24 import com
.google
.common
.collect
.ImmutableList
;
27 * Entry of a LAMI output. Usually corresponds to one row in a JSON LAMI table
30 * @author Alexandre Montplaisir
32 public class LamiTableEntry
{
34 private final List
<LamiData
> fValues
;
39 * @param values Values contained in this row
41 public LamiTableEntry(List
<LamiData
> values
) {
42 fValues
= checkNotNull(ImmutableList
.copyOf(values
));
46 * Get the value at a given index
50 * @return The value at this index
52 public LamiData
getValue(int index
) {
53 return fValues
.get(index
);
57 * Get the time range represented by this row.
59 * If more than one exists, one of them (usually the first) is returned.
61 * If there are no time ranges in this row, null is returned.
63 * @return The time range of this row
65 public @Nullable LamiTimeRange
getCorrespondingTimeRange() {
67 * If there is one or more time range(s) in the values, return the first
68 * one we find directly.
70 Optional
<LamiTimeRange
> oTimerange
= fValues
.stream()
71 .filter(data
-> (data
instanceof LamiTimeRange
))
72 .<@NonNull LamiTimeRange
> map(data
-> (LamiTimeRange
) data
)
74 if (oTimerange
.isPresent()) {
75 return oTimerange
.get();
78 /* Look for individual timestamps instead */
79 List
<LamiTimestamp
> timestamps
= fValues
.stream()
80 .filter(data
-> (data
instanceof LamiTimestamp
))
81 .<@NonNull LamiTimestamp
> map(data
-> (LamiTimestamp
) data
)
82 .collect(Collectors
.toList());
84 if (timestamps
.size() > 1) {
85 /* We can try using the first two timestamps to create a range (making sure it's valid) */
86 long first
= timestamps
.get(0).getValue();
87 long second
= timestamps
.get(1).getValue();
88 if (second
>= first
) {
89 return new LamiTimeRange(first
, second
);
93 if (!timestamps
.isEmpty()) {
94 /* If there is only one timestamp, use it to create a punctual range */
95 long ts
= timestamps
.get(0).getValue();
96 return new LamiTimeRange(ts
, ts
);
99 /* Didn't find any timestamp we can't use */
This page took 0.035198 seconds and 5 git commands to generate.