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