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 return (fRootField
!= null) ? fRootField
.getFieldNames() : null;
111 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getFieldName(int)
114 public String
getFieldName(final int index
) {
115 return (fRootField
!= null) ? fRootField
.getFieldName(index
) : null;
118 // ------------------------------------------------------------------------
120 // ------------------------------------------------------------------------
123 * @see java.lang.Object#clone()
126 public TmfEventType
clone() {
127 TmfEventType clone
= null;
129 clone
= (TmfEventType
) super.clone();
130 clone
.fContext
= fContext
;
131 clone
.fTypeId
= fTypeId
;
132 clone
.fRootField
= (fRootField
!= null) ? fRootField
.clone() : null;
134 catch (final CloneNotSupportedException e
) {
139 // ------------------------------------------------------------------------
141 // ------------------------------------------------------------------------
144 * @see java.lang.Object#hashCode()
147 public int hashCode() {
148 final int prime
= 31;
150 result
= prime
* result
+ fContext
.hashCode();
151 result
= prime
* result
+ fTypeId
.hashCode();
156 * @see java.lang.Object#equals(java.lang.Object)
159 public boolean equals(final Object obj
) {
164 if (!(obj
instanceof TmfEventType
))
166 final TmfEventType other
= (TmfEventType
) obj
;
167 if (!fContext
.equals(other
.fContext
))
169 if (!fTypeId
.equals(other
.fTypeId
))
175 * @see java.lang.Object#toString()
178 @SuppressWarnings("nls")
179 public String
toString() {
180 return "TmfEventType [fContext=" + fContext
+ ", fTypeId=" + fTypeId
+ "]";