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.
20 * @author Francois Chouinard
25 public class TmfEventType
implements ITmfEventType
, Cloneable
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
31 private String fContext
;
32 private String fTypeId
;
33 private ITmfEventField fRootField
;
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
42 public TmfEventType() {
43 this(DEFAULT_CONTEXT_ID
, DEFAULT_TYPE_ID
, null);
49 * @param context the type context
50 * @param typeId the type name
51 * @param root the root field
53 public TmfEventType(final String context
, final String typeId
, final ITmfEventField root
) {
54 if (context
== null || typeId
== null) {
55 throw new IllegalArgumentException();
61 // Register to the event type manager
62 TmfEventTypeManager
.getInstance().add(context
, this);
68 * @param type the other type
70 public TmfEventType(final ITmfEventType type
) {
72 throw new IllegalArgumentException();
74 fContext
= type
.getContext();
75 fTypeId
= type
.getName();
76 fRootField
= type
.getRootField();
79 // ------------------------------------------------------------------------
81 // ------------------------------------------------------------------------
84 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getContext()
87 public String
getContext() {
92 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getName()
95 public String
getName() {
100 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getRootField()
103 public ITmfEventField
getRootField() {
108 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getFieldNames()
111 public String
[] getFieldNames() {
112 return (fRootField
!= null) ? fRootField
.getFieldNames() : new String
[0];
116 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getFieldName(int)
119 public String
getFieldName(final int index
) {
120 return (fRootField
!= null) ? fRootField
.getFieldName(index
) : null;
123 // ------------------------------------------------------------------------
125 // ------------------------------------------------------------------------
128 * @see java.lang.Object#clone()
131 public TmfEventType
clone() {
132 TmfEventType clone
= null;
134 clone
= (TmfEventType
) super.clone();
135 clone
.fContext
= fContext
;
136 clone
.fTypeId
= fTypeId
;
137 clone
.fRootField
= (fRootField
!= null) ? fRootField
.clone() : null;
139 catch (final CloneNotSupportedException e
) {
144 // ------------------------------------------------------------------------
146 // ------------------------------------------------------------------------
149 * @see java.lang.Object#hashCode()
152 public int hashCode() {
153 final int prime
= 31;
155 result
= prime
* result
+ fContext
.hashCode();
156 result
= prime
* result
+ fTypeId
.hashCode();
161 * @see java.lang.Object#equals(java.lang.Object)
164 public boolean equals(final Object obj
) {
171 if (!(obj
instanceof TmfEventType
)) {
174 final TmfEventType other
= (TmfEventType
) obj
;
175 if (!fContext
.equals(other
.fContext
)) {
178 if (!fTypeId
.equals(other
.fTypeId
)) {
185 * @see java.lang.Object#toString()
188 @SuppressWarnings("nls")
189 public String
toString() {
190 return "TmfEventType [fContext=" + fContext
+ ", fTypeId=" + fTypeId
+ "]";