b35703d6bcf8ae538413ec2a9534df06801326be
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfEventType.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2012 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Updated as per TMF Event Model 1.0
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.event;
15
16
17 /**
18 * <b><u>TmfEventType</u></b>
19 * <p>
20 * A basic implementation of ITmfEventType.
21 */
22 public class TmfEventType implements ITmfEventType {
23
24 // ------------------------------------------------------------------------
25 // Attributes
26 // ------------------------------------------------------------------------
27
28 private String fContext;
29 private String fTypeId;
30 private ITmfEventField fRootField;
31
32 // ------------------------------------------------------------------------
33 // Constructors
34 // ------------------------------------------------------------------------
35
36 /**
37 * Default constructor
38 */
39 public TmfEventType() {
40 this(DEFAULT_CONTEXT_ID, DEFAULT_TYPE_ID, null);
41 }
42
43 /**
44 * Full constructor
45 *
46 * @param context the type context
47 * @param typeId the type name
48 * @param root the root field
49 */
50 public TmfEventType(final String context, final String typeId, final ITmfEventField root) {
51 if (context == null || typeId == null)
52 throw new IllegalArgumentException();
53 fContext = context;
54 fTypeId = typeId;
55 fRootField = root;
56
57 // Register to the event type manager
58 TmfEventTypeManager.getInstance().add(context, this);
59 }
60
61 /**
62 * Copy constructor
63 *
64 * @param type the other type
65 */
66 public TmfEventType(final ITmfEventType type) {
67 if (type == null)
68 throw new IllegalArgumentException();
69 fContext = type.getContext();
70 fTypeId = type.getName();
71 fRootField = type.getRootField();
72 }
73
74 // ------------------------------------------------------------------------
75 // ITmfEventType
76 // ------------------------------------------------------------------------
77
78 /* (non-Javadoc)
79 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getContext()
80 */
81 @Override
82 public String getContext() {
83 return fContext;
84 }
85
86 /* (non-Javadoc)
87 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getName()
88 */
89 @Override
90 public String getName() {
91 return fTypeId;
92 }
93
94 /* (non-Javadoc)
95 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getRootField()
96 */
97 @Override
98 public ITmfEventField getRootField() {
99 return fRootField;
100 }
101
102 /* (non-Javadoc)
103 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getFieldNames()
104 */
105 @Override
106 public String[] getFieldNames() {
107 String[] result = (fRootField != null) ? fRootField.getFieldNames() : null;
108 return result;
109 }
110
111 /* (non-Javadoc)
112 * @see org.eclipse.linuxtools.tmf.core.event.ITmfEventType#getFieldName(int)
113 */
114 @Override
115 public String getFieldName(final int index) {
116 String result = (fRootField != null) ? fRootField.getFieldName(index) : null;
117 return result;
118 }
119
120 // ------------------------------------------------------------------------
121 // Cloneable
122 // ------------------------------------------------------------------------
123
124 /* (non-Javadoc)
125 * @see java.lang.Object#clone()
126 */
127 @Override
128 public TmfEventType clone() {
129 TmfEventType clone = null;
130 try {
131 clone = (TmfEventType) super.clone();
132 clone.fContext = fContext;
133 clone.fTypeId = fTypeId;
134 clone.fRootField = (fRootField != null) ? fRootField.clone() : null;
135 }
136 catch (final CloneNotSupportedException e) {
137 }
138 return clone;
139 }
140
141 // ------------------------------------------------------------------------
142 // Object
143 // ------------------------------------------------------------------------
144
145 /* (non-Javadoc)
146 * @see java.lang.Object#hashCode()
147 */
148 @Override
149 public int hashCode() {
150 final int prime = 31;
151 int result = 1;
152 result = prime * result + fContext.hashCode();
153 result = prime * result + fTypeId.hashCode();
154 return result;
155 }
156
157 /* (non-Javadoc)
158 * @see java.lang.Object#equals(java.lang.Object)
159 */
160 @Override
161 public boolean equals(final Object obj) {
162 if (this == obj)
163 return true;
164 if (obj == null)
165 return false;
166 if (!(obj instanceof TmfEventType))
167 return false;
168 final TmfEventType other = (TmfEventType) obj;
169 if (!fContext.equals(other.fContext))
170 return false;
171 if (!fTypeId.equals(other.fTypeId))
172 return false;
173 return true;
174 }
175
176 /* (non-Javadoc)
177 * @see java.lang.Object#toString()
178 */
179 @Override
180 @SuppressWarnings("nls")
181 public String toString() {
182 return "TmfEventType [fContext=" + fContext + ", fTypeId=" + fTypeId + "]";
183 }
184
185 }
This page took 0.034096 seconds and 4 git commands to generate.