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
;
17 * A basic implementation of ITmfEventType.
21 * @author Francois Chouinard
26 public class TmfEventType
implements ITmfEventType
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
32 private String fContext
;
33 private String fTypeId
;
34 private ITmfEventField fRootField
;
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
43 public TmfEventType() {
44 this(DEFAULT_CONTEXT_ID
, DEFAULT_TYPE_ID
, null);
50 * @param context the type context
51 * @param typeId the type name
52 * @param root the root field
54 public TmfEventType(final String context
, final String typeId
, final ITmfEventField root
) {
55 if (context
== null || typeId
== null) {
56 throw new IllegalArgumentException();
62 // Register to the event type manager
63 TmfEventTypeManager
.getInstance().add(context
, this);
69 * @param type the other type
71 public TmfEventType(final ITmfEventType type
) {
73 throw new IllegalArgumentException();
75 fContext
= type
.getContext();
76 fTypeId
= type
.getName();
77 fRootField
= type
.getRootField();
80 // ------------------------------------------------------------------------
82 // ------------------------------------------------------------------------
85 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getContext()
88 public String
getContext() {
93 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getName()
96 public String
getName() {
101 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getRootField()
104 public ITmfEventField
getRootField() {
109 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getFieldNames()
112 public String
[] getFieldNames() {
113 return (fRootField
!= null) ? fRootField
.getFieldNames() : null;
117 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getFieldName(int)
120 public String
getFieldName(final int index
) {
121 return (fRootField
!= null) ? fRootField
.getFieldName(index
) : null;
124 // ------------------------------------------------------------------------
126 // ------------------------------------------------------------------------
129 * @see java.lang.Object#clone()
132 public TmfEventType
clone() {
133 TmfEventType clone
= null;
135 clone
= (TmfEventType
) super.clone();
136 clone
.fContext
= fContext
;
137 clone
.fTypeId
= fTypeId
;
138 clone
.fRootField
= (fRootField
!= null) ? fRootField
.clone() : null;
140 catch (final CloneNotSupportedException e
) {
145 // ------------------------------------------------------------------------
147 // ------------------------------------------------------------------------
150 * @see java.lang.Object#hashCode()
153 public int hashCode() {
154 final int prime
= 31;
156 result
= prime
* result
+ fContext
.hashCode();
157 result
= prime
* result
+ fTypeId
.hashCode();
162 * @see java.lang.Object#equals(java.lang.Object)
165 public boolean equals(final Object obj
) {
172 if (!(obj
instanceof TmfEventType
)) {
175 final TmfEventType other
= (TmfEventType
) obj
;
176 if (!fContext
.equals(other
.fContext
)) {
179 if (!fTypeId
.equals(other
.fTypeId
)) {
186 * @see java.lang.Object#toString()
189 @SuppressWarnings("nls")
190 public String
toString() {
191 return "TmfEventType [fContext=" + fContext
+ ", fTypeId=" + fTypeId
+ "]";