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