0822458b1edc5b117271182da1642e2cdc01a600
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / stubs / org / eclipse / tracecompass / tmf / tests / stubs / trace / text / SyslogEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 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 * Bernd Hufmann - Initial API and implementation
11 * Patrick Tasse - Move field declarations to trace
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.tests.stubs.trace.text;
15
16 import java.util.List;
17
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
20 import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
21 import org.eclipse.tracecompass.tmf.core.event.collapse.ITmfCollapsibleEvent;
22 import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite;
23 import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfSourceLookup;
24 import org.eclipse.tracecompass.tmf.core.event.lookup.TmfCallsite;
25 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
26 import org.eclipse.tracecompass.tmf.core.trace.text.TextTraceEvent;
27 import org.eclipse.tracecompass.tmf.core.trace.text.TextTraceEventContent;
28 import org.eclipse.tracecompass.tmf.tests.stubs.trace.text.SyslogTrace.Field;
29
30 /**
31 * System log trace implementation of TmfEvent.
32 */
33 public class SyslogEvent extends TextTraceEvent implements ITmfCollapsibleEvent, ITmfSourceLookup {
34
35 /**
36 * Default constructor
37 */
38 public SyslogEvent() {
39 super(null, null, new SyslogEventType(), null);
40 }
41
42 /**
43 * Copy constructor
44 *
45 * @param other
46 * the event to copy
47 *
48 */
49 public SyslogEvent(final @NonNull SyslogEvent other) {
50 super(other);
51 }
52
53 /**
54 * Full Constructor
55 *
56 * @param parentTrace
57 * the parent trace
58 * @param timestamp
59 * the event timestamp
60 * @param type
61 * the event type
62 * @param content
63 * the event content (payload)
64 */
65 public SyslogEvent(SyslogTrace parentTrace, final ITmfTimestamp timestamp,
66 final ITmfEventType type, final TextTraceEventContent content) {
67 super(parentTrace, timestamp, type, content);
68 }
69
70 @Override
71 public boolean isCollapsibleWith(ITmfEvent otherEvent) {
72 if (this == otherEvent) {
73 return true;
74 }
75
76 if (!(otherEvent instanceof SyslogEvent)) {
77 return false;
78 }
79
80 final SyslogEvent other = (SyslogEvent) otherEvent;
81
82 if (!getTrace().equals(other.getTrace())) {
83 return false;
84 }
85
86 if (getType() == null) {
87 if (other.getType() != null) {
88 return false;
89 }
90 } else if (!getType().equals(other.getType())) {
91 return false;
92 }
93
94 TextTraceEventContent content = this.getContent();
95 TextTraceEventContent otherContent = other.getContent();
96
97 if (content == null) {
98 if (otherContent != null) {
99 return false;
100 }
101 return true;
102 }
103
104 if (otherContent == null) {
105 return false;
106 }
107
108 List<TextTraceEventContent> fields = content.getFields();
109 List<TextTraceEventContent> otherFields = otherContent.getFields();
110 int size = fields.size();
111
112 if (size != otherFields.size()) {
113 return false;
114 }
115
116 // At i = 0 the timestamp is stored and needs to be bypassed
117 for (int i = 1; i < size; i++) {
118 if (!fields.get(i).equals(otherFields.get(i))) {
119 return false;
120 }
121 }
122 return true;
123 }
124
125 @Override
126 public ITmfCallsite getCallsite() {
127 if (getContent() != null) {
128 long lineNo = 0;
129 try {
130 lineNo = Long.valueOf((String) getContent().getField(Field.LINE).getValue());
131 } catch (NumberFormatException e) {
132 // ignore
133 }
134 return new TmfCallsite((String) getContent().getField(Field.FILE).getValue(), null, lineNo);
135 }
136 return null;
137 }
138
139 }
This page took 0.033556 seconds and 4 git commands to generate.