1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.event
;
16 * <b><u>TmfEventContent</u></b>
20 public class TmfEventContent
implements Cloneable
{
22 // ------------------------------------------------------------------------
24 // ------------------------------------------------------------------------
26 protected TmfEvent fParentEvent
;
27 protected Object fRawContent
;
28 protected Object
[] fFields
;
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
35 * @param parent the parent event (owner)
36 * @param content the raw content
38 public TmfEventContent(TmfEvent parent
, Object content
) {
39 fParentEvent
= parent
;
40 fRawContent
= content
;
44 * @param other the original event content
46 public TmfEventContent(TmfEventContent other
) {
48 throw new IllegalArgumentException();
49 fParentEvent
= other
.fParentEvent
;
50 fRawContent
= other
.fRawContent
;
51 fFields
= other
.fFields
;
54 @SuppressWarnings("unused")
55 private TmfEventContent() {
56 throw new AssertionError();
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
64 * @return the parent (containing) event
66 public TmfEvent
getEvent() {
71 * @return the event type
73 public TmfEventType
getType() {
74 return fParentEvent
.getType();
78 * @return the raw content
80 public Object
getContent() {
85 * Returns the list of fields in the same order as TmfEventType.getLabels()
87 * @return the ordered set of fields (optional fields might be null)
89 public Object
[] getFields() {
90 if (fFields
== null) {
97 * @param id the field id
98 * @return the corresponding field
99 * @throws TmfNoSuchFieldException
101 public Object
getField(String id
) throws TmfNoSuchFieldException
{
102 if (fFields
== null) {
105 return fFields
[getType().getFieldIndex(id
)];
109 * @param n the field index as per TmfEventType.getLabels()
110 * @return the corresponding field (null if non-existing)
112 public Object
getField(int n
) {
113 if (fFields
== null) {
116 if (n
>= 0 && n
< fFields
.length
)
122 // ------------------------------------------------------------------------
124 // ------------------------------------------------------------------------
129 public void setEvent(TmfEvent event
) {
130 fParentEvent
= event
;
134 * Parse the content into fields. By default, a single field (the raw
135 * content) is returned.
136 * Should be overridden.
138 protected void parseContent() {
139 fFields
= new Object
[1];
140 fFields
[0] = fRawContent
;
143 // ------------------------------------------------------------------------
145 // ------------------------------------------------------------------------
148 public int hashCode() {
150 result
= 37 * result
+ ((fParentEvent
!= null) ? fParentEvent
.hashCode() : 0);
151 result
= 37 * result
+ ((fRawContent
!= null) ? fRawContent
.hashCode() : 0);
156 public boolean equals(Object other
) {
157 if (!(other
instanceof TmfEventContent
))
159 TmfEventContent o
= (TmfEventContent
) other
;
160 return fRawContent
.equals(o
.fRawContent
);
164 @SuppressWarnings("nls")
165 public String
toString() {
166 Object
[] fields
= getFields();
167 StringBuilder result
= new StringBuilder("[TmfEventContent(");
168 for (int i
= 0; i
< fields
.length
; i
++) {
169 if (i
> 0) result
.append(",");
170 result
.append(fields
[i
]);
173 return result
.toString();
177 public TmfEventContent
clone() {
178 TmfEventContent clone
= null;
180 clone
= (TmfEventContent
) super.clone();
181 clone
.fParentEvent
= fParentEvent
;
182 clone
.fRawContent
= fRawContent
;
183 clone
.fFields
= fFields
;
185 catch (CloneNotSupportedException e
) {