Add convenience setters to TmdDataEvent
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfEvent.java
CommitLineData
8c8bf09f 1/*******************************************************************************
ce970a71 2 * Copyright (c) 2009, 2012 Ericsson
8c8bf09f 3 *
ce970a71 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
8c8bf09f
ASL
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
ce970a71 9 * Contributors: Francois Chouinard - Initial API and implementation
10 * Francois Chouinard - Updated as per TMF Event Model 1.0
8c8bf09f
ASL
11 *******************************************************************************/
12
6c13869b 13package org.eclipse.linuxtools.tmf.core.event;
8c8bf09f 14
6c13869b 15import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
2c8610f7 16
8c8bf09f
ASL
17/**
18 * <b><u>TmfEvent</u></b>
19 * <p>
1f506a43 20 * The basic event structure in the TMF. In its canonical form, an event has:
8c8bf09f 21 * <ul>
ce970a71 22 * <li>a normalized timestamp
23 * <li>a source (reporter)
24 * <li>a type
25 * <li>a content
8c8bf09f
ASL
26 * </ul>
27 * For convenience, a free-form reference field is also provided. It could be
28 * used as e.g. a location marker in the event stream to distinguish between
29 * otherwise identical events.
28b94d61 30 *
ce970a71 31 * Notice that for performance reasons TmfEvent is NOT immutable. If a copy of
32 * the event is needed, use the copy constructor.
8c8bf09f 33 */
ce970a71 34public class TmfEvent extends TmfDataEvent implements Cloneable {
12c155f5 35
cbd4ad82 36 // ------------------------------------------------------------------------
8c8bf09f 37 // Attributes
cbd4ad82 38 // ------------------------------------------------------------------------
8c8bf09f 39
ce970a71 40 protected TmfTimestamp fTimestamp;
28b94d61 41
cbd4ad82 42 // ------------------------------------------------------------------------
8c8bf09f 43 // Constructors
cbd4ad82 44 // ------------------------------------------------------------------------
8c8bf09f 45
2c8610f7 46 /**
ce970a71 47 * Default constructor
2c8610f7 48 */
ce970a71 49 public TmfEvent() {
2c8610f7
FC
50 }
51
4bf17f4a 52 /**
ce970a71 53 * Full constructor
54 *
4bf17f4a 55 * @param trace the parent trace
ce970a71 56 * @param rank the vent rank (in the trace)
57 * @param timestamp the event timestamp
58 * @param source the event source
4bf17f4a 59 * @param type the event type
ce970a71 60 * @param reference the event reference
12c155f5 61 */
99005796 62 public TmfEvent(ITmfTrace<?> trace, long rank, TmfTimestamp timestamp, String source,
5179fc01
FC
63 TmfEventType type, String reference)
64 {
ce970a71 65 super(trace, rank, source, type, null, reference);
66 fTimestamp = timestamp;
12c155f5 67 }
1f506a43 68
12c155f5 69 /**
ce970a71 70 * Constructor - no rank
12c155f5 71 */
99005796 72 public TmfEvent(ITmfTrace<?> parentTrace, TmfTimestamp timestamp, String source,
5179fc01
FC
73 TmfEventType type, String reference)
74 {
ce970a71 75 this(parentTrace, -1, timestamp, source, type, reference);
12c155f5 76 }
8c8bf09f 77
12c155f5 78 /**
ce970a71 79 * Constructor - no trace, no rank
12c155f5 80 */
4641c2f7 81 public TmfEvent(TmfTimestamp timestamp, String source, TmfEventType type, String reference) {
ce970a71 82 this(null, -1, timestamp, source, type, reference);
12c155f5 83 }
8c8bf09f 84
12c155f5 85 /**
ce970a71 86 * Copy constructor
87 *
88 * @param event the original event
12c155f5 89 */
ce970a71 90 public TmfEvent(TmfEvent event) {
91 super(event);
92 fTimestamp = event.fTimestamp != null ? new TmfTimestamp(event.fTimestamp) : null;
12c155f5 93 }
8c8bf09f 94
ce970a71 95 // ------------------------------------------------------------------------
96 // ITmfEvent
97 // ------------------------------------------------------------------------
8c8bf09f 98
12c155f5 99 /**
ce970a71 100 * @return the effective event timestamp
12c155f5 101 */
ce970a71 102 public TmfTimestamp getTimestamp() {
103 return fTimestamp;
12c155f5 104 }
1f506a43 105
ce970a71 106 // ------------------------------------------------------------------------
107 // Cloneable
108 // ------------------------------------------------------------------------
cbd4ad82 109
ce970a71 110 @Override
111 public TmfEvent clone() {
112 TmfEvent clone = null;
113 clone = (TmfEvent) super.clone();
114 clone.fTimestamp = fTimestamp != null ? fTimestamp.clone() : null;
115 return clone;
12c155f5 116 }
c76c54bb 117
12c155f5 118 // ------------------------------------------------------------------------
cbd4ad82
FC
119 // Object
120 // ------------------------------------------------------------------------
28b94d61 121
12c155f5 122 @Override
cbd4ad82 123 public int hashCode() {
ce970a71 124 final int prime = 31;
125 int result = super.hashCode();
126 result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
cbd4ad82
FC
127 return result;
128 }
129
130 @Override
ce970a71 131 public boolean equals(Object obj) {
132 if (this == obj)
133 return true;
134 if (!super.equals(obj))
12c155f5 135 return false;
ce970a71 136 if (getClass() != obj.getClass())
137 return false;
138 TmfEvent other = (TmfEvent) obj;
139 if (fTimestamp == null) {
140 if (other.fTimestamp != null)
0c841e0f 141 return false;
ce970a71 142 } else if (!fTimestamp.equals(other.fTimestamp))
143 return false;
0c841e0f 144 return true;
cbd4ad82 145 }
28b94d61 146
12c155f5 147 @Override
3b38ea61 148 @SuppressWarnings("nls")
12c155f5 149 public String toString() {
ce970a71 150 return "TmfEvent [fTimestamp=" + fTimestamp + ", fTrace=" + fTrace + ", fRank=" + fRank
151 + ", fSource=" + fSource + ", fType=" + fType + ", fContent=" + fContent
152 + ", fReference=" + fReference + "]";
12c155f5 153 }
f9673903 154
8c8bf09f 155}
This page took 0.073919 seconds and 5 git commands to generate.