ctf: make StreamInputPacketIndexEntry not Comparable
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / internal / ctf / core / trace / StreamInputPacketIndexEntry.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.internal.ctf.core.trace;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 /**
19 * <b><u>StreamInputPacketIndexEntry</u></b>
20 * <p>
21 * Represents an entry in the index of event packets.
22 */
23 public class StreamInputPacketIndexEntry {
24
25 // ------------------------------------------------------------------------
26 // Attributes
27 // ------------------------------------------------------------------------
28
29 /**
30 * Offset of the packet in the file, in bytes
31 */
32 private final long fOffsetBytes;
33
34 /**
35 * Offset of the data in the packet, in bits
36 */
37 private long fDataOffsetBits = 0;
38
39 /**
40 * Packet size, in bits
41 */
42 private long fPacketSizeBits = 0;
43
44 /**
45 * Content size, in bits
46 */
47 private long fContentSizeBits = 0;
48
49 /**
50 * Begin timestamp
51 */
52 private long fTimestampBegin = 0;
53
54 /**
55 * End timestamp
56 */
57 private long fTimestampEnd = 0;
58
59 /**
60 * How many lost events are there?
61 */
62 private long fLostEvents = 0;
63
64 /**
65 * Which target is being traced
66 */
67 private String fTarget;
68 private long fTargetID;
69
70 /**
71 * Attributes of this index entry
72 */
73 private final Map<String, Object> fAttributes = new HashMap<>();
74
75 // ------------------------------------------------------------------------
76 // Constructors
77 // ------------------------------------------------------------------------
78
79 /**
80 * Constructs an index entry.
81 *
82 * @param offset
83 * The offset of the packet in the file, in bytes.
84 */
85
86 public StreamInputPacketIndexEntry(long offset) {
87 fOffsetBytes = offset;
88 }
89
90 // ------------------------------------------------------------------------
91 // Operations
92 // ------------------------------------------------------------------------
93
94 /**
95 * Returns whether the packet includes (inclusively) the given timestamp in
96 * the begin-end timestamp range.
97 *
98 * @param ts
99 * The timestamp to check.
100 * @return True if the packet includes the timestamp.
101 */
102 boolean includes(long ts) {
103 return (ts >= fTimestampBegin) && (ts <= fTimestampEnd);
104 }
105
106 @Override
107 public String toString() {
108 return "StreamInputPacketIndexEntry [offsetBytes=" + fOffsetBytes //$NON-NLS-1$
109 + ", timestampBegin=" + fTimestampBegin + ", timestampEnd=" //$NON-NLS-1$ //$NON-NLS-2$
110 + fTimestampEnd + "]"; //$NON-NLS-1$
111 }
112
113 // ------------------------------------------------------------------------
114 // Getters and Setters
115 // ------------------------------------------------------------------------
116
117 /**
118 * @return the offsetBytes
119 */
120 public long getOffsetBytes() {
121 return fOffsetBytes;
122 }
123
124 /**
125 * @return the dataOffsetBits
126 */
127 public long getDataOffsetBits() {
128 return fDataOffsetBits;
129 }
130
131 /**
132 * @param dataOffsetBits
133 * the dataOffsetBits to set
134 */
135 public void setDataOffsetBits(long dataOffsetBits) {
136 fDataOffsetBits = dataOffsetBits;
137 }
138
139 /**
140 * @return the packetSizeBits
141 */
142 public long getPacketSizeBits() {
143 return fPacketSizeBits;
144 }
145
146 /**
147 * @param packetSizeBits
148 * the packetSizeBits to set
149 */
150 public void setPacketSizeBits(long packetSizeBits) {
151 fPacketSizeBits = packetSizeBits;
152 }
153
154 /**
155 * @return the contentSizeBits
156 */
157 public long getContentSizeBits() {
158 return fContentSizeBits;
159 }
160
161 /**
162 * @param contentSizeBits
163 * the contentSizeBits to set
164 */
165 public void setContentSizeBits(long contentSizeBits) {
166 fContentSizeBits = contentSizeBits;
167 }
168
169 /**
170 * @return the timestampBegin
171 */
172 public long getTimestampBegin() {
173 return fTimestampBegin;
174 }
175
176 /**
177 * @param timestampBegin
178 * the timestampBegin to set
179 */
180 public void setTimestampBegin(long timestampBegin) {
181 fTimestampBegin = timestampBegin;
182 }
183
184 /**
185 * @return the timestampEnd
186 */
187 public long getTimestampEnd() {
188 return fTimestampEnd;
189 }
190
191 /**
192 * @param timestampEnd
193 * the timestampEnd to set
194 */
195 public void setTimestampEnd(long timestampEnd) {
196 fTimestampEnd = timestampEnd;
197 }
198
199 /**
200 * @return the lostEvents in this packet
201 */
202 public long getLostEvents() {
203 return fLostEvents;
204 }
205
206 /**
207 * @param lostEvents
208 * the lostEvents to set
209 */
210 public void setLostEvents(long lostEvents) {
211 fLostEvents = lostEvents;
212 }
213
214 /**
215 * Add an attribute to this index entry
216 *
217 * @param field
218 * The name of the attribute
219 * @param value
220 * The value to insert
221 */
222 public void addAttribute(String field, Object value) {
223 fAttributes.put(field, value);
224 }
225
226 /**
227 * Retrieve the value of an existing attribute
228 *
229 * @param field
230 * The name of the attribute
231 * @return The value that was stored, or null if it wasn't found
232 */
233 public Object lookupAttribute(String field) {
234 return fAttributes.get(field);
235 }
236
237 /**
238 * @return The target that is being traced
239 */
240 public String getTarget() {
241 return fTarget;
242 }
243
244 /**
245 * Assign a target to this index entry
246 *
247 * @param target
248 * The target to assign
249 */
250 public void setTarget(String target) {
251 fTarget = target;
252 fTargetID = Integer.parseInt(target.replaceAll("[\\D]", "")); //$NON-NLS-1$ //$NON-NLS-2$ // slow
253 }
254
255 /**
256 * @return The ID of the target
257 */
258 public long getTargetId() {
259 return fTargetID;
260 }
261 }
This page took 0.043636 seconds and 5 git commands to generate.