1 /*******************************************************************************
2 * Copyright (c) 2009, 2012 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 * Francois Chouinard - Updated as per TMF Event Model 1.0
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.event
;
18 * <b><u>TmfEventType</u></b>
20 * A basic implementation of ITmfEventType.
22 public class TmfEventType
implements ITmfEventType
{
24 // ------------------------------------------------------------------------
26 // ------------------------------------------------------------------------
28 private String fContext
;
29 private String fTypeId
;
30 private ITmfEventField fRootField
;
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
39 public TmfEventType() {
40 this(DEFAULT_CONTEXT_ID
, DEFAULT_TYPE_ID
, null);
46 * @param context the type context
47 * @param typeId the type name
48 * @param root the root field
50 public TmfEventType(final String context
, final String typeId
, final ITmfEventField root
) {
51 if (context
== null || typeId
== null)
52 throw new IllegalArgumentException();
57 // Register to the event type manager
58 TmfEventTypeManager
.getInstance().add(context
, this);
64 * @param type the other type
66 public TmfEventType(final ITmfEventType type
) {
68 throw new IllegalArgumentException();
69 fContext
= type
.getContext();
70 fTypeId
= type
.getName();
71 fRootField
= type
.getRootField();
74 // ------------------------------------------------------------------------
76 // ------------------------------------------------------------------------
79 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getContext()
82 public String
getContext() {
87 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getName()
90 public String
getName() {
95 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getRootField()
98 public ITmfEventField
getRootField() {
103 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getFieldNames()
106 public String
[] getFieldNames() {
107 String
[] result
= (fRootField
!= null) ? fRootField
.getFieldNames() : null;
112 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getFieldName(int)
115 public String
getFieldName(final int index
) {
116 String result
= (fRootField
!= null) ? fRootField
.getFieldName(index
) : null;
120 // ------------------------------------------------------------------------
122 // ------------------------------------------------------------------------
125 * @see java.lang.Object#clone()
128 public TmfEventType
clone() {
129 TmfEventType clone
= null;
131 clone
= (TmfEventType
) super.clone();
132 clone
.fContext
= fContext
;
133 clone
.fTypeId
= fTypeId
;
134 clone
.fRootField
= (fRootField
!= null) ? fRootField
.clone() : null;
136 catch (final CloneNotSupportedException e
) {
141 // ------------------------------------------------------------------------
143 // ------------------------------------------------------------------------
146 * @see java.lang.Object#hashCode()
149 public int hashCode() {
150 final int prime
= 31;
152 result
= prime
* result
+ fContext
.hashCode();
153 result
= prime
* result
+ fTypeId
.hashCode();
158 * @see java.lang.Object#equals(java.lang.Object)
161 public boolean equals(final Object obj
) {
166 if (!(obj
instanceof TmfEventType
))
168 final TmfEventType other
= (TmfEventType
) obj
;
169 if (!fContext
.equals(other
.fContext
))
171 if (!fTypeId
.equals(other
.fTypeId
))
177 * @see java.lang.Object#toString()
180 @SuppressWarnings("nls")
181 public String
toString() {
182 return "TmfEventType [fContext=" + fContext
+ ", fTypeId=" + fTypeId
+ "]";