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
;
17 * <b><u>TmfEventContent</u></b>
21 public class TmfEventContent
{
23 // ------------------------------------------------------------------------
25 // ------------------------------------------------------------------------
27 protected TmfEvent fParentEvent
;
28 protected Object fRawContent
;
29 protected Object
[] fFields
;
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
36 * @param parent the parent event (owner)
37 * @param content the raw content
39 public TmfEventContent(TmfEvent parent
, Object content
) {
40 fParentEvent
= parent
;
41 fRawContent
= content
;
45 * @param other the original event content
47 public TmfEventContent(TmfEventContent other
) {
49 throw new IllegalArgumentException();
50 fParentEvent
= other
.fParentEvent
;
51 fRawContent
= other
.fRawContent
;
52 fFields
= other
.fFields
;
55 @SuppressWarnings("unused")
56 private TmfEventContent() {
57 throw new AssertionError();
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
65 * @return the parent (containing) event
67 public TmfEvent
getEvent() {
72 * @return the event type
74 public TmfEventType
getType() {
75 return fParentEvent
.getType();
79 * @return the raw content
81 public Object
getContent() {
86 * Returns the list of fields in the same order as TmfEventType.getLabels()
88 * @return the ordered set of fields (optional fields might be null)
90 public Object
[] getFields() {
91 if (fFields
== null) {
98 * @param id the field id
99 * @return the corresponding field
100 * @throws TmfNoSuchFieldException
102 public Object
getField(String id
) throws TmfNoSuchFieldException
{
103 if (fFields
== null) {
106 return fFields
[getType().getFieldIndex(id
)];
110 * @param n the field index as per TmfEventType.getLabels()
111 * @return the corresponding field (null if non-existing)
113 public Object
getField(int n
) {
114 if (fFields
== null) {
117 if (n
>= 0 && n
< fFields
.length
)
123 // ------------------------------------------------------------------------
125 // ------------------------------------------------------------------------
128 * Parse the content into fields. By default, a single field (the raw
129 * content) is returned.
130 * Should be overridden.
132 protected void parseContent() {
133 fFields
= new Object
[1];
134 fFields
[0] = fRawContent
;
137 // ------------------------------------------------------------------------
139 // ------------------------------------------------------------------------
142 public int hashCode() {
144 result
= 37 * result
+ ((fParentEvent
!= null) ? fParentEvent
.hashCode() : 0);
145 result
= 37 * result
+ ((fRawContent
!= null) ? fRawContent
.hashCode() : 0);
150 public boolean equals(Object other
) {
151 if (!(other
instanceof TmfEventContent
))
153 TmfEventContent o
= (TmfEventContent
) other
;
154 return fRawContent
.equals(o
.fRawContent
);
158 public String
toString() {
159 Object
[] fields
= getFields();
160 StringBuilder result
= new StringBuilder("[TmfEventContent(");
161 for (int i
= 0; i
< fields
.length
; i
++) {
162 if (i
> 0) result
.append(",");
163 result
.append(fields
[i
]);
166 return result
.toString();
This page took 0.03512 seconds and 6 git commands to generate.