Monster fix: TMF model update + corresponding LTTng adaptations + JUnits
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / event / TmfEventContent.java
1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.event;
14
15
16 /**
17 * <b><u>TmfEventContent</u></b>
18 * <p>
19 * The event content.
20 */
21 public class TmfEventContent implements Cloneable {
22
23 // ========================================================================
24 // Attributes
25 // ========================================================================
26
27 protected TmfEvent fParentEvent = null;
28 protected Object fRawContent = null;
29 protected Object[] fFields = null;
30
31 // ========================================================================
32 // Constructors
33 // ========================================================================
34
35 /**
36 * @param parent
37 * @param content
38 */
39 public TmfEventContent(TmfEvent parent, Object content) {
40 fParentEvent = parent;
41 fRawContent = content;
42 }
43
44 /**
45 * @param other
46 */
47 public TmfEventContent(TmfEventContent other) {
48 assert(other != null);
49 fParentEvent = other.fParentEvent;
50 fRawContent = other.fRawContent;
51 fFields = other.fFields;
52 }
53
54 @SuppressWarnings("unused")
55 private TmfEventContent() {
56 }
57
58 // ========================================================================
59 // Accessors
60 // ========================================================================
61
62 /**
63 * @return the parent (containing) event
64 */
65 public TmfEvent getEvent() {
66 return fParentEvent;
67 }
68
69 /**
70 * @return the event type
71 */
72 public TmfEventType getType() {
73 return fParentEvent.getType();
74 }
75
76 /**
77 * @return the raw content
78 */
79 public Object getContent() {
80 return fRawContent;
81 }
82
83 /**
84 * Returns the list of fields in the same order as TmfEventType.getLabels()
85 *
86 * @return the ordered set of fields (optional fields might be null)
87 */
88 public Object[] getFields() {
89 if (fFields == null) {
90 parseContent();
91 }
92 return fFields;
93 }
94
95 /**
96 * @param id
97 * @return
98 */
99 public Object getField(String id) throws TmfNoSuchFieldException {
100 if (fFields == null) {
101 parseContent();
102 }
103 return fFields[getType().getFieldIndex(id)];
104 }
105
106 /**
107 * @param n
108 * @return
109 */
110 public Object getField(int n) {
111 if (fFields == null) {
112 parseContent();
113 }
114 if (n >= 0 && n < fFields.length)
115 return fFields[n];
116 return null;
117 }
118
119 // ========================================================================
120 // Operators
121 // ========================================================================
122
123 /**
124 * Should be overridden (all fields are null by default)
125 */
126 protected void parseContent() {
127 fFields = new Object[1];
128 fFields[0] = fRawContent;
129 }
130
131 /**
132 * Clone: shallow copy by default; override for deep copy.
133 */
134 @Override
135 public TmfEventContent clone() {
136 return new TmfEventContent(this);
137 }
138
139 @Override
140 public String toString() {
141 Object[] fields = getFields();
142 String result = "[TmfEventContent(";
143 for (int i = 0; i < fields.length; i++) {
144 result += fields[i].toString() + ",";
145 }
146 result += ")]";
147
148 return result;
149 }
150
151 }
This page took 0.034113 seconds and 6 git commands to generate.