tmf: Add configurable marker event source
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / internal / tmf / core / markers / SubMarker.java
1 /*******************************************************************************
2 * Copyright (c) 2017 Ericsson
3 *
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 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.internal.tmf.core.markers;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import com.google.common.collect.Range;
19 import com.google.common.collect.RangeSet;
20
21 /**
22 * Model element for configurable sub-marker.
23 */
24 public abstract class SubMarker extends Marker {
25
26 /**
27 * Private constructor.
28 *
29 * @param name
30 * the name
31 * @param color
32 * the color
33 */
34 private SubMarker(String name, String color) {
35 super(name, color);
36 }
37
38 /**
39 * Subclass for sub-marker evenly split into segments of equal length.
40 *
41 */
42 public static class SplitMarker extends SubMarker {
43
44 private final String fLabel;
45 private final String fId;
46 private final Range<Long> fRange;
47 private final RangeSet<Long> fIndexRange;
48
49 /**
50 * Constructor
51 *
52 * @param name
53 * the name
54 * @param label
55 * the label
56 * @param id
57 * the id
58 * @param color
59 * the color
60 * @param range
61 * the range
62 * @param indexRange
63 * the index range
64 */
65 public SplitMarker(String name, String label, String id, String color, Range<Long> range, RangeSet<Long> indexRange) {
66 super(name, color);
67 fLabel = label;
68 fId = id;
69 fRange = range;
70 fIndexRange = indexRange;
71 }
72
73 /**
74 * @return the label
75 */
76 public String getLabel() {
77 return fLabel;
78 }
79
80 /**
81 * @return the id
82 */
83 public String getId() {
84 return fId;
85 }
86
87 /**
88 * @return the range
89 */
90 public Range<Long> getRange() {
91 return fRange;
92 }
93
94 /**
95 * @return the index range
96 */
97 public RangeSet<Long> getIndexRange() {
98 return fIndexRange;
99 }
100 }
101
102 /**
103 * Subclass for a sub-marker divided into segments of specified weighted lengths.
104 *
105 */
106 public static class WeightedMarker extends SubMarker {
107
108 private final List<MarkerSegment> fSegments;
109 private long fTotalLength = 0;
110
111 /**
112 * Constructor
113 *
114 * @param name
115 * the name
116 */
117 public WeightedMarker(String name) {
118 super(name, null);
119 fSegments = new ArrayList<>();
120 }
121
122 /**
123 * @return the segments
124 */
125 public List<MarkerSegment> getSegments() {
126 return fSegments;
127 }
128
129 /**
130 * Add a segment.
131 *
132 * @param segment
133 * the segment
134 */
135 public void addSegment(MarkerSegment segment) {
136 fSegments.add(segment);
137 fTotalLength += segment.getLength();
138 }
139
140 /**
141 * Get the total length of all segments
142 *
143 * @return the total length
144 */
145 public long getTotalLength() {
146 return fTotalLength;
147 }
148 }
149 }
This page took 0.036223 seconds and 5 git commands to generate.